本文整理汇总了Python中integration.ggrc.Api.get_query方法的典型用法代码示例。如果您正苦于以下问题:Python Api.get_query方法的具体用法?Python Api.get_query怎么用?Python Api.get_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类integration.ggrc.Api
的用法示例。
在下文中一共展示了Api.get_query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WorkflowRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class WorkflowRBACFactory(base.BaseRBACFactory):
"""Workflow RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Workflow permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
# pylint: disable=unused-argument
self.setup_workflow_scope(user_id, acr)
self.api = Api()
if user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Workflow object."""
return self.api.post(all_models.Workflow, {
"workflow": {
"title": "New workflow",
"context": None,
}
})
def read(self):
"""Read existing Workflow object."""
return self.api.get(all_models.Workflow, self.workflow_id)
def update(self):
"""Update title of existing Workflow object."""
workflow = all_models.Workflow.query.get(self.workflow_id)
return self.api.put(workflow, {"title": factories.random_str()})
def delete(self):
"""Delete Workflow object."""
workflow = all_models.Workflow.query.get(self.workflow_id)
return self.api.delete(workflow)
def read_revisions(self):
"""Read revisions for Workflow object."""
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
all_models.Workflow, query.format("workflow", self.workflow_id)
)
)
return responses
def clone(self):
"""Clone existing Workflow object."""
with factories.single_commit():
task_group = wf_factories.TaskGroupFactory(workflow_id=self.workflow_id)
wf_factories.TaskGroupTaskFactory(task_group=task_group)
return self.api.post(all_models.Workflow, {
"workflow": {
# workaround - title is required for validation
"title": "",
"clone": self.workflow_id,
"clone_objects": True,
"clone_people": True,
"clone_tasks": True,
"context": None,
}
})
示例2: TaskGroupTaskRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class TaskGroupTaskRBACFactory(base.BaseRBACFactory):
"""Task Group Task RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Task Group Task permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
# pylint: disable=unused-argument
self.setup_workflow_scope(user_id, acr)
self.api = Api()
if user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Task Group Task object."""
person = factories.PersonFactory()
return self.api.post(all_models.TaskGroupTask, {
"task_group_task": {
"title": "New Task Group Task",
"start_date": datetime.now().strftime("%Y-%m-%d"),
"end_date": datetime.now().strftime("%Y-%m-%d"),
"contact": person,
"context": None,
"task_group": {
"id": self.task_group_id,
"type": "Task Group",
},
}
})
def read(self):
"""Read existing Task Group Task object."""
return self.api.get(all_models.TaskGroupTask, self.task_id)
def update(self):
"""Update title of existing Task Group Task object."""
task = all_models.TaskGroupTask.query.get(self.task_id)
return self.api.put(task, {"title": factories.random_str()})
def delete(self):
"""Delete Task Group Task object."""
task = all_models.TaskGroupTask.query.get(self.task_id)
return self.api.delete(task)
def read_revisions(self):
"""Read revisions for Task Group Task object."""
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
all_models.TaskGroupTask,
query.format("task_group_task", self.task_id)
)
)
return responses
示例3: AssessmentTemplateRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class AssessmentTemplateRBACFactory(base.BaseRBACFactory):
"""Assessment Template RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Assessment Template permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
self.setup_program_scope(user_id, acr, parent)
with factories.single_commit():
template = factories.AssessmentTemplateFactory(audit=self.audit)
factories.RelationshipFactory(source=self.audit, destination=template)
self.template_id = template.id
self.default_assignees = "Admin"
self.default_verifiers = "Admin"
self.api = Api()
if user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Assessment Template object."""
return self.api.post(all_models.AssessmentTemplate, {
"assessment_template": {
"audit": {"id": self.audit_id, "type": "Audit"},
"context": None,
"default_people": {
"assignees": self.default_assignees,
"verifiers": self.default_verifiers,
},
"title": "New Assessment Template"
}
})
def read(self):
"""Read existing Assessment Template object."""
return self.api.get(all_models.AssessmentTemplate, self.template_id)
def update(self):
"""Update title of existing Assessment Template object."""
template = all_models.AssessmentTemplate.query.get(self.template_id)
return self.api.put(template, {"title": factories.random_str()})
def delete(self):
"""Delete Assessment Template object."""
template = all_models.AssessmentTemplate.query.get(self.template_id)
return self.api.delete(template)
def read_revisions(self):
"""Read revisions for Assessment Template object."""
model_class = get_model("AssessmentTemplate")
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
model_class,
query.format("assessment_template", self.template_id)
)
)
return responses
示例4: ProgramRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class ProgramRBACFactory(base.BaseRBACFactory):
"""Program RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Program permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
# pylint: disable=unused-argument
self.setup_program_scope(user_id, acr, "Program")
self.admin_control_id = {
name: id for id, name
in access_control.role.get_custom_roles_for("Control").items()
}["Admin"]
self.api = Api()
self.objgen = generator.ObjectGenerator()
self.objgen.api = self.api
if user_id:
self.user_id = user_id
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Program object."""
return self.api.post(all_models.Program, {
"program": {
"title": "New program",
"program": {"id": self.program_id},
"context": None,
"access_control_list": [],
}
})
def read(self):
"""Read existing Audit object."""
return self.api.get(all_models.Program, self.program_id)
def update(self):
"""Update title of existing Audit object."""
program = all_models.Program.query.get(self.program_id)
return self.api.put(program, {"title": factories.random_str()})
def delete(self):
"""Delete Audit object."""
program = all_models.Program.query.get(self.program_id)
return self.api.delete(program)
def read_revisions(self):
"""Read revisions for Assessment object."""
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
all_models.Program, query.format("program", self.program_id)
)
)
return responses
def map_control(self):
"""Map new Control to Program."""
with factories.single_commit():
control = factories.ControlFactory()
factories.AccessControlListFactory(
ac_role_id=self.admin_control_id,
object_id=control.id,
object_type="Control",
person_id=self.user_id
)
program = all_models.Program.query.get(self.program_id)
return self.objgen.generate_relationship(
source=program,
destination=control,
)[0]
def unmap_control(self):
"""Unmap Control from Program."""
control = factories.ControlFactory()
program = all_models.Program.query.get(self.program_id)
rel = factories.RelationshipFactory(source=control, destination=program)
return self.api.delete(rel)
def read_mapped(self):
"""Read control mapped to Program."""
program = all_models.Program.query.get(self.program_id)
with factories.single_commit():
control = factories.ControlFactory()
factories.RelationshipFactory(source=control, destination=program)
return self.api.get(control, control.id)
def update_mapped(self):
"""Update control mapped to Program."""
#.........这里部分代码省略.........
示例5: AuditRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class AuditRBACFactory(base.BaseRBACFactory):
"""Audit RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Audit permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
# pylint: disable=unused-argument
self.setup_program_scope(user_id, acr, "Audit")
self.api = Api()
self.objgen = generator.ObjectGenerator()
self.objgen.api = self.api
self.admin_control_id = {
name: id for id, name
in access_control.role.get_custom_roles_for("Control").items()
}["Admin"]
if user_id:
self.user_id = user_id
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Audit object."""
return self.api.post(all_models.Audit, {
"audit": {
"title": "New audit",
"program": {"id": self.program_id},
"context": None,
"access_control_list": [],
}
})
def read(self):
"""Read existing Audit object."""
return self.api.get(all_models.Audit, self.audit_id)
def update(self):
"""Update title of existing Audit object."""
audit = all_models.Audit.query.get(self.audit_id)
return self.api.put(audit, {"title": factories.random_str()})
def delete(self):
"""Delete Audit object."""
audit = all_models.Audit.query.get(self.audit_id)
return self.api.delete(audit)
def clone(self):
"""Clone existing Audit with Assessment Templates."""
return self.api.post(all_models.Audit, {
"audit": {
"program": {"id": self.program_id, "type": "Program"},
# workaround - title is required for validation
"title": "",
"context": None,
"operation": "clone",
"cloneOptions": {
"sourceObjectId": self.audit_id,
"mappedObjects": "AssessmentTemplate"
}
}
})
def read_revisions(self):
"""Read revisions for Audit object."""
model_class = get_model("Audit")
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(model_class, query.format("audit", self.audit_id))
)
return responses
def map_external_control(self):
"""Map Control (on which current user don't have any rights) to Audit."""
control = factories.ControlFactory()
audit = all_models.Audit.query.get(self.audit_id)
return self.objgen.generate_relationship(
source=audit,
destination=control,
)[0]
def map_control(self):
"""Map new snapshot of Control to Audit."""
with factories.single_commit():
control = factories.ControlFactory()
acl = [
acl
for acl in control._access_control_list
if acl.ac_role_id == self.admin_control_id
][0]
factories.AccessControlPersonFactory(
#.........这里部分代码省略.........
示例6: TaskGroupRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class TaskGroupRBACFactory(base.BaseRBACFactory):
"""Task Group RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Task Group permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
# pylint: disable=unused-argument
self.setup_workflow_scope(user_id, acr)
self.admin_control_id = {
name: id_ for id_, name
in access_control.role.get_custom_roles_for("Control").items()
}["Admin"]
self.api = Api()
if user_id:
self.user_id = user_id
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Task Group object."""
person = factories.PersonFactory()
return self.api.post(all_models.TaskGroup, {
"task_group": {
"contact": {
"id": person.id,
"type": "Person",
},
"title": "New Task Group",
"context": None,
"workflow": {
"id": self.workflow_id,
"type": "Workflow",
},
}
})
def read(self):
"""Read existing Task Group object."""
return self.api.get(all_models.TaskGroup, self.task_group_id)
def update(self):
"""Update title of existing Task Group object."""
task_group = all_models.TaskGroup.query.get(self.task_group_id)
return self.api.put(task_group, {"title": factories.random_str()})
def delete(self):
"""Delete Task Group object."""
task_group = all_models.TaskGroup.query.get(self.task_group_id)
return self.api.delete(task_group)
def read_revisions(self):
"""Read revisions for Task Group object."""
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
all_models.TaskGroup,
query.format("task_group", self.task_group_id)
)
)
return responses
def map_control(self):
"""Map Control on which user don't have any rights to Cycle Task."""
task_group = all_models.TaskGroup.query.get(self.task_group_id)
control = factories.ControlFactory()
return self.api.post(all_models.TaskGroupObject, {
"task_group_object": {
"context": None,
"object": {
"id": control.id,
"type": "Control",
},
"task_group": {
"id": task_group.id,
"type": "TaskGroup",
},
}
})
def map_created_control(self):
"""Map Control that was created by user to Cycle Task."""
task_group = all_models.TaskGroup.query.get(self.task_group_id)
with factories.single_commit():
control = factories.ControlFactory()
factories.AccessControlListFactory(
ac_role_id=self.admin_control_id,
object_id=control.id,
object_type="Control",
person_id=self.user_id
)
#.........这里部分代码省略.........
示例7: AssessmentRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class AssessmentRBACFactory(base.BaseRBACFactory):
"""Assessment RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Assessment permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
self.setup_program_scope(user_id, acr, parent)
self.api = Api()
self.objgen = generator.ObjectGenerator()
self.objgen.api = self.api
if user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Assessment object."""
return self.api.post(all_models.Assessment, {
"assessment": {
"title": "New Assessment",
"context": None,
"audit": {"id": self.audit_id},
},
})
def generate(self):
"""Generate new Assessment object."""
with factories.single_commit():
control = factories.ControlFactory()
template_id = factories.AssessmentTemplateFactory().id
audit = all_models.Audit.query.get(self.audit_id)
# pylint: disable=protected-access
snapshot = TestCase._create_snapshots(audit, [control])[0]
snapshot_id = snapshot.id
factories.RelationshipFactory(source=snapshot, destination=audit)
responses = []
asmnt_data = {
"assessment": {
"_generated": True,
"audit": {
"id": self.audit_id,
"type": "Audit"
},
"object": {
"id": snapshot_id,
"type": "Snapshot"
},
"context": None,
"title": "New assessment",
}
}
responses.append(self.api.post(all_models.Assessment, asmnt_data))
asmnt_data["assessment"]["template"] = {
"id": template_id,
"type": "AssessmentTemplate"
}
responses.append(self.api.post(all_models.Assessment, asmnt_data))
return responses
def read(self):
"""Read existing Assessment object."""
return self.api.get(all_models.Assessment, self.assessment_id)
def update(self):
"""Update title of existing Assessment object."""
asmnt = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(asmnt, {"title": factories.random_str()})
def delete(self):
"""Delete Assessment object."""
asmnt = all_models.Assessment.query.get(self.assessment_id)
return self.api.delete(asmnt)
def read_revisions(self):
"""Read revisions for Assessment object."""
model_class = get_model("Assessment")
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
model_class,
query.format("assessment", self.assessment_id)
)
)
return responses
def map_snapshot(self):
"""Map snapshot to assessment."""
audit = all_models.Audit.query.get(self.audit_id)
assessment = all_models.Assessment.query.get(self.assessment_id)
#.........这里部分代码省略.........
示例8: IssueRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import get_query [as 别名]
class IssueRBACFactory(base.BaseRBACFactory):
"""Issue RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Issue permission tests.
Args:
user_id: Id of user under which all operations will be run.
acr: Instance of ACR that should be assigned for tested user.
parent: Model name in scope of which objects should be set up.
"""
self.setup_program_scope(user_id, acr)
with factories.single_commit():
issue = factories.IssueFactory()
if parent == "Audit":
self.mapping_id = factories.RelationshipFactory(
source=self.audit, destination=issue
).id
elif parent == "Assessment":
self.mapping_id = factories.RelationshipFactory(
source=self.assessment, destination=issue
).id
self.issue_id = issue.id
self.parent = parent
self.admin_acr_id = all_models.AccessControlRole.query.filter_by(
name="Admin",
object_type="Issue",
).one().id
self.user_id = user_id
self.api = Api()
self.objgen = generator.ObjectGenerator()
self.objgen.api = self.api
if user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Issue object."""
return self.api.post(all_models.Issue, {
"issue": {
"access_control_list": [{
"ac_role_id": self.admin_acr_id,
"person": {
"id": self.user_id,
"type": "Person",
}
}],
"title": factories.random_str(),
"context": None,
}
})
def read(self):
"""Read existing Issue object."""
return self.api.get(all_models.Issue, self.issue_id)
def update(self):
"""Update title of existing Issue object."""
issue = all_models.Issue.query.get(self.issue_id)
return self.api.put(issue, {"title": factories.random_str()})
def delete(self):
"""Delete Issue object."""
issue = all_models.Issue.query.get(self.issue_id)
return self.api.delete(issue)
def read_revisions(self):
"""Read revisions of Issue object."""
model_class = get_model("Issue")
responses = []
for query in ["source_type={}&source_id={}",
"destination_type={}&destination_id={}",
"resource_type={}&resource_id={}"]:
responses.append(
self.api.get_query(
model_class,
query.format("issue", self.issue_id)
)
)
return responses
def map(self, issue=None):
"""Map Issue to parent object."""
if self.parent == "Audit":
parent = all_models.Audit.query.get(self.audit_id)
else:
parent = all_models.Assessment.query.get(self.assessment_id)
map_issue = issue if issue else factories.IssueFactory()
return self.objgen.generate_relationship(
source=parent,
destination=map_issue
)[0]
def create_and_map(self):
"""Create new Issue and map it to parent."""
response = self.create()
#.........这里部分代码省略.........