Ejemplo n.º 1
0
    def test_definitions_with_different_schema_are_not_equal(self):
        """Verify that ref prop defs with different schemas are not equal."""

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', False)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.2', False)
        self.assertFalse(prop1 == prop2)
Ejemplo n.º 2
0
    def test_bidirectional_and_non_bidirectional_defs_are_not_equal(self):
        """Verify that bi-/non-bidirectional ref prop defs are not equal."""

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', False)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', True)
        self.assertFalse(prop1 == prop2)
Ejemplo n.º 3
0
    def test_definitions_with_different_target_class_are_not_equal(self):
        """Verify that ref prop defs with different classes are not equal."""

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', None, False)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'card', None, False)
        self.assertFalse(prop1 == prop2)
Ejemplo n.º 4
0
    def test_constructor_sets_the_class_name(self):
        """Verify that the constructor sets the target class."""

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       None, False)
        self.assertEqual(prop.klass, 'lane')

        prop = definitions.ReferencePropertyDefinition('name1', False, 'card',
                                                       None, False)
        self.assertEqual(prop.klass, 'card')
Ejemplo n.º 5
0
    def test_constructor_sets_the_bidirectional_hint(self):
        """Verify that the constructor sets the bidirectional hint."""

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       None, False)
        self.assertEqual(prop.bidirectional, False)

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       None, True)
        self.assertEqual(prop.bidirectional, True)
Ejemplo n.º 6
0
    def test_constructor_sets_name(self):
        """Verify that the constructor sets the property name."""

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       None, False)
        self.assertEqual(prop.name, 'name1')

        prop = definitions.ReferencePropertyDefinition('name2', False, 'lane',
                                                       None, False)
        self.assertEqual(prop.name, 'name2')
Ejemplo n.º 7
0
    def test_definitions_with_same_target_attributes_are_equal(self):
        """Verify that ref prop defs with same target attributes are equal."""

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', None, False)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', None, False)
        self.assertEqual(prop1, prop2)

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', False)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', False)
        self.assertEqual(prop1, prop2)

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', False)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', False)
        self.assertEqual(prop1, prop2)

        prop1 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', True)
        prop2 = definitions.ReferencePropertyDefinition(
            'name', False, 'lane', 'schema.1', True)
        self.assertEqual(prop1, prop2)
Ejemplo n.º 8
0
    def test_constructor_sets_the_schema(self):
        """Verify that the constructor sets the target schema."""

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       None, False)
        self.assertEqual(prop.schema, None)

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       'schema1', False)
        self.assertEqual(prop.schema, 'schema1')

        prop = definitions.ReferencePropertyDefinition('name1', False, 'lane',
                                                       'schema2', False)
        self.assertEqual(prop.schema, 'schema2')
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    def _load_reference_property_definition(self, phase, class_name, prop_name,
                                            optional, data):
        target_class = data.get('class', None)
        target_schema = data.get('schema', None)
        bidirectional = data.get('bidirectional', None)

        return definitions.ReferencePropertyDefinition(prop_name, optional,
                                                       target_class,
                                                       target_schema,
                                                       bidirectional)
Ejemplo n.º 11
0
    def test_json_representation_has_all_expected_fields(self):
        """Verify that the JSON representation of reference prop defs is ok."""

        prop = definitions.ReferencePropertyDefinition('cards', False, 'card',
                                                       None, None)
        string = json.dumps(prop, cls=JSONObjectEncoder)
        json_data = json.loads(string)

        self.assertTrue(isinstance(json_data, dict))
        self.assertEqual(json_data['type'], 'reference')
        self.assertFalse('optional' in json_data)
        self.assertEqual(json_data['class'], 'card')
        self.assertFalse('schema' in json_data)
        self.assertFalse('bidirectional' in json_data)

        prop = definitions.ReferencePropertyDefinition('lane', True, 'lane',
                                                       'schema.2', None)
        string = json.dumps(prop, cls=JSONObjectEncoder)
        json_data = json.loads(string)

        self.assertTrue(isinstance(json_data, dict))
        self.assertEqual(json_data['type'], 'reference')
        self.assertTrue(json_data['optional'])
        self.assertEqual(json_data['class'], 'lane')
        self.assertEqual(json_data['schema'], 'schema.2')
        self.assertFalse('bidirectional' in json_data)

        prop = definitions.ReferencePropertyDefinition('lane', True, 'lane',
                                                       'schema.2', 'cards')
        string = json.dumps(prop, cls=JSONObjectEncoder)
        json_data = json.loads(string)

        self.assertTrue(isinstance(json_data, dict))
        self.assertEqual(json_data['type'], 'reference')
        self.assertTrue(json_data['optional'])
        self.assertEqual(json_data['class'], 'lane')
        self.assertEqual(json_data['schema'], 'schema.2')
        self.assertEqual(json_data['bidirectional'], 'cards')
Ejemplo n.º 12
0
    def test_yaml_representation_has_all_expected_fields(self):
        """Verify that the YAML representation of reference prop defs is ok."""

        prop = definitions.ReferencePropertyDefinition('cards', False, 'card',
                                                       None, None)
        string = yaml.dump(prop)
        yaml_data = yaml.load(string)

        self.assertTrue(isinstance(yaml_data, dict))
        self.assertEqual(yaml_data['type'], 'reference')
        self.assertFalse('optional' in yaml_data)
        self.assertEqual(yaml_data['class'], 'card')
        self.assertFalse('schema' in yaml_data)
        self.assertFalse('bidirectional' in yaml_data)

        prop = definitions.ReferencePropertyDefinition('lane', True, 'lane',
                                                       'schema.2', None)
        string = yaml.dump(prop)
        yaml_data = yaml.load(string)

        self.assertTrue(isinstance(yaml_data, dict))
        self.assertEqual(yaml_data['type'], 'reference')
        self.assertTrue(yaml_data['optional'])
        self.assertEqual(yaml_data['class'], 'lane')
        self.assertEqual(yaml_data['schema'], 'schema.2')
        self.assertFalse('bidirectional' in yaml_data)

        prop = definitions.ReferencePropertyDefinition('lane', True, 'lane',
                                                       'schema.2', 'cards')
        string = yaml.dump(prop)
        yaml_data = yaml.load(string)

        self.assertTrue(isinstance(yaml_data, dict))
        self.assertEqual(yaml_data['type'], 'reference')
        self.assertTrue(yaml_data['optional'])
        self.assertEqual(yaml_data['class'], 'lane')
        self.assertEqual(yaml_data['schema'], 'schema.2')
        self.assertEqual(yaml_data['bidirectional'], 'cards')
Ejemplo n.º 13
0
    def test_property_definitions_are_not_equal_if_types_differ(self):
        """Verify that property definitions are not equal if types differe."""

        props = [
            definitions.IntPropertyDefinition('name', False),
            definitions.BooleanPropertyDefinition('name', False),
            definitions.FloatPropertyDefinition('name', False),
            definitions.TimestampPropertyDefinition('name', False),
            definitions.TextPropertyDefinition('name', False, []),
            definitions.RawPropertyDefinition('name', False, []),
            definitions.ReferencePropertyDefinition('name', False, 'class',
                                                    None, False),
            definitions.ListPropertyDefinition(
                'name', False,
                definitions.IntPropertyDefinition('name', False)),
        ]

        for prop1, prop2 in itertools.permutations(props, 2):
            self.assertFalse(prop1 == prop2)
Ejemplo n.º 14
0
    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')