def test_amend_package(self):
        harvester = DatahubCKANHarvester()
        portal = 'http://datahub.io/'
        package = {
            'id': 'package-id',
            'name': 'package-name',
            'description': '   ',
            'groups': [
                {'name': 'bibliographic'},
                {'name': 'lld'},
                {'name': 'bibsoup'},
            ],
            'resources': [],
            'extras': []
        }

        valid = harvester.amend_package(package)

        extras = Extras(package['extras'])

        self.assertEqual(package['id'], 'package-id')
        self.assertEqual(package['name'], 'package-name')
        self.assertTrue(extras.key('metadata_original_portal'))
        self.assertEquals(portal, extras.value('metadata_original_portal'))
        self.assertTrue(valid)
        self.assertListEqual(package['groups'],
            [{'id': 'bibliographic', 'name': 'bibliographic'},
             {'id': 'lld', 'name': 'lld'},
             {'id': 'bibsoup', 'name': 'bibsoup'},
             {'id': 'bildung_wissenschaft', 'name': 'bildung_wissenschaft'}]
        )
        self.assertEqual(package['type'], 'datensatz')
        self.assertEqual(extras.value('guid'), 'package-id')
    def test_amend_package(self):

        harvester = DatahubCKANHarvester()
        package = {'name': 'Package Name',
                   'description': '   ',
                   'groups': ['bibliographic', 'lld', 'bibsoup'],
                   'resources': [],
                   'extras': {}}

        harvester.amend_package(package)
        portal = package['extras']['metadata_original_portal']
        self.assertEqual(portal, 'http://datahub.io/')
        self.assertEqual(package['groups'], ['bibliographic', 'lld', 'bibsoup', 'bildung_wissenschaft'])
        self.assertEqual(package['type'], 'datensatz')
    def test_amend_package(self):

        harvester = DatahubCKANHarvester()
        package = {
            'name': 'Package Name',
            'description': '   ',
            'groups': ['bibliographic', 'lld', 'bibsoup'],
            'resources': [],
            'extras': {}
        }

        harvester.amend_package(package)
        portal = package['extras']['metadata_original_portal']
        self.assertEqual(portal, 'http://datahub.io/')
        self.assertEqual(package['groups'], ['bildung_wissenschaft'])
        self.assertEqual(package['type'], 'datensatz')
    def test_package_valid(self):

        harvester = DatahubCKANHarvester()

        valid_package1 = 'hbz_unioncatalog'
        valid_package2 = 'lobid-resources'
        valid_package3 = 'deutsche-nationalbibliografie-dnb'
        valid_package4 = 'dnb-gemeinsame-normdatei'

        invalid_package1 = 'hbz_unioncatalog2'
        invalid_package2 = '_hbz_unioncatalog'
        invalid_package3 = 'xxx'

        self.assertTrue(harvester.package_valid(valid_package1))
        self.assertTrue(harvester.package_valid(valid_package2))
        self.assertTrue(harvester.package_valid(valid_package3))
        self.assertTrue(harvester.package_valid(valid_package4))

        self.assertFalse(harvester.package_valid(invalid_package1))
        self.assertFalse(harvester.package_valid(invalid_package2))
        self.assertFalse(harvester.package_valid(invalid_package3))
    def test_package_valid(self):

        harvester = DatahubCKANHarvester()

        valid_package1 = 'hbz_unioncatalog'
        valid_package2 = 'lobid-resources'
        valid_package3 = 'deutsche-nationalbibliografie-dnb'
        valid_package4 = 'dnb-gemeinsame-normdatei'

        invalid_package1 = 'hbz_unioncatalog2'
        invalid_package2 = '_hbz_unioncatalog'
        invalid_package3 = 'xxx'

        self.assertTrue(harvester.package_valid(valid_package1))
        self.assertTrue(harvester.package_valid(valid_package2))
        self.assertTrue(harvester.package_valid(valid_package3))
        self.assertTrue(harvester.package_valid(valid_package4))

        self.assertFalse(harvester.package_valid(invalid_package1))
        self.assertFalse(harvester.package_valid(invalid_package2))
        self.assertFalse(harvester.package_valid(invalid_package3))