Exemplo n.º 1
0
    def test_json_representation_has_all_expected_fields(self):
        """Verify that the JSON representation of list properties is ok."""

        prop = properties.ListProperty('name', [])
        string = json.dumps(prop, cls=JSONObjectEncoder)
        data = json.loads(string)
        self.assertTrue(isinstance(data, list))
        self.assertEqual(len(data), 0)

        prop = properties.ListProperty('name', [
            properties.IntProperty('name', 5),
            properties.IntProperty('name', -17),
        ])
        string = json.dumps(prop, cls=JSONObjectEncoder)
        data = json.loads(string)
        self.assertTrue(isinstance(data, list))
        self.assertEqual(len(data), 2)
        self.assertEqual(data[0], 5)
        self.assertEqual(data[1], -17)

        prop = properties.ListProperty('name', [
            properties.TextProperty('name', 'foo'),
            properties.TextProperty('name', 'bar'),
            properties.TextProperty('name', 'baz'),
        ])
        string = json.dumps(prop, cls=JSONObjectEncoder)
        data = json.loads(string)
        self.assertTrue(isinstance(data, list))
        self.assertEqual(len(data), 3)
        self.assertEqual(data[0], 'foo')
        self.assertEqual(data[1], 'bar')
        self.assertEqual(data[2], 'baz')
Exemplo n.º 2
0
    def test_yaml_representation_has_all_expected_fields(self):
        """Verify that the YAML representation of list properties is ok."""

        prop = properties.ListProperty('name', [])
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, list))
        self.assertEqual(len(data), 0)

        prop = properties.ListProperty('name', [
            properties.IntProperty('name', 5),
            properties.IntProperty('name', -17),
        ])
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, list))
        self.assertEqual(len(data), 2)
        self.assertEqual(data[0], 5)
        self.assertEqual(data[1], -17)

        prop = properties.ListProperty('name', [
            properties.TextProperty('name', 'foo'),
            properties.TextProperty('name', 'bar'),
            properties.TextProperty('name', 'baz'),
        ])
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, list))
        self.assertEqual(len(data), 3)
        self.assertEqual(data[0], 'foo')
        self.assertEqual(data[1], 'bar')
        self.assertEqual(data[2], 'baz')
Exemplo n.º 3
0
    def test_input_value_is_converted_to_a_list(self):
        """Verify that the input value is converted to a list."""

        test_input = [
            ([1, 2, 3], [1, 2, 3]),
            ((1, 2, 3), [1, 2, 3]),
            ({
                1: 'a',
                2: 'b',
                3: 'c'
            }, [(1, 'a'), (2, 'b'), (3, 'c')]),
            ('abcdefgh', ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']),
            (1, [1]),
            (2.0, [2.0]),
            (references.Reference('4d47faf2-fc79-432f-ad7b-94047c303a22',
                                  'issues', 'master'),
             [
                 references.Reference('4d47faf2-fc79-432f-ad7b-94047c303a22',
                                      'issues', 'master')
             ]),
        ]

        for value, list_value in test_input:
            list_property = properties.ListProperty('property name', value)
            self.assertTrue(isinstance(list_property.value, list))
            self.assertEquals(type(list_property.value), type([]))
            self.assertEquals(list_property.value, list_value)
Exemplo n.º 4
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'}),
                    ])
            })
Exemplo n.º 5
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'}),
                    ]),
            })
Exemplo n.º 6
0
    def test_constructor_sets_property_name_and_value_properly(self):
        """Verify that the constructor sets name and value properly."""

        test_input = [
            ('property1', []),
            ('property2', [1]),
            ('property3', [1.0, 2.1]),
            ('property4', [1, 'foo']),
            ('property5', ['foo', 'bar', 'baz']),
            ('property6', [
                references.Reference('4d47faf2-fc79-432f-ad7b-94047c303a22',
                                     None, 'master'),
                references.Reference('61427efc-e0cd-4f2a-b44e-d603ea506ab3',
                                     'issues', 'master'),
            ]),
        ]

        for name, values in test_input:
            list_property = properties.ListProperty(name, values)
            self.assertEqual(list_property.name, name)
            self.assertEqual(list_property.value, values)
Exemplo n.º 7
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']),
             ]),
        ]