Example #1
0
 def test_relationship__select_by_foreign_keys__no_match(self):
     """Verify select_by_foreign_keys method returns None if there is no match.
     """
     retrieved_rel = Relationship.select_by_foreign_keys(subject_id=uuid.uuid4(),
                                                         object_id=uuid.uuid4(),
                                                         relationship_type_id=uuid.uuid4())
     self.assertIsNone(retrieved_rel, "Expected to not find persisted Relationship")
Example #2
0
    def test_relationship__select_by_foreign_keys(self):
        """Verify select_by_foreign_keys method finds expected Relationship.
        """
        rel_type_id = uuid.uuid4()
        subject_id = uuid.uuid4()
        object_id = uuid.uuid4()

        fk_sets = [(rel_type_id, subject_id, object_id),
                   (uuid.uuid4(), subject_id, object_id),
                   (rel_type_id, uuid.uuid4(), object_id),
                   (rel_type_id, subject_id, uuid.uuid4())]

        for (rt_id, s_id, o_id) in fk_sets:
            db.session.add(Relationship(relationship_type_id=rt_id,
                                        subject_id=s_id,
                                        object_id=o_id))
        self.reset_session()

        retrieved_rel = Relationship.select_by_foreign_keys(subject_id=subject_id, 
                                                            object_id=object_id,
                                                            relationship_type_id=rel_type_id)
        self.assertIsNotNone(retrieved_rel, "Expected to find persisted Relationship")
        self.assertEqual(rel_type_id, retrieved_rel.relationship_type_id)
        self.assertEqual(subject_id, retrieved_rel.subject_id)
        self.assertEqual(object_id, retrieved_rel.object_id)
Example #3
0
    def test_relationship__select_by_foreign_keys(self):
        """Verify select_by_foreign_keys method finds expected Relationship.
        """
        rel_type_id = uuid.uuid4()
        subject_id = uuid.uuid4()
        object_id = uuid.uuid4()

        fk_sets = [(rel_type_id, subject_id, object_id),
                   (uuid.uuid4(), subject_id, object_id),
                   (rel_type_id, uuid.uuid4(), object_id),
                   (rel_type_id, subject_id, uuid.uuid4())]

        for (rt_id, s_id, o_id) in fk_sets:
            db.session.add(
                Relationship(relationship_type_id=rt_id,
                             subject_id=s_id,
                             object_id=o_id))
        self.reset_session()

        retrieved_rel = Relationship.select_by_foreign_keys(
            subject_id=subject_id,
            object_id=object_id,
            relationship_type_id=rel_type_id)
        self.assertIsNotNone(retrieved_rel,
                             "Expected to find persisted Relationship")
        self.assertEqual(rel_type_id, retrieved_rel.relationship_type_id)
        self.assertEqual(subject_id, retrieved_rel.subject_id)
        self.assertEqual(object_id, retrieved_rel.object_id)
Example #4
0
 def test_relationship__select_by_foreign_keys__no_match(self):
     """Verify select_by_foreign_keys method returns None if there is no match.
     """
     retrieved_rel = Relationship.select_by_foreign_keys(
         subject_id=uuid.uuid4(),
         object_id=uuid.uuid4(),
         relationship_type_id=uuid.uuid4())
     self.assertIsNone(retrieved_rel,
                       "Expected to not find persisted Relationship")