예제 #1
0
    def test_returns_modified_extras(self):
        extras = Extras([
            {
                'key': 'terms_of_use',
                'value': [{
                    'license_id': 'some-id',
                    'license_url': 'some-url',
                }]
            },
        ])

        expected_value = [{
            'license_id': 'license-id',
            'license_url': 'license-url',
            'license_type': 'license-mit',
        }]

        extras.update(
            'terms_of_use',
            expected_value,
        )

        expected_extras = [
            {
                'key':
                'terms_of_use',
                'value': [{
                    'license_id': 'license-id',
                    'license_url': 'license-url',
                    'license_type': 'license-mit',
                }]
            },
        ]

        self.assertEquals(expected_extras, extras.get())
예제 #2
0
 def test_update_on_dict_list_works_as_expected(self):
     extras = Extras([
         {
             'key': 'hash',
             'value': 'tag'
         },
         {
             'key': 'label',
             'value': 'dot'
         },
     ])
     self.assertTrue(extras.update('label', 'doubledot'))
     self.assertEquals('doubledot', extras.value('label'))
예제 #3
0
    def upsert_on_empty_dict_list_works_as_expected(self):
        extras = Extras()

        expected_extras = [{
            'key': 'three',
            'value': 3,
        }]

        self.assertTrue(extras.update('three', 3, True))
        self.assertEquals(3, extras.value('three'))
        self.assertEquals(1, extras.len())

        self.assertEquals(expected_extras, extras.get())
예제 #4
0
    def returns_modified_sector(self):
        extras = Extras([
            {
                'key': 'metadata_original_portal',
                'value': None
            },
            {
                'key': 'sector',
                'value': None
            },
        ])

        self.assertTrue(extras.update('sector', 'privat'))
        self.assertEquals('privat', extras.value('sector'))
예제 #5
0
    def test_alternates_structure_as_expected(self):
        extras = Extras([
            {
                'key': 'terms_of_use',
                'value': [{
                    'licence_id': 'some-id',
                    'licence_url': 'some-url',
                }]
            },
        ])

        expected_value = [{
            'license_id': 'some-id',
            'license_url': 'some-url',
        }]

        extras.update(
            'terms_of_use',
            expected_value,
        )

        self.assertEquals(expected_value, extras.value('terms_of_use'))
        self.assertEquals(1, len(extras.value('terms_of_use')))
예제 #6
0
 def upsert_on_dict_list_works_as_expected(self):
     extras = Extras([
         {
             'key': 'one',
             'value': 1
         },
         {
             'key': 'two',
             'value': 2
         },
     ])
     self.assertTrue(extras.update('three', 3, True))
     self.assertEquals(3, extras.value('three'))
     self.assertEquals(3, extras.len())
예제 #7
0
    def test_original_groups_are_updated_as_expected(self):
        extras_in = [{
            "key":
            "contacts",
            "value":
            "[{'url': 'www.open.nrw.de', 'role': 'vertrieb', 'name': 'Gesch\\u00e4ftsstelle Open.NRW', 'email': '*****@*****.**'}]"
        }, {
            "key":
            "dates",
            "value":
            "[{'date': '2016-06-08T12:31:11+02:00', 'role': 'erstellt'}, {'date': '2014-05-26T12:39:03+02:00', 'role': 'veroeffentlicht'}, {'date': '2016-06-08T12:31:11+02:00', 'role': 'aktualisiert'}]"
        }, {
            "key":
            "images",
            "value":
            "['https://open.nrw/profiles/nrw_ressort/themes/custom/nrw_base/images/grayish-blue/files/koeln_klein.png']"
        }, {
            "key": "metadata_original_portal",
            "value": "http://open.nrw/"
        }, {
            "key": "metadata_transformer",
            "value": "boo"
        }, {
            "key": "non_open",
            "value": "false"
        }, {
            "key": "opennrw_spatial",
            "value": "Stadt Köln"
        }, {
            "key": "original_groups",
            "value": "['Politik und Wahlen']"
        }, {
            "key":
            "spatial",
            "value":
            "{'type': 'polygon', 'coordinates': [[[6.7838099999999999, 50.825465999999999], [7.1533170000000004, 50.825465999999999], [7.1533170000000004, 51.090167999999998], [6.7838099999999999, 51.090167999999998], [6.7838099999999999, 50.825465999999999]]]}"
        }]

        extras = Extras(extras_in)

        self.assertTrue(
            extras.update('original_groups', ['group one', 'group two']))
        self.assertEquals(2, len(extras.value('original_groups')))
예제 #8
0
 def upsert_on_flat_list_works_as_expected(self):
     extras = Extras({'dates': 'foo', 'bar': 'baz', 'some': 'thing'})
     self.assertTrue(extras.update('new', 'kid', True))
     self.assertEquals('kid', extras.value('new'))
     self.assertEquals(4, extras.len())
예제 #9
0
 def test_update_on_flat_list_works_as_expected(self):
     extras = Extras({'dates': 'foo', 'bar': 'baz', 'some': 'thing'})
     self.assertTrue(extras.update('some', 'one'))
     self.assertEquals('one', extras.value('some'))
예제 #10
0
 def test_raises_error_when_key_not_found_for_update(self):
     extras = Extras({'dates': 'foo', 'bar': 'baz'})
     extras.update('raiser', 'foo')