Пример #1
0
 def test_groups_allowed_to_be_its_parent(self):
     groups = model.Group.by_name(u'national-health-service').\
         groups_allowed_to_be_its_parent(type=group_type)
     names = names_from_groups(groups)
     assert_in('department-of-health', names)
     assert_in('cabinet-office', names)
     assert_not_in('natonal-health-service', names)
     assert_not_in('nhs-wirral-ccg', names)
Пример #2
0
 def test_groups_allowed_to_be_its_parent(self):
     groups = model.Group.by_name(u'national-health-service').\
         groups_allowed_to_be_its_parent(type=group_type)
     names = names_from_groups(groups)
     assert_in('department-of-health', names)
     assert_in('cabinet-office', names)
     assert_not_in('natonal-health-service', names)
     assert_not_in('nhs-wirral-ccg', names)
Пример #3
0
    def test_sysadmin_can_save_a_UKLP_harvested_dataset(self):
        """Test sysadmin can save a UKLP dataset.

        The thing to test here is that saving works even when the following
        form-fields may be invalid or missing (as they cannot easily be populated
        when harvesting):

        * theme-primary
        * resource formats
        * temporal_coverage-{from,to}
        """
        client = _PackageFormClient()
        response = client.post_form({}, id=self.uklp_dataset['id'])

        assert_not_in('Errors in form', response.body)
        assert_equal(response.response.status_int, 302)
Пример #4
0
    def test_sysadmin_can_save_a_UKLP_harvested_dataset(self):
        """Test sysadmin can save a UKLP dataset.

        The thing to test here is that saving works even when the following
        form-fields may be invalid or missing (as they cannot easily be populated
        when harvesting):

        * theme-primary
        * resource formats
        * temporal_coverage-{from,to}
        """
        client = _PackageFormClient()
        response = client.post_form({}, id=self.uklp_dataset["id"])

        assert_not_in("Errors in form", response.body)
        assert_equal(response.response.status_int, 302)
Пример #5
0
    def test_21_package_dictization_with_deleted_group(self):
        """
        Ensure that the dictization does not return groups that the dataset has
        been removed from.
        """
        # Create a new dataset and 2 new groups
        model.repo.new_revision()
        pkg = model.Package(name='testing-deleted-groups')
        group_1 = model.Group(name='test-group-1')
        group_2 = model.Group(name='test-group-2')
        model.Session.add(pkg)
        model.Session.add(group_1)
        model.Session.add(group_2)
        model.Session.flush()

        # Add the dataset to group_1, and signal that the dataset used
        # to be a member of group_2 by setting its membership state to 'deleted'
        membership_1 = model.Member(table_id = pkg.id,
                                    table_name = 'package',
                                    group = group_1,
                                    group_id = group_1.id,
                                    state = 'active')

        membership_2 = model.Member(table_id = pkg.id,
                                    table_name = 'package',
                                    group = group_2,
                                    group_id = group_2.id,
                                    state = 'deleted')

        model.Session.add(membership_1)
        model.Session.add(membership_2)
        model.repo.commit()

        # Dictize the dataset
        context = {"model": model,
                   "session": model.Session}

        result = package_dictize(pkg, context)
        self.remove_changable_columns(result)
        assert_not_in('test-group-2', [ g['name'] for g in result['groups'] ])
        assert_in('test-group-1', [ g['name'] for g in result['groups'] ])
Пример #6
0
    def test_21_package_dictization_with_deleted_group(self):
        """
        Ensure that the dictization does not return groups that the dataset has
        been removed from.
        """
        # Create a new dataset and 2 new groups
        model.repo.new_revision()
        pkg = model.Package(name='testing-deleted-groups')
        group_1 = model.Group(name='test-group-1')
        group_2 = model.Group(name='test-group-2')
        model.Session.add(pkg)
        model.Session.add(group_1)
        model.Session.add(group_2)
        model.Session.flush()

        # Add the dataset to group_1, and signal that the dataset used
        # to be a member of group_2 by setting its membership state to 'deleted'
        membership_1 = model.Member(table_id = pkg.id,
                                    table_name = 'package',
                                    group = group_1,
                                    group_id = group_1.id,
                                    state = 'active')

        membership_2 = model.Member(table_id = pkg.id,
                                    table_name = 'package',
                                    group = group_2,
                                    group_id = group_2.id,
                                    state = 'deleted')

        model.Session.add(membership_1)
        model.Session.add(membership_2)
        model.repo.commit()

        # Dictize the dataset
        context = {"model": model,
                   "session": model.Session}

        result = package_dictize(pkg, context)
        self.remove_changable_columns(result)
        assert_not_in('test-group-2', [ g['name'] for g in result['groups'] ])
        assert_in('test-group-1', [ g['name'] for g in result['groups'] ])
Пример #7
0
    def test_a_full_timeseries_dataset(self):
        """
        Tests the submission of a fully-completed timeseries dataset.
        """
        package_data = _EXAMPLE_TIMESERIES_DATA
        package_name = package_data['name']
        CreateTestData.flag_for_deletion(package_name)
        assert not self.get_package_by_name(package_name),\
            'Package "%s" already exists' % package_name

        # create package via form
        response = self._form_client.post_form(package_data)
        
        # ensure it's correct
        pkg = self.get_package_by_name(package_name)
        assert pkg, response.body
        assert_equal(package_data['title'], pkg.title)
        assert_equal(package_data['notes'], pkg.notes)

        publisher = pkg.as_dict()['groups'][0]
        assert_equal(package_data['groups__0__name'], publisher)

        # Extra data
        # Timeseries data
        expected_timeseries_keys = filter(lambda k: k.startswith('timeseries_resources'),
                                          package_data.keys())
        timeseries_resources = ckanext.dgu.lib.helpers.timeseries_resources(pkg.as_dict())
        assert_equal(len(timeseries_resources), 4)
        for key in expected_timeseries_keys:
            index, field = key.split('__')[1:]
            index = int(index)
            assert_equal(package_data[key],
                         timeseries_resources[index][field])

        # Publisher / contact details
        # The contact-email should not be an extra-field on the dataset as it's the
        # same as the publisher group's contact-email.  ie - it hasn't been overridden.
        # The resof the information should be in the extras fields
        assert_not_in('contact-email', pkg.extras)
        assert_equal(package_data['contact-name'], pkg.extras['contact-name'])
        assert_equal(package_data['contact-phone'], pkg.extras['contact-phone'])
        assert_equal(package_data['foi-name'], pkg.extras['foi-name'])
        assert_equal(package_data['foi-email'], pkg.extras['foi-email'])
        assert_equal(package_data['foi-phone'], pkg.extras['foi-phone'])

        # Themes and tags
        assert_equal(package_data['theme-primary'], pkg.extras['theme-primary'])

        assert_equal(set(package_data['theme-secondary']),
                     set(pkg.extras['theme-secondary']))

        # Health and Education are from the primary and secondary themes, which
        # end up in the tags
        assert_equal(set(['tag1', 'tag2', 'a multi word tag', 'Health', 'Education']),
                     set(tag.name for tag in pkg.get_tags()))

        # Additional resources
        expected_additional_keys = filter(lambda k: k.startswith('additional_resources'),
                                          package_data.keys())
        additional_resources = ckanext.dgu.lib.helpers.additional_resources(pkg.as_dict())
        assert_equal(len(additional_resources), 2)
        for key in expected_additional_keys:
            index, field = key.split('__')[1:]
            index = int(index)
            assert_equal(package_data[key],
                         additional_resources[index][field])

        assert_equal(package_data['mandate'], pkg.extras['mandate'])
        assert_equal(package_data['access_constraints'], pkg.license_id)

        assert_equal(package_data['temporal_coverage-from'], DateType.db_to_form(pkg.extras['temporal_coverage-from']))
        assert_equal(package_data['temporal_coverage-to'], DateType.db_to_form(pkg.extras['temporal_coverage-to']))
        assert_in('England', pkg.extras['geographic_coverage'])
Пример #8
0
    def test_a_full_timeseries_dataset(self):
        """
        Tests the submission of a fully-completed timeseries dataset.
        """
        package_data = _EXAMPLE_TIMESERIES_DATA
        package_name = package_data["name"]
        CreateTestData.flag_for_deletion(package_name)
        assert not self.get_package_by_name(package_name), 'Package "%s" already exists' % package_name

        # create package via form
        response = self._form_client.post_form(package_data)

        # ensure it's correct
        pkg = self.get_package_by_name(package_name)
        assert pkg, response.body
        assert_equal(package_data["title"], pkg.title)
        assert_equal(package_data["notes"], pkg.notes)

        publisher = pkg.as_dict()["groups"][0]
        assert_equal(package_data["groups__0__name"], publisher)

        # Extra data
        # Timeseries data
        expected_timeseries_keys = filter(lambda k: k.startswith("timeseries_resources"), package_data.keys())
        timeseries_resources = ckanext.dgu.lib.helpers.timeseries_resources(pkg.as_dict())
        assert_equal(len(timeseries_resources), 4)
        for key in expected_timeseries_keys:
            index, field = key.split("__")[1:]
            index = int(index)
            assert_equal(package_data[key], timeseries_resources[index][field])

        # Publisher / contact details
        # The contact-email should not be an extra-field on the dataset as it's the
        # same as the publisher group's contact-email.  ie - it hasn't been overridden.
        # The resof the information should be in the extras fields
        assert_not_in("contact-email", pkg.extras)
        assert_equal(package_data["contact-name"], pkg.extras["contact-name"])
        assert_equal(package_data["contact-phone"], pkg.extras["contact-phone"])
        assert_equal(package_data["foi-name"], pkg.extras["foi-name"])
        assert_equal(package_data["foi-email"], pkg.extras["foi-email"])
        assert_equal(package_data["foi-phone"], pkg.extras["foi-phone"])

        # Themes and tags
        assert_equal(package_data["theme-primary"], pkg.extras["theme-primary"])

        assert_equal(set(package_data["theme-secondary"]), set(pkg.extras["theme-secondary"]))

        # Health and Education are from the primary and secondary themes, which
        # end up in the tags
        assert_equal(
            set(["tag1", "tag2", "a multi word tag", "Health", "Education"]), set(tag.name for tag in pkg.get_tags())
        )

        # Additional resources
        expected_additional_keys = filter(lambda k: k.startswith("additional_resources"), package_data.keys())
        additional_resources = ckanext.dgu.lib.helpers.additional_resources(pkg.as_dict())
        assert_equal(len(additional_resources), 2)
        for key in expected_additional_keys:
            index, field = key.split("__")[1:]
            index = int(index)
            assert_equal(package_data[key], additional_resources[index][field])

        assert_equal(package_data["mandate"], pkg.extras["mandate"])
        assert_equal(package_data["access_constraints"], pkg.license_id)

        assert_equal(package_data["temporal_coverage-from"], DateType.db_to_form(pkg.extras["temporal_coverage-from"]))
        assert_equal(package_data["temporal_coverage-to"], DateType.db_to_form(pkg.extras["temporal_coverage-to"]))
        assert_in("England", pkg.extras["geographic_coverage"])