本文整理汇总了Python中integration.ggrc.Api.put方法的典型用法代码示例。如果您正苦于以下问题:Python Api.put方法的具体用法?Python Api.put怎么用?Python Api.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类integration.ggrc.Api
的用法示例。
在下文中一共展示了Api.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestReindex
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
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: CycleRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
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})
示例3: CycleTaskEntryRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
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)
示例4: CycleTaskGroupRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
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)
示例5: TestIssueDueDate
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
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")
示例6: TestAudit
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
class TestAudit(TestCase):
""" Test Audit class. """
def setUp(self):
super(TestAudit, self).setUp()
self.api = Api()
self.gen = generator.ObjectGenerator()
def generate_control_mappings(self, control):
"""Map Control to several Assessments"""
acr_creator = all_models.AccessControlRole.query.filter_by(
name="Creators", object_type="Assessment"
).first()
with factories.single_commit():
person = factories.PersonFactory()
asmnt_ids = []
for _ in range(2):
asmnt = factories.AssessmentFactory()
asmnt_ids.append(asmnt.id)
factories.AccessControlListFactory(
object=asmnt, person=person, ac_role=acr_creator
)
for asmnt_id in asmnt_ids:
asmnt = all_models.Assessment.query.get(asmnt_id)
self.gen.generate_relationship(source=asmnt, destination=control)
def test_creation_mapped_control(self):
"""Check creation of new Audit if Program has Control with mapped roles"""
control = factories.ControlFactory()
# Map original of control to several assessments to get propagated roles
self.generate_control_mappings(control)
# Existing control should be updated to create new revision with ACL
self.api.put(control, {"title": "Test Control"})
program = factories.ProgramFactory()
factories.RelationshipFactory(source=program, destination=control)
response = self.api.post(all_models.Audit, [{
"audit": {
"title": "New Audit",
"program": {"id": program.id},
"status": "Planned",
"context": None
}
}])
self.assert200(response)
def test_program_mapping(self):
"""Check creation of new Audit if Program has Control with mapped roles"""
program = factories.ProgramFactory()
self.api.post(all_models.Audit, [{
"audit": {
"title": "New Audit",
"program": {"id": program.id, "type": program.type},
"status": "Planned",
"context": None
}
}])
audit = all_models.Audit.query.first()
program = all_models.Program.query.first()
relationships = all_models.Relationship.find_related(audit, program)
self.assertIsNotNone(audit)
self.assertIsNotNone(program)
self.assertIsNotNone(relationships)
def test_delete_audit(self):
"""Check inability to delete audit in relation with assessment template."""
with factories.single_commit():
audit = factories.AuditFactory()
assessment_template = factories.AssessmentTemplateFactory(audit=audit)
factories.RelationshipFactory(
source=audit,
destination=assessment_template
)
response = self.api.delete(audit)
self.assert400(response)
self.assertEqual(response.json["message"],
"This request will break a mandatory relationship from "
"assessment_templates to audits.")
def test_delete_audit_proper(self):
"""Check delete audit with assessment template. Remove template first"""
with factories.single_commit():
audit = factories.AuditFactory()
audit_id = audit.id
assessment_template = factories.AssessmentTemplateFactory(audit=audit)
assessment_template_id = assessment_template.id
factories.RelationshipFactory(
source=audit,
destination=assessment_template
)
assessment_template = \
all_models.AssessmentTemplate.query.get(assessment_template_id)
response = self.api.delete(assessment_template)
self.assert200(response)
audit = all_models.Audit.query.get(audit_id)
#.........这里部分代码省略.........
示例7: TaskGroupTaskRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [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
示例8: TestFolderField
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
class TestFolderField(TestCase):
"""Test class about all folder field activities."""
FOLDERABLE_FACTORIES = [
factories.AccessGroupFactory,
factories.AccountBalanceFactory,
factories.ContractFactory,
factories.ControlFactory,
factories.DataAssetFactory,
factories.DirectiveFactory,
factories.FacilityFactory,
factories.IssueFactory,
factories.KeyReportFactory,
factories.MarketFactory,
factories.MetricFactory,
factories.ObjectiveFactory,
factories.OrgGroupFactory,
factories.PolicyFactory,
factories.ProcessFactory,
factories.ProductFactory,
factories.ProductGroupFactory,
factories.ProgramFactory,
factories.ProjectFactory,
factories.RegulationFactory,
factories.RequirementFactory,
factories.RiskFactory,
factories.StandardFactory,
factories.SystemFactory,
factories.TechnologyEnvironmentFactory,
factories.ThreatFactory,
factories.VendorFactory,
]
def setUp(self):
super(TestFolderField, self).setUp()
self.api = Api()
self.api.login_as_normal()
@ddt.data(*FOLDERABLE_FACTORIES)
def test_create_object(self, factory):
"""Test create folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_create_name"
self.assertEqual(
test_folder_name,
factory(folder=test_folder_name).folder
)
@ddt.data(*FOLDERABLE_FACTORIES)
def test_get_object(self, factory):
"""Test get folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_get_name"
obj = factory(folder=test_folder_name)
data = self.api.get(obj, obj.id).json
self.assertEqual(
test_folder_name,
data[obj._inflector.table_singular.lower()]["folder"]
)
NOT_PUTABLE_FACTORIES = NOT_POSTABLE_FACTORIES = [
factories.DirectiveFactory,
]
@ddt.data(*FOLDERABLE_FACTORIES)
def test_put_object(self, factory):
"""Test put folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_put_name"
obj = factory(folder=test_folder_name)
update_test_folder_name = "upd_tmp_folder_put_name"
obj_id = obj.id
if factory in self.NOT_PUTABLE_FACTORIES:
with self.assertRaises(NotImplementedError):
self.api.put(obj, {"folder": update_test_folder_name})
else:
if isinstance(obj, Synchronizable):
# Currently external user can't modify folder field
# because of WithProtectedAttributes mixin
return
self.api.put(obj, {"folder": update_test_folder_name})
self.assertEqual(
update_test_folder_name,
obj.__class__.query.get(obj_id).folder
)
@ddt.data(*FOLDERABLE_FACTORIES)
def test_post_object(self, factory):
"""Test post folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_put_name"
obj = factory(folder=test_folder_name)
obj_id = obj.id
key = obj._inflector.table_singular.lower()
post_data = self.api.get(obj, obj.id).json
model = obj.__class__
db.session.delete(obj)
db.session.commit()
del post_data[key]["id"]
if factory in self.NOT_POSTABLE_FACTORIES:
with self.assertRaises(NotImplementedError):
self.api.post(model, post_data)
else:
#.........这里部分代码省略.........
示例9: DocumentReferenceUrlRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
class DocumentReferenceUrlRBACFactory(base.BaseRBACFactory):
"""Document Reference Url RBAC factory class."""
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)
def set_user(self, user_id):
"""Set user to send requests"""
if self.user_id:
user = all_models.Person.query.get(user_id)
self.api.set_user(user)
def setup_models(self, parent_name):
"""Setup document, parent, relationship"""
with factories.single_commit():
document = factories.DocumentReferenceUrlFactory()
self.document_id = document.id
self.parent = self.build_parent(parent_name)
self.parent_id = self.parent.id
factories.RelationshipFactory(source=self.parent, destination=document)
self.assign_person(self.parent, self.acr, self.user_id)
@staticmethod
def build_parent(parent_name):
"""Create parent based on Name"""
try:
parent = FACTORIES_MAPPING[parent_name]()
except KeyError():
raise ValueError("Unknown parent {}".format(parent_name))
return parent
def create(self):
"""Create new Document object."""
result = self.api.post(all_models.Document, {
"document": {
"access_control_list": [{
"ac_role_id": self.admin_acr_id,
"person": {
"id": self.user_id,
"type": "Person",
}
}],
"link": factories.random_str(),
"title": factories.random_str(),
"context": None,
}
})
return result
def read(self):
"""Read existing Document object."""
res = self.api.get(all_models.Document, self.document_id)
return res
def update(self):
"""Update title of existing Document object."""
document = all_models.Document.query.get(self.document_id)
return self.api.put(document, {"title": factories.random_str()})
def delete(self):
"""Delete Document object."""
document = all_models.Document.query.get(self.document_id)
return self.api.delete(document)
def map(self, document=None):
"""Map Document to parent object."""
parent = self.parent.__class__.query.get(self.parent_id)
map_document = document if document \
else factories.DocumentReferenceUrlFactory()
return self.objgen.generate_relationship(
source=parent,
destination=map_document
)[0]
def create_and_map(self):
"""Create new Document and map it to parent."""
#.........这里部分代码省略.........
示例10: EvidenceRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
class EvidenceRBACFactory(base.BaseRBACFactory):
"""Evidence RBAC factory class."""
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)
def create(self):
"""Create new Evidence object."""
result = self.api.post(all_models.Evidence, {
"evidence": {
"access_control_list": [{
"ac_role_id": self.admin_acr_id,
"person": {
"id": self.user_id,
"type": "Person",
}
}],
"link": factories.random_str(),
"title": factories.random_str(),
"context": None,
}
})
return result
def read(self):
"""Read existing Evidence object."""
res = self.api.get(all_models.Evidence, self.evidence_id)
return res
def update(self):
"""Update title of existing Evidence object."""
evidence = all_models.Evidence.query.get(self.evidence_id)
return self.api.put(evidence, {"title": factories.random_str()})
def delete(self):
"""Delete Evidence object."""
evidence = all_models.Evidence.query.get(self.evidence_id)
return self.api.delete(evidence)
def map(self, evidence=None):
"""Map Evidence 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_evidence = evidence if evidence else factories.EvidenceUrlFactory()
return self.api.put(parent, {
"actions": {
"add_related": [{
"id": map_evidence.id,
"type": "Evidence",
}]
}
})
def create_and_map(self):
"""Create new Evidence and map it to parent."""
response = self.create()
evidence_id = None
if response.json and response.json.get("evidence"):
evidence_id = response.json.get("evidence", {}).get("id")
if not evidence_id:
return response
evidence = all_models.Evidence.query.get(evidence_id)
return self.map(evidence)
def add_comment(self):
#.........这里部分代码省略.........
示例11: TestReviewNotification
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
#.........这里部分代码省略.........
reviewer_role_id = all_models.AccessControlRole.query.filter_by(
name="Reviewers",
object_type="Review",
).one().id
with factories.single_commit():
program_primary_contact = factories.PersonFactory(name='primary')
program_secondary_contact = factories.PersonFactory(name='secondary')
program = factories.ProgramFactory()
program.add_person_with_role_name(program_primary_contact,
"Primary Contacts")
program.add_person_with_role_name(program_secondary_contact,
"Secondary Contacts")
email_message = "email email_message"
self.generator.generate_object(
all_models.Review,
{
"reviewable": {
"type": program.type,
"id": program.id,
},
"context":
None,
"notification_type":
all_models.Review.NotificationTypes.EMAIL_TYPE,
"status":
all_models.Review.STATES.REVIEWED,
"email_message":
email_message,
"access_control_list":
[{
"ac_role_id": reviewer_role_id,
"person": {
"id": reviewer.id
},
}],
},
)
self.api.put(program, {"title": "new title"})
with mock.patch.object(
fast_digest.DIGEST_TMPL, "render"
) as bodybuilder_mock:
fast_digest.send_notification()
# 4 emails to each user
self.assertEqual(3, bodybuilder_mock.call_count)
call_count = _call_counter(bodybuilder_mock)
# 1 email to reviewer -> need to review
self.assertEqual(1, call_count["review_reviewers"])
# 1 emails to owners -> object state updated
self.assertEqual(2, call_count["review_owners"])
@patch("google.appengine.api.mail.send_mail")
@freezegun.freeze_time("2019-01-15 12:00:00")
def test_notification_subject(self, send_mail_mock):
"""Test that emails are sent with proper subject."""
expected_subject = "GGRC Change requests review digest " \
"for 01/15/2019 04:00:00 PST"
reviewer = factories.PersonFactory()
reviewer_role_id = all_models.AccessControlRole.query.filter_by(
name="Reviewers",
object_type="Review",
).one().id
with factories.single_commit():
risk_admin = factories.PersonFactory()
risk = factories.RiskFactory()
risk.add_person_with_role_name(risk_admin, "Admin")
email_message = "email email_message"
_, review = self.generator.generate_object(
all_models.Review,
{
"reviewable": {
"type": risk.type,
"id": risk.id,
},
"context": None,
"notification_type":
all_models.Review.NotificationTypes.EMAIL_TYPE,
"status": all_models.Review.STATES.REVIEWED,
"email_message": email_message,
"access_control_list": [{
"ac_role_id": reviewer_role_id,
"person": {
"id": reviewer.id
},
}],
},
)
self.api.modify_object(review.reviewable, {"title": "new title"})
with mock.patch.object(fast_digest.DIGEST_TMPL, "render"):
fast_digest.send_notification()
for call_item in send_mail_mock.call_args_list:
self.assertEqual(expected_subject, call_item[1]["subject"])
示例12: TaskGroupRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [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
)
#.........这里部分代码省略.........
示例13: TestAccessControlListValidation
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [as 别名]
class TestAccessControlListValidation(TestCase):
"""Test AccessControlList validation."""
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
def test_create_with_wrong_acl(self):
"""Test creation of object with wrong ACR in ACL."""
response = self.api.post(all_models.Control, {
"control": {
"title": "Control title",
"context": None,
"access_control_list": [{
"ac_role_id": self.objective_admin_acr_id,
"person": {
"type": "Person",
"id": factories.PersonFactory().id,
}
}],
},
})
self.assert400(response)
self.assertEqual(all_models.Control.query.count(), 0)
def test_update_with_wrong_acl(self):
"""Test update of object with wrong ACR in ACL."""
with factories.single_commit():
control = factories.ControlFactory()
control_id = control.id
person_id = factories.PersonFactory().id
factories.AccessControlListFactory(
object_type="Control",
object_id=control_id,
person_id=person_id,
ac_role_id=self.control_admin_acr_id
)
response = self.api.put(
control,
{
"access_control_list": [{
"ac_role_id": self.objective_admin_acr_id,
"person": {
"type": "Person",
"id": person_id,
}
}]
}
)
self.assert400(response)
acls = all_models.AccessControlList.query.filter_by(
object_type="Control",
object_id=control_id
)
for acl in acls:
acl_obj_type = acl.object_type
acr_obj_type = acl.ac_role.object_type
self.assertEqual(acl_obj_type, acr_obj_type)
示例14: AssessmentRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [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)
#.........这里部分代码省略.........
示例15: IssueRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import put [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()
#.........这里部分代码省略.........