本文整理汇总了Python中integration.ggrc.Api类的典型用法代码示例。如果您正苦于以下问题:Python Api类的具体用法?Python Api怎么用?Python Api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Api类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestReindex
class TestReindex(TestCase):
"""Tests for reindex procedure."""
def setUp(self):
super(TestReindex, self).setUp()
self.api = Api()
def test_reindex(self):
"""Test reindex of big portion of objects."""
obj_count = listeners.ReindexSet.CHUNK_SIZE + 1
with factories.single_commit():
audit = factories.AuditFactory()
for _ in range(obj_count):
factories.AssessmentFactory(audit=audit)
indexer = fulltext.get_indexer()
archived_index = indexer.record_type.query.filter(
mysql.MysqlRecordProperty.type == "Assessment",
mysql.MysqlRecordProperty.property == "archived",
mysql.MysqlRecordProperty.content == "True"
)
self.assertEqual(archived_index.count(), 0)
# Reindex of Audit.archived lead to reindex of all related assessments
self.api.put(audit, {"archived": True})
# Check that all Assessment.archived were properly reindexed
self.assertEqual(archived_index.count(), obj_count)
示例2: TestAssessmentTemplate
class TestAssessmentTemplate(TestCase):
""" Test AssessmentTemplate class. """
def setUp(self):
super(TestAssessmentTemplate, self).setUp()
self.api = Api()
def test_audit_setup(self):
"""Test audit setup for assessment_template"""
audit = factories.AuditFactory()
response = self.api.post(all_models.AssessmentTemplate, {
"assessment_template": {
"audit": {"id": audit.id},
"context": {"id": audit.context.id},
"default_people": {
"assignees": "Admin",
"verifiers": "Admin",
},
"title": "Some title"
}
})
self.assertStatus(response, 201)
template_id = response.json["assessment_template"]["id"]
template = all_models.AssessmentTemplate.query.get(template_id)
self.assertEqual(template.audit.id, audit.id)
def test_audit_issue_tracker(self):
"""Test existing audit issue_tracker info in template response"""
with factories.single_commit():
audit = factories.AuditFactory()
audit_id = audit.id
factories.IssueTrackerIssueFactory(
issue_tracked_obj=audit,
component_id="some id",
hotlist_id="some host id",
)
template_id = factories.AssessmentTemplateFactory(
audit=audit,
context=audit.context
).id
response = self.api.get(all_models.AssessmentTemplate, template_id)
self.assert200(response)
audit = all_models.Audit.query.get(audit_id)
self.assertEqual(
response.json["assessment_template"]["audit"],
{
"type": "Audit",
"id": audit.id,
"href": "/api/audits/{}".format(audit.id),
"context_id": audit.context.id,
"issue_tracker": {
"component_id": "some id",
"enabled": False,
"issue_severity": None,
"hotlist_id": "some host id",
"issue_priority": None,
"issue_type": None
}
}
)
示例3: generate_cycle
def generate_cycle(workflow_id, api=None):
"""Create cycle with task automatically."""
if not api:
api = Api()
return api.post(all_models.Cycle, {
"cycle": {
"context": None,
"autogenerate": True,
"isOverdue": False,
"workflow": {
"id": workflow_id,
"type": "Workflow",
},
}
})
示例4: __init__
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Evidence 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():
evidence = factories.EvidenceUrlFactory()
if parent == "Audit":
self.mapping_id = factories.RelationshipFactory(
source=self.audit, destination=evidence
).id
elif parent == "Assessment":
self.mapping_id = factories.RelationshipFactory(
source=self.assessment, destination=evidence
).id
self.evidence_id = evidence.id
self.parent = parent
self.admin_acr_id = all_models.AccessControlRole.query.filter_by(
name="Admin",
object_type="Evidence",
).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)
示例5: __init__
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Snapshot 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)
control = factories.ControlFactory()
# pylint: disable=protected-access
snapshot = TestCase._create_snapshots(self.audit, [control])[0]
factories.RelationshipFactory(source=snapshot, destination=self.audit)
factories.RelationshipFactory(source=control, destination=self.program)
if parent == "Assessment":
factories.RelationshipFactory(
source=snapshot, destination=self.assessment
)
self.control_id = control.id
self.snapshot_id = snapshot.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)
示例6: __init__
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Document 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.api = Api()
self.objgen = generator.ObjectGenerator()
self.objgen.api = self.api
self.acr = acr
self.user_id = user_id
self.parent_name = parent
self.document_id = None
self.parent = None
self.parent_id = None
self.admin_acr_id = all_models.AccessControlRole.query.filter_by(
name="Admin",
object_type="Document",
).one().id
self.setup_models(self.parent_name)
self.set_user(user_id)
示例7: setUp
def setUp(self):
super(TestIssue, self).setUp()
self.api = Api()
with factories.single_commit():
audit = factories.AuditFactory()
for status in all_models.Issue.VALID_STATES:
factories.IssueFactory(audit=audit, status=status)
示例8: CycleRBACFactory
class CycleRBACFactory(base.BaseRBACFactory):
"""Cycle RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Cycle permission tests.
Args:
user_id: Id of user under which all operations will be run.
object_acl: Dict with format: {
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 cycle for Workflow."""
return self.generate_cycle(self.workflow_id, self.api)
def update(self):
"""Update existing cycle."""
cycle = all_models.Cycle.query.first()
return self.api.put(cycle, {"title": factories.random_str()})
def delete(self):
"""Delete existing cycle."""
cycle = all_models.Cycle.query.first()
return self.api.delete(cycle)
def activate(self):
"""Activate Workflow."""
workflow = all_models.Workflow.query.get(self.workflow_id)
cycle = wf_factories.CycleFactory(workflow=workflow)
return self.api.put(workflow, {
"status": "Active",
"recurrences": bool(workflow.repeat_every and workflow.unit),
"cycles": [{
"id": cycle.id,
"type": "Cycle",
}]
})
def read(self):
"""Read existing Cycle object."""
cycle = all_models.Cycle.query.first()
return self.api.get(cycle, cycle.id)
def end(self):
"""End existing Cycle."""
cycle = all_models.Cycle.query.first()
return self.api.put(cycle, {"is_current": False})
示例9: CycleTaskGroupRBACFactory
class CycleTaskGroupRBACFactory(base.BaseRBACFactory):
"""Cycle Task Group RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Cycle 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:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def read(self):
"""Read existing Cycle Task Group object."""
cycle_tg = all_models.CycleTaskGroup.query.first()
return self.api.get(all_models.CycleTaskGroup, cycle_tg.id)
def update(self):
"""Update title of existing Cycle Task Group object."""
cycle_tg = all_models.CycleTaskGroup.query.first()
return self.api.put(cycle_tg, {"title": factories.random_str()})
def delete(self):
"""Delete Cycle Task Group object."""
cycle_tg = all_models.CycleTaskGroup.query.first()
return self.api.delete(cycle_tg)
示例10: setUp
def setUp(self):
super(TestAccessControlListValidation, self).setUp()
self.api = Api()
self.client.get("/login")
role_ids = db.session.query(
all_models.AccessControlRole.id
).filter(
all_models.AccessControlRole.object_type.in_(("Control", "Objective")),
all_models.AccessControlRole.name == "Admin"
).order_by(all_models.AccessControlRole.object_type)
role_ids = [id_[0] for id_ in role_ids]
self.control_admin_acr_id, self.objective_admin_acr_id = role_ids
示例11: TestIssueDueDate
class TestIssueDueDate(TestCase):
"""Test suite to test Due Date of Issue"""
def setUp(self):
self.clear_data()
super(TestIssueDueDate, self).setUp()
self.api = Api()
def test_issue_due_date_post(self):
"""Test POST requests to Issue.due_date"""
response = self.api.post(all_models.Issue, data={
"issue": {
"title": "TestDueDate",
"context": None,
"due_date": "06/14/2018",
}
})
self.assertEqual(201, response.status_code)
due_date = all_models.Issue.query.first().due_date.strftime("%m/%d/%Y")
self.assertEqual(due_date, "06/14/2018")
def test_issue_due_date_get(self):
"""Test GET HTTP requests to Issue.due_date"""
issue = factories.IssueFactory(due_date=datetime.date(2018, 6, 14))
response = self.api.get(all_models.Issue, issue.id)
issue_json = response.json
self.assert200(response)
self.assertEqual(issue_json["issue"]["due_date"], "2018-06-14")
def test_issue_due_date_put(self):
"""Test PUT HTTP requests to Issue.due_date"""
issue = factories.IssueFactory(due_date=datetime.date(2018, 6, 14))
data = issue.log_json()
data["due_date"] = "2018-06-15"
response = self.api.put(issue, data)
self.assert200(response)
self.assertEqual(response.json["issue"]["due_date"], "2018-06-15")
示例12: CycleTaskEntryRBACFactory
class CycleTaskEntryRBACFactory(base.BaseRBACFactory):
"""Cycle Task Entry RBAC factory class."""
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Cycle Task Entry 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()
self.create()
if user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def create(self):
"""Create new Cycle Task Entry object."""
cycle_task = all_models.CycleTaskGroupObjectTask.query.first()
return self.api.post(all_models.CycleTaskEntry, {
"cycle_task_entry": {
"description": "New Comment",
"is_declining_review": "",
"context": None,
"cycle_task_group_object_task": {
"id": cycle_task.id,
"type": "CycleTaskGroupObjectTask",
},
"cycle": {
"id": cycle_task.cycle.id,
"type": "Cycle",
},
}
})
def read(self):
"""Read existing Cycle Task Entry object."""
cycle_task_entry = all_models.CycleTaskEntry.query.first()
return self.api.get(cycle_task_entry, cycle_task_entry.id)
def update(self):
"""Update title of existing Cycle Task Entry object."""
cycle_task_entry = all_models.CycleTaskEntry.query.first()
return self.api.put(
cycle_task_entry,
{"description": factories.random_str()}
)
def delete(self):
"""Delete Cycle Task Entry object."""
cycle_task_entry = all_models.CycleTaskEntry.query.first()
return self.api.delete(cycle_task_entry)
示例13: __init__
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)
示例14: TestIssue
class TestIssue(TestCase):
""" Test Issue class. """
def setUp(self):
super(TestIssue, self).setUp()
self.api = Api()
with factories.single_commit():
audit = factories.AuditFactory()
for status in all_models.Issue.VALID_STATES:
factories.IssueFactory(audit=audit, status=status)
def test_filter_by_status(self):
"""Test Issue filtering by status."""
query_request_data = [{
'fields': [],
'filters': {
'expression': {
'left': {
'left': 'status',
'op': {'name': '='},
'right': 'Fixed'
},
'op': {'name': 'OR'},
'right': {
'left': 'status',
'op': {'name': '='},
'right': 'Fixed and Verified'
},
},
},
'object_name': 'Issue',
'permissions': 'read',
'type': 'values',
}]
response = self.api.send_request(
self.api.client.post,
data=query_request_data,
api_link="/query"
)
self.assertEqual(response.status_code, 200)
statuses = {i["status"] for i in response.json[0]["Issue"]["values"]}
self.assertEqual(statuses, {"Fixed", "Fixed and Verified"})
示例15: __init__
def __init__(self, user_id, acr, parent=None):
"""Set up objects for Cycle 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:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)