def test_general_atom_feed_works(self, app): dataset = factories.Dataset(notes="Test\x0c Notes") offset = url_for(u"feeds.general") res = app.get(offset) assert helpers.body_contains( res, u"<title>{0}</title>".format(dataset["title"])) assert helpers.body_contains(res, u"<content>Test Notes</content>")
def test_08_all_fields_syntax_error(self): offset = (self.base_url + "?all_fields=should_be_boolean" ) # invalid all_fields value res = self.app.get(offset, status=400) assert body_contains(res, "boolean") assert body_contains(res, "all_fields") self.assert_json_response(res, "boolean")
def test_custom_atom_feed_works(self, app): dataset1 = factories.Dataset( title=u"Test weekly", extras=[{ "key": "frequency", "value": "weekly" }], ) dataset2 = factories.Dataset( title=u"Test daily", extras=[{ "key": "frequency", "value": "daily" }], ) offset = url_for(u"feeds.custom") params = {"q": "frequency:weekly"} res = app.get(offset, query_string=params) assert helpers.body_contains( res, u"<title>{0}</title>".format(dataset1["title"])) assert not helpers.body_contains( res, u'<title">{0}</title>'.format(dataset2["title"]))
def test_general_atom_feed_works_with_no_notes(self, app): dataset = factories.Dataset(notes=None) offset = url_for(u"feeds.general") res = app.get(offset) assert helpers.body_contains( res, u"<title>{0}</title>".format(dataset["title"])) assert helpers.body_contains(res, u"<content/>")
def test_flash_success(self, app): """ Test flash_success messages are rendered. """ url = "/flash_success_redirect" res = app.get(url) assert body_contains(res, "This is a success message") assert body_contains(res, 'alert-success')
def test_flash_success_with_html(self, app): """ Test flash_success messages are rendered. """ url = "/flash_success_html_redirect" res = app.get(url) assert body_contains(res, "<h1> This is a success message with HTML</h1>") assert body_contains(res, 'alert-success')
def test_translated_string_in_extensions_templates(self, app): response = app.get( url=plugins.toolkit.url_for(u"home.index", locale="fr"), ) assert helpers.body_contains(response, "This is a itranslated string") assert not helpers.body_contains(response, "This is an untranslated string") # double check the untranslated strings response = app.get(url=plugins.toolkit.url_for(u"home.index"),) assert helpers.body_contains(response, "This is an untranslated string") assert not helpers.body_contains(response, "This is a itranslated string")
def test_pagination(self, app): user = factories.User() group = factories.Organization(user=user, type=custom_group_type) group_name = group["name"] for _ in range(0, 21): factories.Dataset(owner_org=group['id'], user=user) env = {"REMOTE_USER": six.ensure_str(user["name"])} url = url_for("%s.read" % custom_group_type, id=group_name) response = app.get(url=url, extra_environ=env) assert helpers.body_contains(response, '/grup/{}?page=2'.format(group_name)) assert not helpers.body_contains( response, '/organization/{}?page=2'.format(group_name))
def test_config_page_has_custom_tabs(self, app): """ The admin base template should include our custom ckan-admin tabs added using the toolkit.add_ckan_admin_tab method. """ response = app.get("/ckan-admin/myext_config_one", status=200) assert response.status_code == 200 # The label text assert helpers.body_contains(response, "My First Custom Config Tab") assert helpers.body_contains(response, "My Second Custom Config Tab") # The link path assert helpers.body_contains(response, "/ckan-admin/myext_config_one") assert helpers.body_contains(response, "/ckan-admin/myext_config_two")
def test_12_v1_or_v2_syntax(self): offset = self.base_url + "?all_fields=1" res = self.app.get(offset, status=400) assert body_contains( res, "Invalid search parameters: ['all_fields']" )
def test_11_pagination_validation_error(self): offset = ( self.base_url + "?fl=*&q=tags:russian&start=should_be_integer&rows=1&sort=name asc" ) # invalid offset value res = self.app.get(offset, status=409) assert body_contains(res, "Validation Error")
def test_about(self, app, user): env = {"Authorization": user["token"]} group = factories.Organization(user=user, type=custom_group_type) group_name = group["name"] url = url_for("%s.about" % custom_group_type, id=group_name) response = app.get(url=url, extra_environ=env) assert helpers.body_contains(response, group_name)
def test_pagination(self, app, user): env = {"Authorization": user["token"]} group = factories.Organization(user=user, type=custom_group_type) group_name = group["name"] for _ in range(0, 21): factories.Dataset(owner_org=group['id'], user=user) url = url_for("%s.read" % custom_group_type, id=group_name) response = app.get(url=url, extra_environ=env) assert helpers.body_contains( response, '/grup/{}?page=2'.format(group_name) ) assert not helpers.body_contains( response, '/organization/{}?page=2'.format(group_name) )
def test_remove_member(self, current_user, app): """Member can be removed from group""" user = factories.User(fullname="My Owner") user_obj = model.User.get(user["name"]) # mock current_user current_user.return_value = user_obj user_two = factories.User(fullname="User Two") other_users = [{"name": user_two["id"], "capacity": "member"}] group = self._create_group(user["name"], other_users) remove_url = url_for("group.member_delete", user=user_two["id"], id=group["id"]) remove_response = app.post(remove_url) assert helpers.body_contains(remove_response, "1 members") remove_response_html = BeautifulSoup(remove_response.body) user_names = [ u.string for u in remove_response_html.select("#member-table td.media a") ] roles = [ r.next_sibling.next_sibling.string for r in remove_response_html.select("#member-table td.media") ] user_roles = dict(zip(user_names, roles)) assert len(user_roles.keys()) == 1 assert user_roles["My Owner"] == "Admin"
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( title="Dataset One", owner_org=org["id"] ) factories.Dataset( title="Dataset Two", owner_org=org["id"] ) factories.Dataset( title="Dataset Three", owner_org=org["id"] ) org_url = url_for("organization.read", id=org["name"]) search_response = app.get( org_url, query_string={"q": "Nout"} ) assert helpers.body_contains(search_response, 'No datasets found for "Nout"') 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_flask_request_in_template(self, app): u""" Test that we are using Flask request wrapped with CKANRequest params is should be accessible for backward compatibility """ res = app.get(u"/flask_request?test=it_works") assert helpers.body_contains(res, 'it_works')
def test_helper_existing_helper_as_item(self, app): """Calling an existing helper on `h` doesn't raises a HelperException.""" res = app.get("/helper_as_item") assert helpers.body_contains(res, "My lang is: en")
def test_custom_group_form(self, app): """Our custom group form is being used to edit groups.""" env, response, group_name = _get_group_edit_page( app, custom_group_type ) assert helpers.body_contains(response, "My Custom Group Form!")
def test_remove_member(self, app): """Member can be removed from group""" user_one = factories.User(fullname="User One", name="user-one") user_two = factories.User(fullname="User Two") other_users = [{"name": user_two["id"], "capacity": "member"}] group = self._create_group(user_one["name"], other_users) remove_url = url_for("group.member_delete", user=user_two["id"], id=group["id"]) env = {"REMOTE_USER": six.ensure_str(user_one["name"])} remove_response = app.post(remove_url, extra_environ=env) assert helpers.body_contains(remove_response, "1 members") remove_response_html = BeautifulSoup(remove_response.body) user_names = [ u.string for u in remove_response_html.select("#member-table td.media a") ] roles = [ r.next_sibling.next_sibling.string for r in remove_response_html.select("#member-table td.media") ] user_roles = dict(zip(user_names, roles)) assert len(user_roles.keys()) == 1 assert user_roles["User One"] == "Admin"
def test_group_search_within_org_no_results(self, app): """Searching for non-returning phrase within an group returns no results.""" grp = factories.Group() factories.Dataset(name="ds-one", title="Dataset One", groups=[{ "id": grp["id"] }]) factories.Dataset(name="ds-two", title="Dataset Two", groups=[{ "id": grp["id"] }]) factories.Dataset(name="ds-three", title="Dataset Three", groups=[{ "id": grp["id"] }]) grp_url = url_for("group.read", id=grp["name"]) search_response = app.get(grp_url, query_string={"q": "Nout"}) assert helpers.body_contains(search_response, 'No datasets found for "Nout"') 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_plugin_route_core_flask_override(self, app): u"""Test extension overrides flask core route.""" res = app.get(u"/") assert helpers.body_contains( res, u"Hello World, this is served from an extension, " u"overriding the flask url.")
def test_changes(self, app): user = factories.User() dataset = factories.Dataset(title="First title", user=user) dataset["title"] = "Second title" helpers.call_action("package_update", **dataset) activity = activity_model.package_activity_list( dataset["id"], limit=1, offset=0 )[0] env = {"REMOTE_USER": user["name"]} response = app.get( url_for("activity.package_changes", id=activity.id), extra_environ=env, ) assert helpers.body_contains(response, "First") assert helpers.body_contains(response, "Second")
def test_flash_populated_in_flask_view_redirect_to_pylons(self, app): u""" Flash store is populated by flask view is accessible by pylons action. """ res = app.get(u"/flask_add_flash_message_redirect_pylons") assert body_contains(res, u"This is a success message populated by Flask")
def test_plugin_route_with_helper(self, app): u""" Test extension rendering with a helper method that exists shouldn't cause error. """ res = app.get(u"/helper") assert helpers.body_contains(res, u"Hello World, helper here: <p><em>hi</em></p>")
def test_about(self, app): user = factories.User() group = factories.Organization(user=user, type=custom_group_type) group_name = group["name"] env = {"REMOTE_USER": six.ensure_str(user["name"])} url = url_for("%s.about" % custom_group_type, id=group_name) response = app.get(url=url, extra_environ=env) assert helpers.body_contains(response, group_name)
def test_organization_atom_feed_works(self, app): group = factories.Organization() dataset = factories.Dataset(owner_org=group["id"]) offset = url_for(u"feeds.organization", id=group["name"]) res = app.get(offset) assert helpers.body_contains( res, u"<title>{0}</title>".format(dataset["title"]))
def test_group_atom_feed_works(self, app): group = factories.Group() dataset = factories.Dataset(groups=[{"id": group["id"]}]) offset = url_for(u"feeds.group", id=group["name"]) res = app.get(offset) assert helpers.body_contains( res, u"<title>{0}</title>".format(dataset["title"]))
def test_before_view(self, app): res = app.get("/dataset/annakarenina") assert body_contains(res, "string_not_found_in_rest_of_template") res = app.get("/dataset?q=") assert six.ensure_str( res.body).count("string_not_found_in_rest_of_template") == 2
def test_unicode_in_error_message_works_ok(self, app): # Use tag_delete to echo back some unicode org_url = "/api/action/tag_delete" data_dict = {"id": u"Delta symbol: \u0394"} # unicode gets rec'd ok response = app.post(url=org_url, data=data_dict, status=404) # The unicode is backslash encoded (because that is the default when # you do str(exception) ) assert helpers.body_contains(response, "Delta symbol: \\u0394")
def test_flash_populated_by_flask_redirect_to_flask(self, app): """ Flash store is populated by Flask view is accessible by another Flask view. """ url = "/flask_add_flash_message_redirect_to_flask" res = app.get(url) assert body_contains(res, "This is a success message populated by Flask")