def test_timeseries_resource_url_non_empty(self): """Asserts that timeseries resources must have url defined""" data = {'timeseries_resources__0__description': 'description with no url', 'timeseries_resources__0__date': 'date with no url', 'timeseries_resources__0__format': 'format with no url'} response = self._form_client.post_form(data) assert_in('URL:</b> Missing value', response.body, response.body)
def test_cannot_create_a_non_ogl_dataset_without_specifying_license_name(self): """ Asserts that the user specify a license name if the license is non-OGL """ data = {'license_id': ""} response = self._form_client.post_form(data) assert_in('Licence:</b> Please enter the access constraints.', response.body)
def test_cannot_create_a_non_ogl_dataset_without_specifying_license_name(self): """ Asserts that the user specify a license name if the license is non-OGL """ data = {"license_id": ""} response = self._form_client.post_form(data) assert_in("Licence:</b> Please enter the access constraints.", response.body)
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)
def test_get_children_group_hierarchy__from_top_2(self): groups = model.Group.by_name(u'department-of-health').\ get_children_group_hierarchy(type=group_type) # the first group must be NHS or Food Standards Agency - i.e. on the # first level down nhs = groups[0] assert_in(nhs[1], ('national-health-service', 'food-standards-agency')) assert_equal(model.Group.get(nhs[3]).name, 'department-of-health')
def test_publisher_cannot_edit_a_UKLP_dataset(self): """Test that a publisher cannot access the edit page of a UKLP dataset""" offset = url_for(controller="package", action="edit", id=self.uklp_dataset["id"]) response = None try: response = self.app.get(offset, extra_environ={"REMOTE_USER": self.tester}) except paste.fixture.AppError, e: assert_in("401 Unauthorized", str(e))
def test_publisher_cannot_edit_a_UKLP_dataset(self): """Test that a publisher cannot access the edit page of a UKLP dataset""" offset = url_for(controller='package', action='edit', id=self.uklp_dataset['id']) response = None try: response = self.app.get(offset, extra_environ={'REMOTE_USER': self.tester}) except paste.fixture.AppError, e: assert_in('401 Unauthorized', str(e))
def test_timeseries_resource_url_non_empty(self): """Asserts that timeseries resources must have url defined""" data = { "timeseries_resources__0__description": "description with no url", "timeseries_resources__0__date": "date with no url", "timeseries_resources__0__format": "format with no url", } response = self._form_client.post_form(data) assert_in("URL:</b> Missing value", response.body, response.body)
def test_get_children_groups(self): res = model.Group.by_name(u'department-of-health').\ get_children_groups(type=group_type) # check groups assert_equal(name_set_from_groups(res), set(('national-health-service', 'food-standards-agency'))) # check each group is a Group assert isinstance(res[0], model.Group) assert_in(res[0].name, ('national-health-service', 'food-standards-agency')) assert_in(res[0].title, ('National Health Service', 'Food Standards Agency'))
def test_additional_resources_disallows_non_documentation_resource_types(self): """ Asserts that non-documentation resource types are not allowed for additional resources. """ for resource_type in ["bad", "api", "file"]: data = { "additional_resources__0__description": "Additional resource 1", "additional_resources__0__url": "http://example.com/doc1", "additional_resources__0__resource_type": resource_type, } response = self._form_client.post_form(data) assert_in("Invalid resource type: %s" % resource_type, response.body)
def test_additional_resources_disallows_non_documentation_resource_types(self): """ Asserts that non-documentation resource types are not allowed for additional resources. """ for resource_type in ["bad", "api", "file"]: data = { 'additional_resources__0__description': 'Additional resource 1', 'additional_resources__0__url': 'http://example.com/doc1', 'additional_resources__0__resource_type': resource_type, } response = self._form_client.post_form(data) assert_in("Invalid resource type: %s" % resource_type, response.body)
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'] ])
def test_data_resources_disallows_non_file_or_api_resource_types(self): """ Asserts that non-{file,api} resource types are not allowed for data resources. """ for resource_type in ["bad", "documentation"]: data = { "timeseries_resources__0__description": "Timeseries resource 1", "timeseries_resources__0__url": "http://example.com/data1", "timeseries_resources__0__date": "Summer", "timeseries_resources__0__resource_type": resource_type, } response = self._form_client.post_form(data) assert_in("Invalid resource type: %s" % resource_type, response.body) data = { "individual_resources__0__description": "Individual resource 1", "individual_resources__0__url": "http://example.com/data1", "individual_resources__0__resource_type": resource_type, } response = self._form_client.post_form(data) assert_in("Invalid resource type: %s" % resource_type, response.body)
def test_data_resources_disallows_non_file_or_api_resource_types(self): """ Asserts that non-{file,api} resource types are not allowed for data resources. """ for resource_type in ["bad", "documentation"]: data = { 'timeseries_resources__0__description': 'Timeseries resource 1', 'timeseries_resources__0__url': 'http://example.com/data1', 'timeseries_resources__0__date': 'Summer', 'timeseries_resources__0__resource_type': resource_type, } response = self._form_client.post_form(data) assert_in("Invalid resource type: %s" % resource_type, response.body) data = { 'individual_resources__0__description': 'Individual resource 1', 'individual_resources__0__url': 'http://example.com/data1', 'individual_resources__0__resource_type': resource_type, } response = self._form_client.post_form(data) assert_in("Invalid resource type: %s" % resource_type, response.body)
def test_url_with_404(self, url): result = self.check_link(url) assert_in('Server returned HTTP error status: 404 Not Found', result['url_errors'])
def test_file_url(self): url = u'file:///home/root/test.txt' result = self.check_link(url) assert_in(u'Invalid url scheme. Please use one of: ftp http https', result['url_errors'])
def test_url_with_503(self, url): result = self.check_link(url) assert_in('Server returned HTTP error status: 503 Service Unavailable', result['url_errors'])
def test_empty_url(self): url = u'' result = self.check_link(url) assert_in("URL parsing failure - did not find a host name", result['url_errors'])
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'])
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"])