Exemple #1
0
    def test_json_representation_is_correct(self):
        """Verify that the JSON repr of reference properties is correct."""

        prop = properties.ReferenceProperty(
            'name',
            references.Reference('5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0', None,
                                 None))
        string = json.dumps(prop, cls=JSONObjectEncoder)
        data = json.loads(string)
        self.assertTrue(isinstance(data, dict))
        self.assertEqual(data['uuid'], '5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0')
        self.assertTrue('service' not in data)
        self.assertTrue('ref' not in data)

        prop = properties.ReferenceProperty(
            'name',
            references.Reference('5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0',
                                 'issues', None))
        string = json.dumps(prop, cls=JSONObjectEncoder)
        data = json.loads(string)
        self.assertTrue(isinstance(data, dict))
        self.assertEqual(data['uuid'], '5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0')
        self.assertEqual(data['service'], 'issues')
        self.assertTrue('ref' not in data)

        prop = properties.ReferenceProperty(
            'name',
            references.Reference('5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0',
                                 'issues', 'master'))
        string = json.dumps(prop, cls=JSONObjectEncoder)
        data = json.loads(string)
        self.assertTrue(isinstance(data, dict))
        self.assertEqual(data['uuid'], '5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0')
        self.assertEqual(data['service'], 'issues')
        self.assertEqual(data['ref'], 'master')
Exemple #2
0
    def test_yaml_representation_has_all_expected_fields(self):
        """Verify that the YAML representation of reference props is ok."""

        prop = properties.ReferenceProperty(
            'name',
            references.Reference('5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0', None,
                                 None))
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, dict))
        self.assertEqual(data['uuid'], '5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0')
        self.assertTrue('service' not in data)
        self.assertTrue('ref' not in data)

        prop = properties.ReferenceProperty(
            'name',
            references.Reference('5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0',
                                 'issues', None))
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, dict))
        self.assertEqual(data['uuid'], '5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0')
        self.assertEqual(data['service'], 'issues')
        self.assertTrue('ref' not in data)

        prop = properties.ReferenceProperty(
            'name',
            references.Reference('5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0',
                                 'issues', 'master'))
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, dict))
        self.assertEqual(data['uuid'], '5f2c9a1d-1113-49f1-9d1d-29aaa4a520b0')
        self.assertEqual(data['service'], 'issues')
        self.assertEqual(data['ref'], 'master')
Exemple #3
0
    def test_constructor_sets_action_id_uuid_action_id_and_properties(self):
        """Verify that the constructor sets the id, uuid, action id, props."""

        action = actions.UpdateAction(
            'foo', '37982fe0-467f-4f02-b6a0-f010ceb8ad63', None, [
                properties.TextProperty('title', 'New title'),
                properties.ReferenceProperty(
                    'lane', {'uuid': 'cfdaa6e9-eb13-49a3-b43c-51b40a005d39'}),
                ])
        self.assertEqual(action.id, 'foo')
        self.assertEqual(action.uuid, '37982fe0-467f-4f02-b6a0-f010ceb8ad63')
        self.assertEqual(action.action_id, None)
        self.assertEqual(action.properties, {
            'title': properties.TextProperty('title', 'New title'),
            'lane': properties.ReferenceProperty(
                'lane', {'uuid': 'cfdaa6e9-eb13-49a3-b43c-51b40a005d39'}),
            })

        action = actions.UpdateAction(
            'bar',
            None, '5',
            [
                properties.TextProperty('title', 'A new title'),
                properties.ListProperty(
                    'cards', [
                        properties.ReferenceProperty(
                            'cards',
                            {'uuid': '3d745cc5-cff4-4676-aa78-ff48b9da0ed0'})
                        ])
                ])
        self.assertEqual(action.id, 'bar')
        self.assertEqual(action.uuid, None)
        self.assertEqual(action.action_id, '5')
        self.assertEqual(action.properties, {
            'title': properties.TextProperty('title', 'A new title'),
            'cards': properties.ListProperty(
                'cards', [
                    properties.ReferenceProperty(
                        'cards',
                        {'uuid': '3d745cc5-cff4-4676-aa78-ff48b9da0ed0'}),
                    ])
            })
Exemple #4
0
    def test_constructor_sets_action_id_class_and_properties(self):
        """Verify that the constructor sets the action id, class and props."""

        action = actions.CreateAction('foo', 'card', [
            properties.TextProperty('title', 'New title'),
            properties.ReferenceProperty(
                'lane', {'uuid': 'cfdaa6e9-eb13-49a3-b43c-51b40a005d39'}),
            ])
        self.assertEqual(action.id, 'foo')
        self.assertEqual(action.klass, 'card')
        self.assertEqual(action.properties, {
            'title': properties.TextProperty('title', 'New title'),
            'lane': properties.ReferenceProperty(
                'lane', {'uuid': 'cfdaa6e9-eb13-49a3-b43c-51b40a005d39'}),
            })

        action = actions.CreateAction('bar', 'lane', [
            properties.TextProperty('title', 'A new title'),
            properties.ListProperty(
                'cards', [
                    properties.ReferenceProperty(
                        'cards',
                        {'uuid': '3d745cc5-cff4-4676-aa78-ff48b9da0ed0'}),
                    ])
            ])
        self.assertEqual(action.id, 'bar')
        self.assertEqual(action.klass, 'lane')
        self.assertEqual(action.properties, {
            'title': properties.TextProperty('title', 'A new title'),
            'cards': properties.ListProperty(
                'cards', [
                    properties.ReferenceProperty(
                        'cards',
                        {'uuid': '3d745cc5-cff4-4676-aa78-ff48b9da0ed0'}),
                    ]),
            })
Exemple #5
0
    def test_constructor_sets_property_name_and_value_properly(self):
        """Verify that the constructor sets name and value properly."""

        test_references = [
            references.Reference('229dd334-321c-4c95-95a6-aff5533db1d6', None,
                                 None),
            references.Reference('12c814bc-f3e6-4ee3-9f25-4b69a4d6fb95',
                                 'issues', None),
            references.Reference('4d47faf2-fc79-432f-ad7b-94047c303a22', None,
                                 'master'),
            references.Reference('61427efc-e0cd-4f2a-b44e-d603ea506ab3',
                                 'issues', 'master')
        ]

        for object_reference in test_references:
            name = 'property name'
            reference_property = properties.ReferenceProperty(
                name, object_reference)
            self.assertEqual(reference_property.name, name)
            self.assertEqual(reference_property.value, object_reference)
    def list_property_in_data(self, context, object_entry, prop_def, data):
        """Return a list property from an object properties dictionary."""

        if not isinstance(data, list):
            context.error(
                ListPropertyValueNotAListError(context, prop_def.name, data))

        context.in_list_property = True
        try:
            element_type = prop_def.elements.property_type
            element_func = '%s_property_in_data' % element_type
            values = []
            for raw_value in data:
                value = getattr(self,
                                element_func)(context, object_entry,
                                              prop_def.elements, raw_value)
                values.append(value)
        finally:
            context.in_list_property = False

        return properties.ReferenceProperty(prop_def.name, values)
    def reference_property_in_data(self, context, object_entry, prop_def,
                                   data):
        """Return a reference property from an object properties dictionary."""

        if not isinstance(data, dict):
            context.error(
                ReferencePropertyValueNotADictError(context, prop_def.name,
                                                    data))

            return None
        else:
            if 'uuid' not in data:
                context.error(
                    ReferencePropertyUUIDUndefinedError(
                        context, prop_def.name, data))
            elif not isinstance(data['uuid'], basestring):
                context.error(
                    ReferencePropertyUUIDNotAStringError(
                        context, prop_def.name, data['uuid']))
            elif not expressions.object_uuid.match(data['uuid']):
                context.error(
                    ReferencePropertyUUIDInvalidError(context, prop_def.name,
                                                      data['uuid']))

            if 'ref' in data and not isinstance(data['ref'], basestring):
                context.error(
                    ReferencePropertyRefNotAStringError(
                        context, prop_def.name, data['ref']))

            if 'service' in data:
                if not isinstance(data['service'], basestring):
                    context.error(
                        ReferencePropertyServiceNotAStringError(
                            context, prop_def.name, data['service']))

            reference = references.Reference(data.get('uuid', None),
                                             data.get('ref', None),
                                             data.get('service', None))

            return properties.ReferenceProperty(prop_def.name, reference)
Exemple #8
0
    def setUp(self):
        """Initialise helper variables for the tests."""

        self.test_input = [
            ('hash1', '5e27f17c-ff22-4c49-82d9-6549f2800d1a',
             objects.ObjectClass('someclass', []), []),
            ('hash2', 'ad791799-4c3a-4cac-a07d-43493baab121',
             objects.ObjectClass('someclass', []), [
                 properties.TextProperty('title', 'Title'),
                 properties.TextProperty('info', 'Info'),
                 properties.FloatProperty('amount', 237.5),
                 properties.BooleanProperty('important', False),
                 properties.IntProperty('count', 5),
                 properties.TimestampProperty('date', '1377703755 +0100'),
                 properties.ReferenceProperty(
                     'others',
                     set([
                         references.Reference('a', None, None),
                         references.Reference('b', None, None),
                         references.Reference('c', None, None),
                     ])),
                 properties.ListProperty('tags', ['tag-1', 'tag-2', 'tag-3']),
             ]),
        ]