示例#1
0
  def test_sox_302_enabled_filter_tmpl(self, obj_value, filter_by_value):
    # pylint: disable=invalid-name
    """Test tmpl could be filtered by sox_302_enabled field."""
    with ggrc_factories.single_commit():
      tmpl = ggrc_factories.AssessmentTemplateFactory(
          sox_302_enabled=obj_value)
      ggrc_factories.AssessmentTemplateFactory(sox_302_enabled=(not obj_value))
    searched_tmpl_id = tmpl.id

    query_request_data = [
        self._make_query_dict(
            "AssessmentTemplate",
            expression=["SOX 302 assessment workflow", "=", filter_by_value],
        ),
    ]

    response = self.api.send_request(
        self.api.client.post, data=query_request_data, api_link="/query"
    )

    self.assert200(response)
    self._assert_right_obj_found(
        response.json,
        "AssessmentTemplate",
        searched_tmpl_id,
    )
    def test_generation_with_template_ids_given_0(self):
        """
      Test generation of csv file with filtered IDs
      ids of related assessment templates.

      0 - test that only assessment templates with given
      ids are used while gathering local custom attribute
      definitions
    """

        included_template_ids = []

        with factories.single_commit():
            included_template = factories.AssessmentTemplateFactory()
            excluded_template = factories.AssessmentTemplateFactory()

            assessment = factories.AssessmentFactory()
            assessment.audit = included_template.audit

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment_template",
                title="Included LCAD",
                definition_id=included_template.id,
            )

            included_template_ids.append(included_template.id)

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 0",
            )

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment_template",
                title="Excluded LCAD",
                definition_id=excluded_template.id)

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 1",
            )

        objects = [{
            "object_name": "Assessment",
            "template_ids": included_template_ids,
        }]

        response = self.export_csv_template(objects)

        self.assertIn('Included LCAD', response.data)
        self.assertNotIn("Excluded LCAD", response.data)
    def test_generation_without_template_ids_given(self):
        """
      Test generation of csv file without filtering by ids
    """

        with factories.single_commit():
            included_template_0 = factories.AssessmentTemplateFactory()
            included_template_1 = factories.AssessmentTemplateFactory()

            assessment = factories.AssessmentFactory()
            assessment.audit = included_template_0.audit

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment_template",
                title="Excluded LCAD 0",
                definition_id=included_template_0.id,
            )

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 0",
            )

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment_template",
                title="Excluded LCAD 1",
                definition_id=included_template_1.id)

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 1",
            )

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment",
                title="Included GCAD",
                definition_id=None)

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 1",
            )

        objects = [{"object_name": "Assessment"}]

        response = self.export_csv_template(objects)

        self.assertIn("Included GCAD", response.data)
        self.assertNotIn("Excluded LCAD 0", response.data)
        self.assertNotIn("Excluded LCAD 1", response.data)
示例#4
0
  def test_sox_302_asmt_with_tmpl_create(self, tmpl_value, sent_value,
                                         exp_value):
    # pylint: disable=invalid-name
    """Test SOX 302 enabled is mutable when create asmt with tmpl via API.

    Test `sox_302_enabled` on Assessment could be set via API if there is an
    AssessmentTemplate provided in request data. SOX 302 enabled flag is read
    only on Assessment and could be set only from template.
    """
    with ggrc_factories.single_commit():
      audit = ggrc_factories.AuditFactory()
      asmt_tmpl = ggrc_factories.AssessmentTemplateFactory(
          audit=audit,
          sox_302_enabled=tmpl_value,
      )
    audit_id = audit.id

    response = self.api.post(
        all_models.Assessment,
        {
            "assessment": {
                "audit": {"id": audit.id},
                "template": {"id": asmt_tmpl.id},
                "title": "Assessment Title",
                "sox_302_enabled": sent_value,
            },
        },
    )

    self.assert201(response)
    asmt = self._get_query_by_audit_for(all_models.Assessment, audit_id).one()
    self._assert_sox_302_enabled_flag(asmt, exp_value)
示例#5
0
  def test_sox_302_tmpl_clone(self, orig_value, exp_value):
    """Test AssessmentTemplate SOX 302 enabled={0} when clone via API."""
    tmpl = ggrc_factories.AssessmentTemplateFactory(
        sox_302_enabled=orig_value)
    audit_id = tmpl.audit.id
    tmpl_id = tmpl.id

    response = self.api.send_request(
        self.api.client.post,
        api_link="/api/assessment_template/clone",
        data=[{
            "sourceObjectIds": [tmpl.id],
            "destination": {
                "type": "Audit",
                "id": tmpl.audit.id,
            },
            "mappedObjects": []
        }],
    )

    self.assert200(response)
    tmpl_q = self._get_query_by_audit_for(
        all_models.AssessmentTemplate, audit_id)
    tmpl_clone = tmpl_q.filter(
        all_models.AssessmentTemplate.id != tmpl_id).one()
    self._assert_sox_302_enabled_flag(tmpl_clone, exp_value)
示例#6
0
  def test_sox_302_asmt_with_tmpl_upd(self, init_value, tmpl_value, exp_value):
    """Test SOX 302 enabled is immutable when update asmt with tmpl via import.

    Test `sox_302_enabled` on Assessment could not be set via import during
    Assessment update if there is an AssessmentTemplate provided in import
    data. SOX 302 enabled flag is read only on Assessment and could not be
    updated in noway.
    """
    with ggrc_factories.single_commit():
      asmt = ggrc_factories.AssessmentFactory(sox_302_enabled=init_value)
      tmpl = ggrc_factories.AssessmentTemplateFactory(
          audit=asmt.audit,
          sox_302_enabled=tmpl_value,
      )
    asmt_id = asmt.id

    asmt_data = collections.OrderedDict([
        ("object_type", "Assessment"),
        ("Code*", asmt.slug),
        ("Template", tmpl.slug),
    ])

    self._login()
    response = self.import_data(asmt_data)

    self._check_csv_response(response, {})
    asmt = self._refresh_object(asmt.__class__, asmt_id)
    self._assert_sox_302_enabled_flag(asmt, exp_value)
示例#7
0
  def test_sox_302_asmt_with_tmpl_create(self, tmpl_value, imported_value,
                                         exp_value):
    # pylint: disable=invalid-name
    """Test SOX 302 enabled is mutable when create asmt with tmpl via import.

    Test `sox_302_enabled` on Assessment could be set via import if there is an
    AssessmentTemplate provided in import data. SOX 302 enabled flag is read
    only on Assessment and could be set only from template.
    """
    with ggrc_factories.single_commit():
      audit = ggrc_factories.AuditFactory()
      tmpl = ggrc_factories.AssessmentTemplateFactory(
          audit=audit,
          sox_302_enabled=tmpl_value,
      )
    audit_id = audit.id

    asmt_data = collections.OrderedDict([
        ("object_type", "Assessment"),
        ("Code*", ""),
        ("Template", tmpl.slug),
        ("Audit*", audit.slug),
        ("Title", "Assessment Title"),
        ("Assignees", "*****@*****.**"),
        ("Creators", "*****@*****.**"),
        ("SOX 302 assessment workflow", imported_value),
    ])

    self._login()
    response = self.import_data(asmt_data)

    self._check_csv_response(response, {})
    asmt = self._get_query_by_audit_for(all_models.Assessment, audit_id).one()
    self._assert_sox_302_enabled_flag(asmt, exp_value)
示例#8
0
 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
             }
         })
示例#9
0
    def test_asmnt_template_clone(self):
        """Test assessment template cloning"""
        with factories.single_commit():
            audit1 = factories.AuditFactory()
            audit2 = factories.AuditFactory()
            assessment_template = factories.AssessmentTemplateFactory(
                template_object_type="Control",
                procedure_description="Test procedure",
                title="Test clone of Assessment Template",
                context=audit1.context,
            )
            factories.RelationshipFactory(source=audit1,
                                          destination=assessment_template)
            for cad_type in [
                    "Text", "Rich Text", "Checkbox", "Date", "Dropdown",
                    "Map:Person"
            ]:
                factories.CustomAttributeDefinitionFactory(
                    definition_type="assessment_template",
                    definition_id=assessment_template.id,
                    title="Test {}".format(cad_type),
                    attribute_type=cad_type,
                    multi_choice_options="a,b,c"
                    if cad_type == "Dropdown" else "",
                )

        self.clone_asmnt_templates([assessment_template.id], audit2)

        assessment_template = models.AssessmentTemplate.query.get(
            assessment_template.id)
        audit2 = models.Audit.query.get(audit2.id)
        template_copy = models.AssessmentTemplate.query.filter(
            models.AssessmentTemplate.title == assessment_template.title,
            models.AssessmentTemplate.id != assessment_template.id).first()
        self.assert_template_copy(assessment_template, template_copy, audit2)
示例#10
0
 def test_control_test_plan(self):
     """Test test_plan from control"""
     test_plan = self.control.test_plan
     template = factories.AssessmentTemplateFactory(
         test_plan_procedure=True)
     response = self.assessment_post(template)
     self.assertEqual(response.json["assessment"]["test_plan"], test_plan)
  def test_import_assessment_with_deleted_template(self):
    """Test import with deleted template from exported assessment"""
    with factories.single_commit():
      audit = factories.AuditFactory()
      assessment_template = factories.AssessmentTemplateFactory(audit=audit)
      assessment = factories.AssessmentFactory(audit=audit)
      factories.CustomAttributeDefinitionFactory(
          title='test_attr',
          definition_type='assessment_template',
          definition_id=assessment_template.id,
      )
      factories.CustomAttributeDefinitionFactory(
          title='test_attr',
          definition_type='assessment',
          definition_id=assessment.id,
      )
      db.session.delete(assessment_template)

    response = self.import_data(OrderedDict([
        ("object_type", "Assessment"),
        ("Code*", ""),
        ("Template", ""),
        ("Audit", audit.slug),
        ("Assignees", "*****@*****.**"),
        ("Creators", "*****@*****.**"),
        ("Title", "test-{id}Title".format(id=assessment.id)),
        ("test_attr", "asdfafs"),
    ]), dry_run=True)

    self._check_csv_response(response, {})
示例#12
0
    def test_autogenerated_auditors(self, add_verifier):
        """Test autogenerated assessment with auditor settings."""
        auditor_role = all_models.Role.query.filter_by(name="Auditor").first()

        users = ["*****@*****.**", "*****@*****.**"]
        with factories.single_commit():
            audit_context = factories.ContextFactory()
            self.audit.context = audit_context
            auditors = [factories.PersonFactory(email=e) for e in users]
            for auditor in auditors:
                rbac_factories.UserRoleFactory(context=audit_context,
                                               role=auditor_role,
                                               person=auditor)
            default_people = {"assessors": "Auditors"}
            if add_verifier:
                default_people["verifiers"] = "Auditors"
            template = factories.AssessmentTemplateFactory(
                test_plan_procedure=False,
                procedure_description="Assessment Template Test Plan",
                default_people=default_people)
        response = self.assessment_post(template)
        self.assert_assignees("Assessor", response, *users)
        if add_verifier:
            self.assert_assignees("Verifier", response, *users)
        else:
            self.assert_assignees("Verifier", response)
        self.assert_assignees("Creator", response, "*****@*****.**")
示例#13
0
    def test_asmt_with_mandatory_lca_to_deprecated_state(self):
        """Test new Assessment with not filled mandatory LCA could be Deprecated"""
        # pylint: disable=attribute-defined-outside-init
        with factories.single_commit():
            self.audit = factories.AuditFactory()
            self.control = factories.ControlFactory(
                test_plan="Control Test Plan")
            self.snapshot = self._create_snapshots(self.audit,
                                                   [self.control])[0]

            template = factories.AssessmentTemplateFactory(
                test_plan_procedure=False,
                procedure_description="Assessment Template Test Plan")
            custom_attribute_definition = {
                "definition_type": "assessment_template",
                "definition_id": template.id,
                "title": "test checkbox",
                "attribute_type": "Checkbox",
                "multi_choice_options": "test checkbox label",
                "mandatory": True,
            }
            factories.CustomAttributeDefinitionFactory(
                **custom_attribute_definition)

        response = self.assessment_post(template)

        self.assertEqual(response.json["assessment"]["status"],
                         models.Assessment.START_STATE)
        asmt = models.Assessment.query.get(response.json["assessment"]["id"])
        asmt = self.change_status(asmt, models.Assessment.DEPRECATED)
        asmt = self.refresh_object(asmt)
        self.assertEqual(asmt.status, models.Assessment.DEPRECATED)
示例#14
0
 def test_cloned_assessment_template_status(self, status):
   """Test that the status of cloned Assessment Template is equal original
   Assessment Template status"""
   audit_1 = factories.AuditFactory()
   audit_2 = factories.AuditFactory()
   assessment_template = factories.AssessmentTemplateFactory(
       template_object_type="Control",
       procedure_description="Test procedure",
       title="Test clone of Assessment Template",
       context=audit_1.context,
       status=status,
   )
   factories.RelationshipFactory(
       source=audit_1,
       destination=assessment_template
   )
   self.clone_asmnt_templates([assessment_template.id], audit_2)
   templates_count = models.AssessmentTemplate.query.count()
   self.assertEqual(templates_count, 2,
                    msg="Unexpected assessment templates "
                        "appeared in database.")
   template_copy = models.AssessmentTemplate.query.filter(
       models.AssessmentTemplate.title == assessment_template.title,
       models.AssessmentTemplate.id != assessment_template.id
   ).first()
   self.assertEqual(template_copy.status, status)
示例#15
0
    def test_autogenerated_assignees_base_on_audit(self, assessor_role,
                                                   verifier_role):
        """Test autogenerated assessment assignees base on audit setting

    and empty tmpl."""
        assessor_audit = "*****@*****.**"
        verifier_audit = "*****@*****.**"
        with factories.single_commit():
            default_people = {"assignees": assessor_role}
            if verifier_role is not None:
                default_people["verifiers"] = verifier_role
            self.generate_acls([assessor_audit], self.captains_role)
            self.generate_acls([verifier_audit], self.auditor_role)
            self.snapshot.revision.content = self.control.log_json()
            db.session.add(self.snapshot.revision)
            template = factories.AssessmentTemplateFactory(
                test_plan_procedure=False,
                procedure_description="Assessment Template Test Plan",
                default_people=default_people)
        response = self.assessment_post(template)
        self.assert_assignees("Assignees", response, assessor_audit)
        if verifier_role:
            self.assert_assignees("Verifiers", response, verifier_audit)
        else:
            self.assert_assignees("Verifiers", response)
        self.assert_assignees("Creators", response, "*****@*****.**")
示例#16
0
 def test_import_template_update(self, verifier_update_email,
                                 default_verifiers):
     """Test for template update via import."""
     with mock.patch.multiple(PersonClient, _post=self._mock_post):
         audit = factories.AuditFactory()
         assessment_template = factories.AssessmentTemplateFactory(
             audit=audit)
         response = self.import_data(
             OrderedDict([
                 ('object_type', 'Assessment_Template'),
                 ('Code*', assessment_template.slug),
                 ('Audit*', audit.slug),
                 ('Default Assignees', '*****@*****.**'),
                 ('Default Verifiers', verifier_update_email),
                 ('Title', 'Title'),
                 ('Default Assessment Type', 'Control'),
             ]))
         updated_template = AssessmentTemplate.query.filter(
             AssessmentTemplate.slug == assessment_template.slug).first()
         self._check_csv_response(response, {})
         self.assertNotEqual(
             updated_template.default_people['assignees'],
             assessment_template.default_people['assignees'])
         self.assertEqual(updated_template.default_people['verifiers'],
                          default_verifiers)
示例#17
0
    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
示例#18
0
 def test_template_test_plan(self):
     """Test if generating assessments from template sets default test plan"""
     template = factories.AssessmentTemplateFactory(
         test_plan_procedure=False,
         procedure_description="Assessment Template Test Plan")
     response = self.assessment_post(template)
     self.assertEqual(response.json["assessment"]["test_plan"],
                      template.procedure_description)
示例#19
0
    def setUpClass(cls):
        """Prepare data needed to run the tests."""
        TestCase.clear_data()

        with app.app_context():
            cls.response = cls._import_file("audit_rbac.csv")
            cls.people = {
                person.name: person
                for person in all_models.Person.eager_query().all()
            }
            created_objects = (
                (all_models.Audit, all_models.Audit.slug == 'AUDIT-1',
                 'audit'), (all_models.Audit,
                            all_models.Audit.slug == 'AUDIT-2',
                            'archived_audit'),
                (all_models.Issue, all_models.Issue.slug == 'PMRBACISSUE-1',
                 'issue'), (all_models.Issue,
                            all_models.Issue.slug == 'PMRBACISSUE-2',
                            'archived_issue'),
                (all_models.Assessment,
                 all_models.Assessment.slug == 'PMRBACASSESSMENT-1',
                 'assessment'),
                (all_models.Assessment,
                 all_models.Assessment.slug == 'PMRBACASSESSMENT-2',
                 'archived_assessment'))
            for obj, cond, name in created_objects:
                setattr(cls, name, obj.eager_query().filter(cond).first())

            revision = all_models.Revision.query.filter(
                all_models.Revision.resource_type == 'Objective').first()
            cls.rev_id = revision.id

            # Create snapshot objects:
            for audit, name in ((cls.audit, 'snapshot'),
                                (cls.archived_audit, 'archived_snapshot')):
                snapshot = factories.SnapshotFactory(
                    child_id=revision.resource_id,
                    child_type=revision.resource_type,
                    parent=audit,
                    revision=revision,
                    context=audit.context,
                )
                factories.RelationshipFactory(source=audit,
                                              destination=snapshot)
                setattr(cls, name, snapshot)

            # Create asessment template objects:
            for audit, name in ((cls.audit, 'template'),
                                (cls.archived_audit, 'archived_template')):
                template = factories.AssessmentTemplateFactory(
                    context=audit.context, )
                factories.RelationshipFactory(source=audit,
                                              destination=template,
                                              context=audit.context)
                setattr(cls, name, template)
            # Refresh objects in the session
            for obj in db.session:
                db.session.refresh(obj)
示例#20
0
    def setup_objects(self):
        """Sets up all the objects needed by the tests"""
        objects = self.objects
        # Program
        objects['program'] = program = factories.ProgramFactory(
            title="A Program")
        # Controls
        objects['controls'] = controls = [
            factories.ControlFactory(title="My First Control"),
            factories.ControlFactory(title="My Second Control")
        ]

        # Audit
        objects['audit'] = audit = factories.AuditFactory(
            program=objects['program'],
            access_control_list=[{
                "ac_role_id": self.audit_roles['Auditors'].id,
                "person": {
                    "id": self.people['created_auditor'].id
                },
            }, {
                "ac_role_id":
                self.audit_roles['Audit Captains'].id,
                "person": {
                    "id": self.people['created_captain'].id
                },
            }])
        factories.RelationshipFactory(source=program, destination=audit)
        # Assessment template
        objects['assessment_template'] = factories.AssessmentTemplateFactory()

        # Assessment
        objects['assessment'] = factories.AssessmentFactory(audit=audit)

        # Snapshot
        objects['snapshots'] = self._create_snapshots(audit, controls)
        for snapshot in objects['snapshots']:
            factories.RelationshipFactory(source=audit, destination=snapshot)

        # Issues
        objects['issue'] = factories.IssueFactory(
            access_control_list=[{
                "ac_role_id": self.issue_roles['Admin'].id,
                "person": {
                    "id": self.people['issue_admin'].id
                },
            }])

        # Comments
        objects['comment'] = factories.CommentFactory()
        objects['issue_comment'] = factories.CommentFactory()

        # Documents
        objects['issue_document'] = factories.DocumentFactory()

        # Evidence
        objects['evidence'] = factories.EvidenceUrlFactory()
    def test_procedure_description(self):
        """Test correct export of Default Assessment Procedure field"""
        proc_description = "some description"
        factories.AssessmentTemplateFactory(
            title="Audit Lead", procedure_description=proc_description)

        response = self.export_parsed_csv(self.EXPORT_ALL_FIELDS_DATA)
        assessment_template = response["Assessment Template"][0]
        self.assertEqual(proc_description,
                         assessment_template["Default Assessment Procedure"])
    def test_empty_people_export(self):
        """Test for check people label export"""
        default_people = {"assignees": "Auditors", "verifiers": None}
        factories.AssessmentTemplateFactory(title="Audit Lead",
                                            default_people=default_people)

        response = self.export_parsed_csv(self.EXPORT_ALL_FIELDS_DATA)
        assessment_template = response["Assessment Template"][0]
        self.assertEqual(assessment_template["Default Assignees*"], "Auditors")
        self.assertEqual(assessment_template["Default Verifiers"], "--")
    def test_people_labels_export(self, title, label):
        """Test for check people label export"""
        default_people = {"assignees": label, "verifiers": label}
        factories.AssessmentTemplateFactory(title=title,
                                            default_people=default_people)

        response = self.export_parsed_csv(self.EXPORT_ALL_FIELDS_DATA)
        assessment_template = response["Assessment Template"][0]
        self.assertEqual(assessment_template["Default Assignees*"], title)
        self.assertEqual(assessment_template["Default Verifiers"], title)
示例#24
0
    def test_ca_order(self):
        """Test LCA/GCA order in Assessment"""
        template = factories.AssessmentTemplateFactory(
            test_plan_procedure=False,
            procedure_description="Assessment Template Test Plan")

        custom_attribute_definitions = [
            # Global CAs
            {
                "definition_type": "assessment",
                "title": "rich_test_gca",
                "attribute_type": "Rich Text",
                "multi_choice_options": ""
            },
            {
                "definition_type": "assessment",
                "title": "checkbox1_gca",
                "attribute_type": "Checkbox",
                "multi_choice_options": "test checkbox label"
            },
            # Local CAs
            {
                "definition_type": "assessment_template",
                "definition_id": template.id,
                "title": "test text field",
                "attribute_type": "Text",
                "multi_choice_options": ""
            },
            {
                "definition_type": "assessment_template",
                "definition_id": template.id,
                "title": "test RTF",
                "attribute_type": "Rich Text",
                "multi_choice_options": ""
            },
            {
                "definition_type": "assessment_template",
                "definition_id": template.id,
                "title": "test checkbox",
                "attribute_type": "Checkbox",
                "multi_choice_options": "test checkbox label"
            },
        ]

        for attribute in custom_attribute_definitions:
            factories.CustomAttributeDefinitionFactory(**attribute)
        response = self.assessment_post(template)
        self.assertListEqual([
            u'test text field', u'test RTF', u'test checkbox',
            u'rich_test_gca', u'checkbox1_gca'
        ], [
            cad['title'] for cad in response.json["assessment"]
            ["custom_attribute_definitions"]
        ])
示例#25
0
 def test_delete_audit_asmnt_tmpl(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.assertStatus(response, 409)
     self.assertEqual(response.json["message"], errors.MAPPED_ASSESSMENT)
示例#26
0
 def test_autogenerated_assignees_base_on_role(self, assessor_role,
                                               verifier_role):
     """Test autogenerated assessment assignees base on template settings."""
     assessor = "*****@*****.**"
     verifier = "*****@*****.**"
     auditors = collections.defaultdict(list)
     with factories.single_commit():
         self.audit.context = factories.ContextFactory()
         auditors[assessor_role].append(
             factories.PersonFactory(email=assessor))
         if verifier_role is not None:
             auditors[verifier_role].append(
                 factories.PersonFactory(email=verifier))
         for role, people in auditors.iteritems():
             ac_role = all_models.AccessControlRole.query.filter_by(
                 name=role,
                 object_type=self.snapshot.child_type,
             ).first()
             if not ac_role:
                 ac_role = factories.AccessControlRoleFactory(
                     name=role,
                     object_type=self.snapshot.child_type,
                 )
                 factories.AccessControlListFactory(
                     ac_role=ac_role,
                     object=self.control,  # snapshot child
                 )
                 db.session.commit()
             for user in people:
                 factories.AccessControlPersonFactory(
                     ac_list=self.control.acr_acl_map[ac_role],
                     person=user,
                 )
         default_people = {"assignees": assessor_role}
         if verifier_role is not None:
             default_people["verifiers"] = verifier_role
         template = factories.AssessmentTemplateFactory(
             test_plan_procedure=False,
             procedure_description="Assessment Template Test Plan",
             default_people=default_people)
         self.snapshot.revision.content = self.control.log_json()
         db.session.add(self.snapshot.revision)
     response = self.assessment_post(template)
     if assessor_role == verifier_role:
         self.assert_assignees("Verifiers", response, assessor, verifier)
         self.assert_assignees("Assignees", response, assessor, verifier)
     elif verifier_role is None:
         self.assert_assignees("Verifiers", response)
         self.assert_assignees("Assignees", response, assessor)
     else:
         self.assert_assignees("Verifiers", response, verifier)
         self.assert_assignees("Assignees", response, assessor)
     self.assert_assignees("Creators", response, "*****@*****.**")
示例#27
0
    def test_delete_http400(self):
        """Deletion returns HTTP400 if BadRequest is raised."""
        with factories.single_commit():
            audit = factories.AuditFactory()
            factories.AssessmentTemplateFactory(audit=audit)

        result = self.api.delete(audit)

        self.assert400(result)
        self.assertEqual(
            result.json["message"],
            "This request will break a mandatory relationship from "
            "assessment_templates to audits.")
示例#28
0
 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_generation_with_template_ids_given_1(self):
        """
      Test that GCA are not filtered out by template_ids.

      1 - test that global custom attribute definitions
      are not filtered out by template_ids related filter.
    """

        included_template_ids = []

        with factories.single_commit():
            included_template = factories.AssessmentTemplateFactory()

            assessment = factories.AssessmentFactory()
            assessment.audit = included_template.audit

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment_template",
                title="Included LCAD",
                definition_id=included_template.id,
            )

            included_template_ids.append(included_template.id)

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 0",
            )

            cad = factories.CustomAttributeDefinitionFactory(
                definition_type="assessment",
                title="Included GCAD",
                definition_id=None)

            factories.CustomAttributeValueFactory(
                custom_attribute=cad,
                attributable=assessment,
                attribute_value="Test CAD 1",
            )

        objects = [{
            "object_name": "Assessment",
            "template_ids": included_template_ids,
        }]

        response = self.export_csv_template(objects)

        self.assertIn('Included LCAD', response.data)
        self.assertIn("Included GCAD", response.data)
示例#30
0
 def test_generate_empty_auditor(self):
   """Test generation in audit without Auditor from template with Auditor."""
   with factories.single_commit():
     person = factories.PersonFactory()
     self.audit.add_person_with_role(person, self.captains_role)
     template = factories.AssessmentTemplateFactory(
         default_people={"assignees": "Auditors", "verifiers": "Auditors"}
     )
   response = self.assessment_post(template)
   self.assert_assignees("Creators", response, "*****@*****.**")
   audit = all_models.Audit.query.get(self.audit_id)
   acp = audit.acr_name_acl_map["Audit Captains"].access_control_people[0]
   # If Auditor is not set, Audit Captain should be used as Assignee
   self.assert_assignees("Assignees", response, acp.person.email)
   self.assert_assignees("Verifiers", response, acp.person.email)