def test_amend_portal(self):

        harvester = BerlinCKANHarvester()
        default = 'http://datenregister.berlin.de'

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {}}

        valid = harvester.amend_package(dataset)
        portal = dataset['extras']['metadata_original_portal']
        self.assertEqual(portal, default)
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(dataset)
        portal = dataset['extras']['metadata_original_portal']
        self.assertEqual(portal, default)
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': 'www.example.com'}}

        valid = harvester.amend_package(dataset)
        portal = dataset['extras']['metadata_original_portal']
        self.assertEqual(portal, 'www.example.com')
        self.assertTrue(valid)
    def test_type_amendment(self):

        harvester = BerlinCKANHarvester()

        package = {'type': None,
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'datensatz')
        self.assertTrue(valid)

        package = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'datensatz')
        self.assertTrue(valid)

        package = {'type': 'dokument',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'dokument')
        self.assertTrue(valid)

        package = {'type': 'app',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'app')
        self.assertTrue(valid)

        package = {'type': 'garbage',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'datensatz')
        self.assertTrue(valid)
    def test_amend_package(self):

        package = {'license_title': '',
                   'maintainer': '',
                   'maintainer_email': '',
                   'id': 'f998d542-c652-467e-b31b-c3e5d0300589',
                   'metadata_created': '2013-03-11T11:53:20.283753',
                   'relationships': [],
                   'license': None,
                   'metadata_modified': '2013-03-11T11:53:20.283753',
                   'author': '',
                   'author_email': '',
                   'state': 'active',
                   'version': '',
                   'license_id': '',
                   'type': None,
                   'resources': [],
                   'tags': [],
                   'tracking_summary': {'total': 0, 'recent': 0},
                   'groups': ['arbeit', 'geo', 'umwelt', 'wohnen'],
                   'name': 'test-dataset',
                   'isopen': False,
                   'notes_rendered': '',
                   'url': '',
                   'notes': '',
                   'title': 'Test Dataset',
                   'ratings_average': None,
                   'extras': {},
                   'ratings_count': 0,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'revision_id': '411b25f9-1b8f-4f2a-90ae-05d3e8ff8d33'}

        harvester = BerlinCKANHarvester()

        self.assertEqual(package['license_id'], '')
        self.assertEqual(len(package['groups']), 4)
        self.assertTrue('arbeit' in package['groups'])
        self.assertTrue('geo' in package['groups'])
        self.assertTrue('umwelt' in package['groups'])
        self.assertTrue('wohnen' in package['groups'])

        harvester.amend_package(package)

        self.assertEqual(package['license_id'], 'notspecified')
        self.assertEqual(len(package['groups']), 4)
        self.assertTrue('wirtschaft_arbeit' in package['groups'])
        self.assertTrue('geo' in package['groups'])
        self.assertTrue('umwelt_klima' in package['groups'])
        self.assertTrue('infrastruktur_bauen_wohnen' in package['groups'])
    def test_type_amendment(self):

        harvester = BerlinCKANHarvester()

        package = {'type': None,
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'datensatz')
        self.assertTrue(valid)

        package = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'datensatz')
        self.assertTrue(valid)

        package = {'type': 'dokument',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'dokument')
        self.assertTrue(valid)

        package = {'type': 'app',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'app')
        self.assertTrue(valid)

        package = {'type': 'garbage',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(package)
        self.assertEqual(package['type'], 'datensatz')
        self.assertTrue(valid)
    def test_amend_package(self):

        package = {'license_title': '',
                   'maintainer': '',
                   'maintainer_email': '',
                   'id': 'f998d542-c652-467e-b31b-c3e5d0300589',
                   'metadata_created': '2013-03-11T11:53:20.283753',
                   'relationships': [],
                   'license': None,
                   'metadata_modified': '2013-03-11T11:53:20.283753',
                   'author': '',
                   'author_email': '',
                   'state': 'active',
                   'version': '',
                   'license_id': '',
                   'type': None,
                   'resources': [],
                   'tags': [],
                   'tracking_summary': {'total': 0, 'recent': 0},
                   'groups': ['arbeit', 'geo', 'umwelt', 'wohnen'],
                   'name': 'test-dataset',
                   'isopen': False,
                   'notes_rendered': '',
                   'url': '',
                   'notes': '',
                   'title': 'Test Dataset',
                   'ratings_average': None,
                   'extras': {},
                   'ratings_count': 0,
                   'revision_id': '411b25f9-1b8f-4f2a-90ae-05d3e8ff8d33'}

        harvester = BerlinCKANHarvester()

        self.assertEqual(package['license_id'], '')
        self.assertEqual(len(package['groups']), 4)
        self.assertTrue('arbeit' in package['groups'])
        self.assertTrue('geo' in package['groups'])
        self.assertTrue('umwelt' in package['groups'])
        self.assertTrue('wohnen' in package['groups'])

        harvester.amend_package(package)

        self.assertEqual(package['license_id'], 'notspecified')
        self.assertEqual(len(package['groups']), 4)
        self.assertTrue('wirtschaft_arbeit' in package['groups'])
        self.assertTrue('geo' in package['groups'])
        self.assertTrue('umwelt_klima' in package['groups'])
        self.assertTrue('infrastruktur_bauen_wohnen' in package['groups'])
    def test_sector_amendment(self):

        harvester = BerlinCKANHarvester()

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'oeffentlich')
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None,
                              'sector':                   None}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'oeffentlich')
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None,
                              'sector':                   'privat'}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'privat')
        self.assertFalse(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None,
                              'sector':                   'andere'}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'andere')
        self.assertFalse(valid)
    def test_sector_amendment(self):

        harvester = BerlinCKANHarvester()

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'oeffentlich')
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None,
                              'sector':                   None}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'oeffentlich')
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None,
                              'sector':                   'privat'}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'privat')
        self.assertFalse(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'extras': {'metadata_original_portal': None,
                              'sector':                   'andere'}}

        valid = harvester.amend_package(dataset)
        self.assertEqual(dataset['extras']['sector'], 'andere')
        self.assertFalse(valid)
    def test_amend_portal(self):

        harvester = BerlinCKANHarvester()
        default = 'http://datenregister.berlin.de'

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {}}

        valid = harvester.amend_package(dataset)
        portal = dataset['extras']['metadata_original_portal']
        self.assertEqual(portal, default)
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': None}}

        valid = harvester.amend_package(dataset)
        portal = dataset['extras']['metadata_original_portal']
        self.assertEqual(portal, default)
        self.assertTrue(valid)

        dataset = {'type': 'datensatz',
                   'groups': [],
                   'license_id': None,
                   'resources': [{'format':'CSV', 'url': 'http://travis-ci.org'}],
                   'extras': {'metadata_original_portal': 'www.example.com'}}

        valid = harvester.amend_package(dataset)
        portal = dataset['extras']['metadata_original_portal']
        self.assertEqual(portal, 'www.example.com')
        self.assertTrue(valid)