Esempio n. 1
0
  def test_relationship_single_layer(self):
    """Test single layer propagation through relationships.

    Test propagation of a new relationship between audit and assessment. Here
    we check that propagation happens both ways on the relationship creation.
    """

    with factories.single_commit():
      person = factories.PersonFactory()
      audit = factories.AuditFactory()
      assessment1 = factories.AssessmentFactory(audit=audit)
      assessment2 = factories.AssessmentFactory(audit=audit)

      # This is excluded from propagation to test for proper filtering
      assessment3 = factories.AssessmentFactory(audit=audit)
      factories.RelationshipFactory(source=assessment3, destination=audit)

      relationship_ids = [
          factories.RelationshipFactory(
              source=assessment1,
              destination=audit,
          ).id,
          factories.RelationshipFactory(
              source=audit,
              destination=assessment2,
          ).id,
      ]

      factories.AccessControlListFactory(
          ac_role=self.roles["Audit"]["Audit Captains"],
          object=audit,
          person=person,
      )
      factories.AccessControlListFactory(
          ac_role=self.roles["Assessment"]["Assignees"],
          object=assessment1,
          person=person,
      )
      factories.AccessControlListFactory(
          ac_role=self.roles["Assessment"]["Assignees"],
          object=assessment2,
          person=person,
      )

    child_ids = propagation._handle_relationship_step(relationship_ids, [])

    self.assertEqual(
        all_models.AccessControlList.query.count(),
        3 + 2 + 2 + 4
        # 3 Initial roles
        # 2 roles for assessment 1 propagation to relationship and audit
        # 2 roles for assessment 2 propagation to relationship and audit
        # 4 for audit role propagation to two relationships and assessments
    )
    self.assertEqual(
        db.session.execute(child_ids.alias("counts").count()).scalar(),
        4,  # audit captain to both assessments and both assignees to audit
    )
Esempio n. 2
0
    def test_relationship_single_layer(self):
        """Test single layer propagation through relationships.

    Test propagation of a new relationship between audit and assessment. Here
    we check that propagation happens both ways on the relationship creation.
    """

        with factories.single_commit():
            person = factories.PersonFactory()
            audit = factories.AuditFactory()
            assessment1 = factories.AssessmentFactory(audit=audit)
            assessment2 = factories.AssessmentFactory(audit=audit)

            # This is excluded from propagation to test for proper filtering
            assessment3 = factories.AssessmentFactory(audit=audit)
            factories.RelationshipFactory(source=assessment3,
                                          destination=audit)

            relationship_ids = [
                factories.RelationshipFactory(
                    source=assessment1,
                    destination=audit,
                ).id,
                factories.RelationshipFactory(
                    source=audit,
                    destination=assessment2,
                ).id,
            ]

            factories.AccessControlListFactory(
                ac_role=self.roles["Audit"]["Audit Captains"],
                object=audit,
                person=person,
            )
            factories.AccessControlListFactory(
                ac_role=self.roles["Assessment"]["Assignees"],
                object=assessment1,
                person=person,
            )
            factories.AccessControlListFactory(
                ac_role=self.roles["Assessment"]["Assignees"],
                object=assessment2,
                person=person,
            )

        child_ids = propagation._handle_relationship_step(relationship_ids, [])

        self.assertEqual(
            all_models.AccessControlList.query.count(), 3 + 2 + 2 + 4
            # 3 Initial roles
            # 2 roles for assessment 1 propagation to relationship and audit
            # 2 roles for assessment 2 propagation to relationship and audit
            # 4 for audit role propagation to two relationships and assessments
        )
        self.assertEqual(
            db.session.execute(child_ids.alias("counts").count()).scalar(),
            4,  # audit captain to both assessments and both assignees to audit
        )
Esempio n. 3
0
    def test_relationship_single_layer(self):
        """Test single layer propagation through relationships.

    Test propagation of a new relationship between audit and assessment. Here
    we check that propagation happens both ways on the relationship creation.
    """

        with factories.single_commit():
            audit = factories.AuditFactory()
            assessment1 = factories.AssessmentFactory(audit=audit)
            assessment2 = factories.AssessmentFactory(audit=audit)

            # This is excluded from propagation to test for proper filtering
            assessment3 = factories.AssessmentFactory(audit=audit)
            factories.RelationshipFactory(source=assessment3,
                                          destination=audit)

            relationship_ids = [
                factories.RelationshipFactory(
                    source=assessment1,
                    destination=audit,
                ).id,
                factories.RelationshipFactory(
                    source=audit,
                    destination=assessment2,
                ).id,
            ]

        with app.app.app_context():
            flask.g.user_ids = set()
            child_ids = propagation._handle_relationship_step(
                relationship_ids,
                [],
                self.user_id,
            )

        self.assertEqual(
            all_models.AccessControlList.query.filter(
                all_models.AccessControlList.parent_id.isnot(None)).count(),
            20)
        self.assertEqual(
            db.session.execute(child_ids.alias("counts").count()).scalar(),
            10,
        )
Esempio n. 4
0
  def test_relationship_single_layer(self):
    """Test single layer propagation through relationships.

    Test propagation of a new relationship between audit and assessment. Here
    we check that propagation happens both ways on the relationship creation.
    """

    with factories.single_commit():
      audit = factories.AuditFactory()
      assessment1 = factories.AssessmentFactory(audit=audit)
      assessment2 = factories.AssessmentFactory(audit=audit)

      # This is excluded from propagation to test for proper filtering
      assessment3 = factories.AssessmentFactory(audit=audit)
      factories.RelationshipFactory(source=assessment3, destination=audit)

      relationship_ids = [
          factories.RelationshipFactory(
              source=assessment1,
              destination=audit,
          ).id,
          factories.RelationshipFactory(
              source=audit,
              destination=assessment2,
          ).id,
      ]

    child_ids = propagation._handle_relationship_step(
        relationship_ids,
        [],
        self.user_id,
    )

    self.assertEqual(
        all_models.AccessControlList.query.filter(
            all_models.AccessControlList.parent_id.isnot(None)
        ).count(),
        20
    )
    self.assertEqual(
        db.session.execute(child_ids.alias("counts").count()).scalar(),
        10,
    )