def test_name_required(self): response = self.app.get(url=self.organization_new_url, extra_environ=self.user_env) form = response.forms["organization-edit-form"] response = webtest_submit(form, name="save", extra_environ=self.user_env) assert_true("organization-edit-form" in response.forms) assert_true("Name: Missing value" in response)
def test_organization_search_within_org_results(self): '''Searching within an organization returns expected dataset results.''' app = self._get_test_app() org = factories.Organization() factories.Dataset(name="ds-one", title="Dataset One", owner_org=org['id']) factories.Dataset(name="ds-two", title="Dataset Two", owner_org=org['id']) factories.Dataset(name="ds-three", title="Dataset Three", owner_org=org['id']) org_url = url_for('organization.read', id=org['name']) org_response = app.get(org_url) search_form = org_response.forms['organization-datasets-search-form'] search_form['q'] = 'One' search_response = webtest_submit(search_form) assert_true('1 dataset found for "One"' in search_response) search_response_html = BeautifulSoup(search_response.body) ds_titles = search_response_html.select('.dataset-list ' '.dataset-item ' '.dataset-heading a') ds_titles = [t.string for t in ds_titles] assert_equal(len(ds_titles), 1) assert_true('Dataset One' in ds_titles) assert_true('Dataset Two' not in ds_titles) assert_true('Dataset Three' not in ds_titles)
def test_spatial_extra_bad_geojson(self, app): user = factories.User() env = {"REMOTE_USER": user["name"].encode("ascii")} dataset = factories.Dataset(user=user) if tk.check_ckan_version(min_version="2.9"): offset = url_for("dataset.edit", id=dataset["id"]) else: offset = url_for(controller="package", action="edit", id=dataset["id"]) res = app.get(offset, extra_environ=env) if tk.check_ckan_version(min_version="2.9"): data = { "name": dataset['name'], "extras__0__key": u"spatial", "extras__0__value": u'{"Type":"Bad_GeoJSON","a":2}' } res = app.post(offset, environ_overrides=env, data=data) else: form = res.forms[1] form['extras__0__key'] = u'spatial' form['extras__0__value'] = u'{"Type":"Bad_GeoJSON","a":2}' res = helpers.webtest_submit(form, extra_environ=env, name='save') assert "Error" in res, res assert "Spatial" in res assert "Error creating geometry" in res
def test_organization_search_within_org_results(self): """Searching within an organization returns expected dataset results.""" app = self._get_test_app() org = factories.Organization() factories.Dataset(name="ds-one", title="Dataset One", owner_org=org["id"]) factories.Dataset(name="ds-two", title="Dataset Two", owner_org=org["id"]) factories.Dataset(name="ds-three", title="Dataset Three", owner_org=org["id"]) org_url = url_for(controller="organization", action="read", id=org["id"]) org_response = app.get(org_url) search_form = org_response.forms["organization-datasets-search-form"] search_form["q"] = "One" search_response = webtest_submit(search_form) assert_true("1 dataset found for "One"" in search_response) search_response_html = BeautifulSoup(search_response.body) ds_titles = search_response_html.select(".dataset-list " ".dataset-item " ".dataset-heading a") ds_titles = [t.string for t in ds_titles] assert_equal(len(ds_titles), 1) assert_true("Dataset One" in ds_titles) assert_true("Dataset Two" not in ds_titles) assert_true("Dataset Three" not in ds_titles)
def test_organization_search_within_org_no_results(self, app): """Searching for non-returning phrase within an organization returns no results.""" org = factories.Organization() factories.Dataset( name="ds-one", title="Dataset One", owner_org=org["id"] ) factories.Dataset( name="ds-two", title="Dataset Two", owner_org=org["id"] ) factories.Dataset( name="ds-three", title="Dataset Three", owner_org=org["id"] ) org_url = url_for("organization.read", id=org["name"]) org_response = app.get(org_url) search_form = org_response.forms["organization-datasets-search-form"] search_form["q"] = "Nout" search_response = webtest_submit(search_form) assert 'No datasets found for "Nout"' in search_response.body search_response_html = BeautifulSoup(search_response.body) ds_titles = search_response_html.select( ".dataset-list " ".dataset-item " ".dataset-heading a" ) ds_titles = [t.string for t in ds_titles] assert len(ds_titles) == 0
def test_delete(self, app): self.user = factories.User() self.user_env = {"REMOTE_USER": self.user["name"].encode("ascii")} self.organization = factories.Organization(user=self.user) datasets = [ factories.Dataset(owner_org=self.organization["id"], private=True) for i in range(0, 5) ] response = app.get( url=url_for( "organization.bulk_process", id=self.organization["id"] ), extra_environ=self.user_env, ) form = response.forms[1] for v in form.fields.values(): try: v[0].checked = True except AttributeError: pass response = webtest_submit( form, name="bulk_action.delete", value="delete", extra_environ=self.user_env, ) for dataset in datasets: d = helpers.call_action("package_show", id=dataset["id"]) assert d["state"] == "deleted"
def test_organization_search_within_org_no_results(self): '''Searching for non-returning phrase within an organization returns no results.''' app = self._get_test_app() org = factories.Organization() factories.Dataset(name="ds-one", title="Dataset One", owner_org=org['id']) factories.Dataset(name="ds-two", title="Dataset Two", owner_org=org['id']) factories.Dataset(name="ds-three", title="Dataset Three", owner_org=org['id']) org_url = url_for(controller='organization', action='read', id=org['id']) org_response = app.get(org_url) search_form = org_response.forms['organization-datasets-search-form'] search_form['q'] = 'Nout' search_response = webtest_submit(search_form) assert_true('No datasets found for "Nout"' in search_response) search_response_html = BeautifulSoup(search_response.body) ds_titles = search_response_html.select('.dataset-list ' '.dataset-item ' '.dataset-heading a') ds_titles = [t.string for t in ds_titles] assert_equal(len(ds_titles), 0)
def test_saved(self): response = self.app.get(url=self.organization_edit_url, extra_environ=self.user_env) form = response.forms["organization-edit-form"] response = webtest_submit(form, name="save", extra_environ=self.user_env) group = helpers.call_action("organization_show", id=self.organization["id"]) assert_equal(group["title"], u"Test Organization") assert_equal(group["type"], "organization") assert_equal(group["state"], "active")
def test_name_required(self, app, user_env): response = app.get( url=url_for("organization.new"), extra_environ=user_env ) form = response.forms["organization-edit-form"] response = webtest_submit(form, name="save", extra_environ=user_env) assert "organization-edit-form" in response.forms assert "Name: Missing value" in response
def test_name_required(self): response = self.app.get(url=self.organization_new_url, extra_environ=self.user_env) form = response.forms['organization-edit-form'] response = webtest_submit(form, name='save', extra_environ=self.user_env) assert_true('organization-edit-form' in response.forms) assert_true('Name: Missing value' in response)
def test_saved(self): response = self.app.get(url=self.organization_edit_url, extra_environ=self.user_env) form = response.forms['organization-edit-form'] response = webtest_submit(form, name='save', extra_environ=self.user_env) group = helpers.call_action('organization_show', id=self.organization['id']) assert_equal(group['title'], u'Test Organization') assert_equal(group['type'], 'organization') assert_equal(group['state'], 'active')
def test_all_fields_saved(self): response = self.app.get(url=self.organization_edit_url, extra_environ=self.user_env) form = response.forms["organization-edit-form"] form["name"] = u"all-fields-edited" form["title"] = "Science" form["description"] = "Sciencey datasets" form["image_url"] = "http://example.com/image.png" response = webtest_submit(form, name="save", extra_environ=self.user_env) group = helpers.call_action("organization_show", id=self.organization["id"]) assert_equal(group["title"], u"Science") assert_equal(group["description"], "Sciencey datasets") assert_equal(group["image_url"], "http://example.com/image.png")
def test_organization_search_no_results(self): """Searching with a term that doesn't apply returns no results.""" index_response = self.app.get(self.search_url) search_form = index_response.forms["organization-search-form"] search_form["q"] = "No Results Here" search_response = webtest_submit(search_form) search_response_html = BeautifulSoup(search_response.body) org_names = search_response_html.select("ul.media-grid " "li.media-item " "h3.media-heading") org_names = [n.string for n in org_names] assert_equal(len(org_names), 0) assert_true("No organizations found for "No Results Here"" in search_response)
def test_delete(self): datasets = [factories.Dataset(owner_org=self.organization["id"], private=True) for i in range(0, 5)] response = self.app.get(url=self.organization_bulk_url, extra_environ=self.user_env) form = response.forms[1] for v in form.fields.values(): try: v[0].checked = True except AttributeError: pass response = webtest_submit(form, name="bulk_action.delete", value="delete", extra_environ=self.user_env) for dataset in datasets: d = helpers.call_action("package_show", id=dataset["id"]) assert_equal(d["state"], "deleted")
def test_organization_search_results(self): """Searching via organization search form returns list of expected organizations.""" index_response = self.app.get(self.search_url) search_form = index_response.forms["organization-search-form"] search_form["q"] = "AOrg" search_response = webtest_submit(search_form) search_response_html = BeautifulSoup(search_response.body) org_names = search_response_html.select("ul.media-grid " "li.media-item " "h3.media-heading") org_names = [n.string for n in org_names] assert_equal(len(org_names), 2) assert_true("AOrg One" in org_names) assert_true("AOrg Two" in org_names) assert_true("Org Three" not in org_names)
def test_all_fields_saved(self): response = self.app.get(url=self.organization_edit_url, extra_environ=self.user_env) form = response.forms['organization-edit-form'] form['name'] = u'all-fields-edited' form['title'] = 'Science' form['description'] = 'Sciencey datasets' form['image_url'] = 'http://example.com/image.png' response = webtest_submit(form, name='save', extra_environ=self.user_env) group = helpers.call_action('organization_show', id=self.organization['id']) assert_equal(group['title'], u'Science') assert_equal(group['description'], 'Sciencey datasets') assert_equal(group['image_url'], 'http://example.com/image.png')
def test_organization_search_no_results(self): '''Searching with a term that doesn't apply returns no results.''' index_response = self.app.get(self.search_url) search_form = index_response.forms['organization-search-form'] search_form['q'] = 'No Results Here' search_response = webtest_submit(search_form) search_response_html = BeautifulSoup(search_response.body) org_names = search_response_html.select('ul.media-grid ' 'li.media-item ' 'h3.media-heading') org_names = [n.string for n in org_names] assert_equal(len(org_names), 0) assert_true("No organizations found for "No Results Here"" in search_response)
def test_saved(self, app, initial_data): response = app.get( url=url_for( "organization.edit", id=initial_data["organization"]["id"] ), extra_environ=initial_data["user_env"], ) form = response.forms["organization-edit-form"] response = webtest_submit( form, name="save", extra_environ=initial_data["user_env"] ) group = helpers.call_action( "organization_show", id=initial_data["organization"]["id"] ) assert group["title"] == u"Test Organization" assert group["type"] == "organization" assert group["state"] == "active"
def test_make_private(self): datasets = [factories.Dataset(owner_org=self.organization['id']) for i in range(0, 5)] response = self.app.get(url=self.organization_bulk_url, extra_environ=self.user_env) form = response.forms[1] for v in form.fields.values(): try: v[0].checked = True except AttributeError: pass response = webtest_submit(form, name='bulk_action.private', value='private', extra_environ=self.user_env) for dataset in datasets: d = helpers.call_action('package_show', id=dataset['id']) assert_equal(d['private'], True)
def test_organization_search_results(self): '''Searching via organization search form returns list of expected organizations.''' index_response = self.app.get(self.search_url) search_form = index_response.forms['organization-search-form'] search_form['q'] = 'AOrg' search_response = webtest_submit(search_form) search_response_html = BeautifulSoup(search_response.body) org_names = search_response_html.select('ul.media-grid ' 'li.media-item ' 'h3.media-heading') org_names = [n.string for n in org_names] assert_equal(len(org_names), 2) assert_true('AOrg One' in org_names) assert_true('AOrg Two' in org_names) assert_true('Org Three' not in org_names)
def test_organization_search_results(self, app): """Searching via organization search form returns list of expected organizations.""" factories.Organization(name="org-one", title="AOrg One") factories.Organization(name="org-two", title="AOrg Two") factories.Organization(name="org-three", title="Org Three") index_response = app.get(url_for("organization.index")) search_form = index_response.forms["organization-search-form"] search_form["q"] = "AOrg" search_response = webtest_submit(search_form) search_response_html = BeautifulSoup(search_response.body) org_names = search_response_html.select( "ul.media-grid " "li.media-item " "h3.media-heading" ) org_names = [n.string for n in org_names] assert len(org_names) == 2 assert "AOrg One" in org_names assert "AOrg Two" in org_names assert "Org Three" not in org_names
def test_organization_search_no_results(self, app): """Searching with a term that doesn't apply returns no results.""" factories.Organization(name="org-one", title="AOrg One") factories.Organization(name="org-two", title="AOrg Two") factories.Organization(name="org-three", title="Org Three") index_response = app.get(url_for("organization.index")) search_form = index_response.forms["organization-search-form"] search_form["q"] = "No Results Here" search_response = webtest_submit(search_form) search_response_html = BeautifulSoup(search_response.body) org_names = search_response_html.select( "ul.media-grid " "li.media-item " "h3.media-heading" ) org_names = [n.string for n in org_names] assert len(org_names) == 0 assert ( 'No organizations found for "No Results Here"' in search_response.body )
def test_all_fields_saved(self, app, initial_data): response = app.get( url=url_for( "organization.edit", id=initial_data["organization"]["id"] ), extra_environ=initial_data["user_env"], ) form = response.forms["organization-edit-form"] form["name"] = u"all-fields-edited" form["title"] = "Science" form["description"] = "Sciencey datasets" form["image_url"] = "http://example.com/image.png" response = webtest_submit( form, name="save", extra_environ=initial_data["user_env"] ) group = helpers.call_action( "organization_show", id=initial_data["organization"]["id"] ) assert group["title"] == u"Science" assert group["description"] == "Sciencey datasets" assert group["image_url"] == "http://example.com/image.png"