本文整理汇总了Python中integration.ggrc.Api.modify_object方法的典型用法代码示例。如果您正苦于以下问题:Python Api.modify_object方法的具体用法?Python Api.modify_object怎么用?Python Api.modify_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类integration.ggrc.Api
的用法示例。
在下文中一共展示了Api.modify_object方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEvidenceRolePropagation
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import modify_object [as 别名]
class TestEvidenceRolePropagation(TestCase):
"""Evidence role propagation test case"""
# pylint: disable=invalid-name
def setUp(self):
super(TestEvidenceRolePropagation, self).setUp()
self.api = Api()
self.generator = ObjectGenerator()
# Propagation isn't work for 'Primary Contacts', 'Secondary Contacts'
# just add them to data list to check if fix works.
@ddt.data("Assignees", "Creators", "Verifiers")
def test_assessment_role_propagation_edit(self, role_name):
"""Asses user with role '{0}' should be able to edit related evidence"""
_, reader = self.generator.generate_person(user_role="Creator")
with factories.single_commit():
assessment = factories.AssessmentFactory()
assessment.add_person_with_role_name(reader, role_name)
evidence = factories.EvidenceFactory()
evidence_id = evidence.id
factories.RelationshipFactory(source=assessment, destination=evidence)
self.api.set_user(reader)
evidence = all_models.Evidence.query.get(evidence_id)
new_description = 'new description'
resp = self.api.modify_object(evidence, {'description': new_description})
evidence = self.refresh_object(evidence)
self.assert200(resp)
self.assertEquals(new_description, evidence.description)
self.assertEquals(reader.id, evidence.modified_by_id)
@ddt.data(
("Creator", "Audit Captains", 200),
("Creator", "Auditors", 403),
("Reader", "Audit Captains", 200),
("Reader", "Auditors", 403),
("Editor", "Audit Captains", 200),
("Editor", "Auditors", 200),
)
@ddt.unpack
def test_audit_role_propagation_edit(self, user_role, audit_role,
status_code):
"""'{0}' assigned as '{1}' should get '{2}' when editing audit evidence"""
_, user = self.generator.generate_person(user_role=user_role)
with factories.single_commit():
audit = factories.AuditFactory()
audit.add_person_with_role_name(user, audit_role)
evidence = factories.EvidenceFactory()
evidence_id = evidence.id
factories.RelationshipFactory(source=audit, destination=evidence)
self.api.set_user(user)
evidence = all_models.Evidence.query.get(evidence_id)
new_description = 'new description'
resp = self.api.modify_object(evidence, {'description': new_description})
evidence = self.refresh_object(evidence)
if status_code == 200:
self.assert200(resp)
self.assertEquals(new_description, evidence.description)
self.assertEquals(user.id, evidence.modified_by_id)
else:
self.assertStatus(resp, status_code)
def test_audit_role_propagation_not_delete(self):
"""Audit user with role Auditors can NOT delete related evidence"""
role_name = "Auditors"
_, reader = self.generator.generate_person(user_role="Reader")
with factories.single_commit():
audit = factories.AuditFactory()
audit.add_person_with_role_name(reader, role_name)
evidence = factories.EvidenceFactory()
evidence_id = evidence.id
factories.RelationshipFactory(source=audit, destination=evidence)
self.api.set_user(reader)
evidence = all_models.Evidence.query.get(evidence_id)
resp = self.api.delete(evidence)
self.assertStatus(resp, 403)
evidence = all_models.Evidence.query.get(evidence_id)
self.assertTrue(evidence)
示例2: AuditRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import modify_object [as 别名]
#.........这里部分代码省略.........
})
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(
person_id=self.user_id,
ac_list=acl
)
audit = all_models.Audit.query.get(self.audit_id)
return self.objgen.generate_relationship(
source=audit,
destination=control,
)[0]
def deprecate(self):
"""Set status 'Deprecated' for Audit."""
audit = all_models.Audit.query.get(self.audit_id)
return self.api.modify_object(audit, {
"status": "Deprecated"
})
def archive(self):
"""Move Audit into archived state."""
audit = all_models.Audit.query.get(self.audit_id)
return self.api.modify_object(audit, {
"archived": True
})
def unarchive(self):
"""Move Audit into unarchived state."""
audit = all_models.Audit.query.get(self.audit_id)
return self.api.modify_object(audit, {
"archived": False
})
def summary(self):
"""Get Audit summary information."""
return self.api.client.get(
"api/audits/{}/{}".format(self.audit_id, "summary")
)
示例3: TestEvidenceRolePropagation
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import modify_object [as 别名]
class TestEvidenceRolePropagation(TestCase):
"""Evidence role propagation test case"""
# pylint: disable=invalid-name
def setUp(self):
super(TestEvidenceRolePropagation, self).setUp()
self.api = Api()
self.generator = ObjectGenerator()
# Propagation isn't work for 'Primary Contacts', 'Secondary Contacts'
# just add them to data list to check if fix works.
@ddt.data("Assignees", "Creators", "Verifiers")
def test_assessment_role_propagation_edit(self, role):
"""Asses user with role '{0}' should be able to edit related evidence"""
_, reader = self.generator.generate_person(user_role="Creator")
assignees_role = all_models.AccessControlRole.query.filter_by(
object_type=all_models.Assessment.__name__, name=role
).first()
with factories.single_commit():
assessment = factories.AssessmentFactory()
factories.AccessControlListFactory(
ac_role=assignees_role,
object=assessment,
person=reader
)
evidence = factories.EvidenceFactory()
evidence_id = evidence.id
factories.RelationshipFactory(source=assessment, destination=evidence)
self.api.set_user(reader)
evidence = all_models.Evidence.query.get(evidence_id)
new_description = 'new description'
resp = self.api.modify_object(evidence, {'description': new_description})
evidence = self.refresh_object(evidence)
self.assert200(resp)
self.assertEquals(new_description, evidence.description)
self.assertEquals(reader.id, evidence.modified_by_id)
@ddt.data("Audit Captains", "Auditors")
def test_audit_role_propagation_edit(self, role):
"""Audit user with role '{0}' should be able to edit related evidence"""
_, reader = self.generator.generate_person(user_role="Reader")
assignees_role = all_models.AccessControlRole.query.filter_by(
object_type=all_models.Audit.__name__, name=role
).first()
with factories.single_commit():
audit = factories.AuditFactory()
factories.AccessControlListFactory(
ac_role=assignees_role,
object=audit,
person=reader
)
evidence = factories.EvidenceFactory()
evidence_id = evidence.id
factories.RelationshipFactory(source=audit, destination=evidence)
self.api.set_user(reader)
evidence = all_models.Evidence.query.get(evidence_id)
new_description = 'new description'
resp = self.api.modify_object(evidence, {'description': new_description})
evidence = self.refresh_object(evidence)
self.assert200(resp)
self.assertEquals(new_description, evidence.description)
self.assertEquals(reader.id, evidence.modified_by_id)
def test_audit_role_propagation_not_delete(self, role="Auditors"):
"""Audit user with role Auditors can NOT delete related evidence"""
_, reader = self.generator.generate_person(user_role="Reader")
assignees_role = all_models.AccessControlRole.query.filter_by(
object_type=all_models.Audit.__name__, name=role
).first()
with factories.single_commit():
audit = factories.AuditFactory()
factories.AccessControlListFactory(
ac_role=assignees_role,
object=audit,
person=reader
)
evidence = factories.EvidenceFactory()
evidence_id = evidence.id
factories.RelationshipFactory(source=audit, destination=evidence)
self.api.set_user(reader)
evidence = all_models.Evidence.query.get(evidence_id)
resp = self.api.delete(evidence)
self.assertStatus(resp, 403)
evidence = all_models.Evidence.query.get(evidence_id)
self.assertTrue(evidence)
示例4: TestReviewNotification
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import modify_object [as 别名]
class TestReviewNotification(TestCase):
"""Test notification on Review status change."""
def setUp(self):
super(TestReviewNotification, self).setUp()
self.client.get("/login")
self.generator = generator.ObjectGenerator()
self.api = Api()
@ddt.data(
(all_models.Review.NotificationTypes.EMAIL_TYPE, 1),
(all_models.Review.NotificationTypes.ISSUE_TRACKER, 0),
)
@ddt.unpack
def test_notification_add_new_review(
self, notification_type, expected_notifications
):
"""After creation of new review notification should be created"""
program = factories.ProgramFactory()
resp, _ = self.generator.generate_object(
all_models.Review,
{
"reviewable": {
"type": program.type,
"id": program.id,
},
"context": None,
"notification_type": notification_type,
"status": all_models.Review.STATES.UNREVIEWED,
"access_control_list": build_reviewer_acl(),
},
)
self.assertEqual(201, resp.status_code)
self.assertEqual(
expected_notifications, len(all_models.Notification.query.all())
)
@ddt.data(
(all_models.Review.NotificationTypes.EMAIL_TYPE, 1),
(all_models.Review.NotificationTypes.ISSUE_TRACKER, 0),
)
@ddt.unpack
def test_reviewable_attributes(self, notification_type,
expected_notifications):
"""Review change state to Unreviewed
Notification with notification type STATUS_UNREVIEWED created
"""
with factories.single_commit():
program = factories.ProgramFactory()
review = factories.ReviewFactory(
status=all_models.Review.STATES.REVIEWED,
reviewable=program,
notification_type=notification_type
)
review_id = review.id
reviewable = review.reviewable
self.api.modify_object(reviewable, {"title": "new title"})
review = all_models.Review.query.get(review_id)
self.assertEqual(review.status, all_models.Review.STATES.UNREVIEWED)
review_notif_types = all_models.Review.NotificationObjectTypes
notyf_unreviewed_type = all_models.Notification.query.join(
all_models.NotificationType
).filter(
all_models.NotificationType.name ==
review_notif_types.STATUS_UNREVIEWED
).all()
self.assertEqual(expected_notifications, len(notyf_unreviewed_type))
@ddt.data(
(all_models.Review.NotificationTypes.EMAIL_TYPE, 1),
(all_models.Review.NotificationTypes.ISSUE_TRACKER, 0),
)
@ddt.unpack
def test_map_snapshotable_notification(self, notification_type,
expected_notifications):
"""Map snapshotable should change review status and add notification"""
with factories.single_commit():
program = factories.ProgramFactory()
review = factories.ReviewFactory(
status=all_models.Review.STATES.REVIEWED,
reviewable=program,
notification_type=notification_type
)
review_id = review.id
self.generator.generate_relationship(
source=program,
destination=factories.ProductFactory(),
context=None,
)
review = all_models.Review.query.get(review_id)
self.assertEqual(review.status, all_models.Review.STATES.UNREVIEWED)
review_notif_types = all_models.Review.NotificationObjectTypes
notyf_unreviewed_type = all_models.Notification.query.join(
#.........这里部分代码省略.........
示例5: AssessmentRBACFactory
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import modify_object [as 别名]
#.........这里部分代码省略.........
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)
control = factories.ControlFactory()
# pylint: disable=protected-access
snapshot = TestCase._create_snapshots(audit, [control])[0]
factories.RelationshipFactory(source=snapshot, destination=audit)
return self.objgen.generate_relationship(
source=assessment,
destination=snapshot,
)[0]
def deprecate(self):
"""Set status 'Deprecated' for Assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.modify_object(assessment, {"status": "Deprecated"})
def complete(self):
"""Set status 'Completed' for Assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(assessment, {"status": "Completed"})
def in_progress(self):
"""Set status 'In Progress' for Assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(assessment, {"status": "In Progress"})
def not_started(self):
"""Set status 'Not Started' for Assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(assessment, {"status": "Not Started"})
def decline(self):
"""Set status 'Rework Needed' for Assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(assessment, {"status": "Rework Needed"})
def verify(self):
"""Set status 'Verified' for Assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(assessment, {"status": "Completed", "verified": True})
def map_comment(self):
"""Map new comment to assessment."""
assessment = all_models.Assessment.query.get(self.assessment_id)
return self.api.put(assessment, {
"actions": {