def test_base_classes_have_eq_equal_false(self): for entity_class in get_all_entity_classes_in_module(base_entity): self.assertEqual(entity_class.__eq__, Entity.__eq__, f"Class [{entity_class}] has an __eq__ function " f"unequal to the base Entity class - did you " f"remember to set eq=False in the @attr.s " f"declaration?")
def test_all_classes_have_a_non_optional_state_code(self): for cls in get_all_entity_classes_in_module(entities): self.assertTrue( 'state_code' in attr.fields_dict(cls), f"Expected field |state_code| not defined for class [{cls}].") attribute = attr.fields_dict(cls)['state_code'] self.assertEqual( attribute.type, str, f"Unexpected type [{attribute.type}] for " f"|state_code| field of class [{cls}].")
def test_all_entity_classes_have_expected_primary_id(self): for cls in get_all_entity_classes_in_module(entities): key_name = primary_key_name_from_cls(cls) self.assertTrue(key_name in attr.fields_dict(cls), f"Expected primary key field [{key_name}] not " f"defined for class [{cls}].") attribute = attr.fields_dict(cls)[key_name] self.assertEqual(attribute.type, Optional[int], f"Unexpected type [{attribute.type}] for primary " f"key [{key_name}] of class [{cls}].")
def test_all_classes_have_person_reference(self): classes_without_a_person_ref = [ entities.StatePerson, entities.StateAgent, ] for cls in get_all_entity_classes_in_module(entities): if cls in classes_without_a_person_ref: continue self.assertTrue( 'person' in attr.fields_dict(cls), f"Expected field |person| not defined for class [{cls}].") attribute = attr.fields_dict(cls)['person'] self.assertEqual(attribute.type, Optional[ForwardRef('StatePerson')], f"Unexpected type [{attribute.type}] for |person| " f"field of class [{cls}].")
def test_all_entity_class_names_prefixed_with_state(self): for cls in get_all_entity_classes_in_module(entities): self.assertTrue(cls.__name__.startswith("State"))