Exemple #1
0
    def test_json_representation_has_all_expected_fields(self):
        """Verify that the JSON representation of list prop defs is ok."""

        elements = definitions.IntPropertyDefinition('name', False)
        prop = definitions.ListPropertyDefinition('numbers', False, elements)
        string = json.dumps(prop, cls=JSONObjectEncoder)
        json_data = json.loads(string)

        self.assertTrue(isinstance(json_data, dict))
        self.assertEqual(json_data['type'], 'list')
        self.assertFalse('optional' in json_data)
        self.assertTrue(isinstance(json_data['elements'], dict))
        self.assertEqual(json_data['elements']['type'], 'int')
        self.assertFalse('optional' in json_data['elements'])

        elements = definitions.FloatPropertyDefinition('name', False)
        prop = definitions.ListPropertyDefinition('numbers', True, elements)
        string = json.dumps(prop, cls=JSONObjectEncoder)
        json_data = json.loads(string)

        self.assertTrue(isinstance(json_data, dict))
        self.assertEqual(json_data['type'], 'list')
        self.assertTrue(json_data['optional'])
        self.assertTrue(isinstance(json_data['elements'], dict))
        self.assertEqual(json_data['elements']['type'], 'float')
        self.assertFalse('optional' in json_data['elements'])
Exemple #2
0
    def test_yaml_representation_has_all_expected_fields(self):
        """Verify that the YAML representation of list prop defs is ok."""

        elements = definitions.IntPropertyDefinition('name', False)
        prop = definitions.ListPropertyDefinition('numbers', False, elements)
        string = yaml.dump(prop)
        yaml_data = yaml.load(string)

        self.assertTrue(isinstance(yaml_data, dict))
        self.assertEqual(yaml_data['type'], 'list')
        self.assertFalse('optional' in yaml_data)
        self.assertTrue(isinstance(yaml_data['elements'], dict))
        self.assertEqual(yaml_data['elements']['type'], 'int')
        self.assertFalse('optional' in yaml_data['elements'])

        elements = definitions.FloatPropertyDefinition('name', False)
        prop = definitions.ListPropertyDefinition('numbers', True, elements)
        string = yaml.dump(prop)
        yaml_data = yaml.load(string)

        self.assertTrue(isinstance(yaml_data, dict))
        self.assertEqual(yaml_data['type'], 'list')
        self.assertTrue(yaml_data['optional'])
        self.assertTrue(isinstance(yaml_data['elements'], dict))
        self.assertEqual(yaml_data['elements']['type'], 'float')
        self.assertFalse('optional' in yaml_data['elements'])
Exemple #3
0
    def test_definitions_with_different_elements_are_not_equal(self):
        """Verify that list prop defs with different elements are not equal."""

        prop1 = definitions.ListPropertyDefinition(
            'name', False, definitions.FloatPropertyDefinition('name', False))
        prop2 = definitions.ListPropertyDefinition(
            'name', False, definitions.IntPropertyDefinition('name', False))
        self.assertFalse(prop1 == prop2)
Exemple #4
0
    def test_constructor_sets_optional_hint(self):
        """Verify that the constructor sets the optional hint."""

        prop = definitions.ListPropertyDefinition('name1', False, None)
        self.assertEqual(prop.optional, False)

        prop = definitions.ListPropertyDefinition('name1', True, None)
        self.assertEqual(prop.optional, True)
Exemple #5
0
    def test_definitions_with_same_elements_are_equal(self):
        """Verify that list prop defs with the same element type are equal."""

        prop1 = definitions.ListPropertyDefinition(
            'name', False, definitions.IntPropertyDefinition('name', False))
        prop2 = definitions.ListPropertyDefinition(
            'name', False, definitions.IntPropertyDefinition('name', False))
        self.assertEqual(prop1, prop2)
Exemple #6
0
    def test_constructor_sets_name(self):
        """Verify that the constructor sets the property name."""

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

        prop = definitions.ListPropertyDefinition('name2', False, None)
        self.assertEqual(prop.name, 'name2')
Exemple #7
0
    def test_constructor_sets_element_definition(self):
        """Verify that the constructor sets the element definition."""

        prop = definitions.ListPropertyDefinition('name1', False, None)
        self.assertEqual(prop.elements, None)

        elements = definitions.IntPropertyDefinition('name1', False)
        prop = definitions.ListPropertyDefinition('name1', False, elements)
        self.assertEqual(prop.elements, elements)

        elements = definitions.FloatPropertyDefinition('name1', False)
        prop = definitions.ListPropertyDefinition('name1', False, elements)
        self.assertEqual(prop.elements, elements)
Exemple #8
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)
Exemple #9
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)
Exemple #10
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')
 def _load_list_property_definition(self, phase, class_name, prop_name,
                                    optional, data):
     elements = self._load_property_definition(phase, class_name, prop_name,
                                               data['elements'])
     return definitions.ListPropertyDefinition(prop_name, optional,
                                               elements)