def test_constructor_sets_classes(self): """Verify that the constructor initialises the classes mapping.""" classes = [ definitions.ClassDefinition('card', []), definitions.ClassDefinition('lane', [ definitions.TextPropertyDefinition('title', False, []), definitions.ListPropertyDefinition( 'cards', False, definitions.ReferencePropertyDefinition( 'cards', False, 'card', None, False) )] ), ] sch = schemas.Schema('org.a.schemas.1', classes) self.assertEqual(len(sch.classes), len(classes)) for klass in classes: self.assertTrue(klass.name in sch.classes) self.assertEqual(sch.classes[klass.name], klass) classes = [ definitions.ClassDefinition('requirement', [ definitions.TextPropertyDefinition('title', False, []), definitions.IntPropertyDefinition('priority', True) ]), ] sch = schemas.Schema('org.another.schemas.2', classes) self.assertEqual(len(sch.classes), len(classes)) for klass in classes: self.assertTrue(klass.name in sch.classes) self.assertEqual(sch.classes[klass.name], klass)
def test_constructor_sets_name(self): """Verify that the constructor sets the class name.""" klass = definitions.ClassDefinition('name1', []) self.assertEqual(klass.name, 'name1') klass = definitions.ClassDefinition('name2', []) self.assertEqual(klass.name, 'name2')
def test_classes_with_different_properties_are_not_equal(self): """Verify that classes with different properties are not equal.""" klass1 = definitions.ClassDefinition('name', [ definitions.IntPropertyDefinition('prop1', False), ]) klass2 = definitions.ClassDefinition('name', [ definitions.BooleanPropertyDefinition('prop1', False), ]) self.assertFalse(klass1 == klass2)
def test_schemas_with_different_classes_are_not_equal(self): """Verify that schemas with different classes are not equal.""" schema1 = schemas.Schema('schema.1', [ definitions.ClassDefinition('card', []), definitions.ClassDefinition('lane', []) ]) schema2 = schemas.Schema('schema.2', [ definitions.ClassDefinition('card', []) ]) self.assertFalse(schema1 == schema2)
def test_classes_with_same_name_and_properties_are_equal(self): """Verify that classes with the same name and properties are equal.""" klass1 = definitions.ClassDefinition('name', [ definitions.IntPropertyDefinition('prop1', False), definitions.BooleanPropertyDefinition('prop2', False) ]) klass2 = definitions.ClassDefinition('name', [ definitions.IntPropertyDefinition('prop1', False), definitions.BooleanPropertyDefinition('prop2', False) ]) self.assertEqual(klass1, klass2)
def test_constructor_sets_property_definitions(self): """Verify that the constructor sets the property definitions.""" klass = definitions.ClassDefinition('name1', []) self.assertEqual(klass.properties, {}) properties = [ definitions.IntPropertyDefinition('prop1', False), definitions.BooleanPropertyDefinition('prop2', False) ] klass = definitions.ClassDefinition('name1', properties) self.assertEqual(len(klass.properties), len(properties)) for prop in properties: self.assertTrue(prop.name in klass.properties) self.assertEqual(klass.properties[prop.name], prop)
def test_json_representation_has_all_expected_fields(self): """Verify that the JSON representation of schemas is ok.""" klasses = [ definitions.ClassDefinition('card', [ definitions.TextPropertyDefinition('title', False, []), definitions.IntPropertyDefinition('number', True), ]), definitions.ClassDefinition('lane', [ definitions.ListPropertyDefinition( 'cards', True, definitions.ReferencePropertyDefinition( 'cards', False, 'card', None, None)) ]), ] schema = schemas.Schema('schema.1', klasses) string = json.dumps(schema, cls=JSONObjectEncoder) json_data = json.loads(string) self.assertTrue(isinstance(json_data, dict)) self.assertEqual(json_data['name'], 'schema.1') self.assertEqual(len(json_data['classes']), 2) self.assertTrue('card' in json_data['classes']) self.assertTrue('lane' in json_data['classes']) card_data = json_data['classes']['card'] self.assertEqual(len(card_data['properties']), 2) self.assertTrue('title' in card_data['properties']) self.assertTrue('number' in card_data['properties']) self.assertEqual(card_data['properties']['title']['type'], 'text') self.assertFalse('optional' in card_data['properties']['title']) self.assertEqual(card_data['properties']['number']['type'], 'int') self.assertTrue(card_data['properties']['number']['optional']) lane_data = json_data['classes']['lane'] self.assertEqual(len(lane_data['properties']), 1) self.assertTrue('cards' in lane_data['properties']) self.assertEqual(lane_data['properties']['cards']['type'], 'list') self.assertTrue(lane_data['properties']['cards']['optional']) self.assertEqual(lane_data['properties']['cards']['elements']['type'], 'reference') self.assertEqual(lane_data['properties']['cards']['elements']['class'], 'card')
def test_schemas_with_the_same_name_and_classes_are_equal(self): """Verify that schemas with the same name and classes are equal.""" classes = [ definitions.ClassDefinition('requirement', [ definitions.TextPropertyDefinition('title', False, []), definitions.IntPropertyDefinition('priority', True) ]), ] schema1 = schemas.Schema('schema.1', classes) schema2 = schemas.Schema('schema.1', classes) self.assertEqual(schema1, schema2)
def test_json_representation_has_all_expected_fields(self): """Verify that the JSON representation of class definitions is ok.""" props = [ definitions.TextPropertyDefinition('title', False, []), definitions.IntPropertyDefinition('number', True), ] klass = definitions.ClassDefinition('card', props) string = json.dumps(klass, cls=JSONObjectEncoder) json_data = json.loads(string) self.assertTrue(isinstance(json_data, dict)) self.assertEqual(json_data['name'], 'card') self.assertEqual(len(json_data['properties']), 2) self.assertTrue('title' in json_data['properties']) self.assertTrue('number' in json_data['properties']) self.assertEqual(json_data['properties']['title']['type'], 'text') self.assertFalse('optional' in json_data['properties']['title']) self.assertEqual(json_data['properties']['number']['type'], 'int') self.assertTrue(json_data['properties']['number']['optional'])
def test_yaml_representation_has_all_expected_fields(self): """Verify that the YAML representation of class definitions is ok.""" props = [ definitions.TextPropertyDefinition('title', False, []), definitions.IntPropertyDefinition('number', True), ] klass = definitions.ClassDefinition('card', props) string = yaml.dump(klass) yaml_data = yaml.load(string) self.assertTrue(isinstance(yaml_data, dict)) self.assertEqual(yaml_data['name'], 'card') self.assertEqual(len(yaml_data['properties']), 2) self.assertTrue('title' in yaml_data['properties']) self.assertTrue('number' in yaml_data['properties']) self.assertEqual(yaml_data['properties']['title']['type'], 'text') self.assertFalse('optional' in yaml_data['properties']['title']) self.assertEqual(yaml_data['properties']['number']['type'], 'int') self.assertTrue(yaml_data['properties']['number']['optional'])
def _load_class_definition(self, phase, class_name, class_data): props = self._load_property_definitions(phase, class_name, class_data) return definitions.ClassDefinition(class_name, props)
def test_classes_and_non_classes_are_not_equal(self): """Verify that class definitions and non-classes are not equal.""" self.assertFalse(definitions.ClassDefinition('name', []) == 'name')