def test_add_relationship(self): """Tests adding relationships.""" table = Table(table_name="table1", primary_key="pk1") table.add_relationship( GenericRelationship( from_table="table1", to_table="table2", conditions="table1.col1 = table2.col2", name="rel1", ) ) table.add_relationship( to_table="table3", conditions="table1.col1 = table3.col3", name="rel2", ) rel = table.get_relationship("rel1") self.assertEqual("rel1", rel.name) rel = table.relationships["rel2"] self.assertEqual("rel2", rel.name) self.assertEqual("table1", rel.from_table) self.assertEqual("table3", rel.to_table) self.assertEqual("table1.col1 = table3.col3", rel.conditions) rel = table.get_relationship("foo") self.assertIsNone(rel)
def test_set_conditions(self): """Tests setting conditions in the model.""" the_condition = "tableA.colA > tableB.colB" gr = GenericRelationship( from_table="tableA", to_table="tableB", conditions=the_condition ) self.assertEqual(gr.conditions, the_condition)
def test_create_rel_with_name(self): """Tests creation with a specific name.""" gr = GenericRelationship( from_table="tableA", to_table="tableB", name="REL_test", conditions="col1 = col2", ) self.assertEqual("REL_test", gr.name)
def test_create_rel_default_name(self): """Tests creation with a default name.""" gr = GenericRelationship( from_table="tableA", to_table="tableB", conditions="col1 = col2" ) self.assertEqual(gr.name, "REL_tableA_to_tableB")