Skip to content

Commit

Permalink
replace nose asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 19, 2019
1 parent f04c2da commit cb73287
Show file tree
Hide file tree
Showing 23 changed files with 466 additions and 686 deletions.
8 changes: 0 additions & 8 deletions .circleci/config.yml
Expand Up @@ -77,14 +77,6 @@ jobs:
- store_test_results:
path: ~/junit

# test_revision_legacy_code is run separately because it mucks up the model for some other tests when nose starts up
- run:
command: |
case $CIRCLE_NODE_INDEX in
3) nosetests -v --ckan --with-pylons=test-core-circle-ci.ini --nologcapture test_revision_legacy_code.py
;;
esac
# Tests Frontend, only in one container
- run:
command: |
Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/controllers/test_admin.py
Expand Up @@ -354,7 +354,7 @@ def _update_config_option(self, app):
webtest_submit(form, "save", status=302, extra_environ=env)

@pytest.mark.usefixtures("clean_db")
def test_admin_config_update(self, make_app):
def test_admin_config_update(self, app):
"""Changing a config option using the admin interface appropriately
updates value returned by config_option_show,
system_info.get_system_info and in the title tag in templates."""
Expand All @@ -377,7 +377,7 @@ def test_admin_config_update(self, make_app):
assert before_update_default == "CKAN"

# title tag contains default value
app = make_app()
# app = make_app()
home_page_before = app.get("/", status=200)
assert "Welcome - CKAN" in home_page_before

Expand Down
19 changes: 7 additions & 12 deletions ckan/tests/controllers/test_group.py
Expand Up @@ -161,27 +161,26 @@ def test_all_fields_saved(self, app):

class TestGroupRead(object):
@pytest.mark.usefixtures("clean_db")
def test_group_read(self):
def test_group_read(self, app):
group = factories.Group()
app = helpers._get_test_app()
response = app.get(url=url_for("group.read", id=group["name"]))
assert group["title"] in response
assert group["description"] in response

@pytest.mark.usefixtures("clean_db")
def test_redirect_when_given_id(self):
def test_redirect_when_given_id(self, app):
group = factories.Group()
app = helpers._get_test_app()

response = app.get(url_for("group.read", id=group["id"]), status=302)
# redirect replaces the ID with the name in the URL
redirected_response = response.follow()
expected_url = url_for("group.read", id=group["name"])
assert redirected_response.request.path == expected_url

@pytest.mark.usefixtures("clean_db")
def test_no_redirect_loop_when_name_is_the_same_as_the_id(self):
def test_no_redirect_loop_when_name_is_the_same_as_the_id(self, app):
group = factories.Group(id="abc", name="abc")
app = helpers._get_test_app()

# 200 == no redirect
app.get(url_for("group.read", id=group["id"]), status=200)

Expand Down Expand Up @@ -411,15 +410,13 @@ def test_remove_member(self, app):
assert user_roles["User One"] == "Admin"

@pytest.mark.usefixtures("clean_db")
def test_member_users_cannot_add_members(self):
def test_member_users_cannot_add_members(self, app):

user = factories.User()
group = factories.Group(
users=[{"name": user["name"], "capacity": "member"}]
)

app = helpers._get_test_app()

env = {"REMOTE_USER": user["name"].encode("ascii")}

with app.flask_app.test_request_context():
Expand All @@ -442,11 +439,9 @@ def test_member_users_cannot_add_members(self):
)

@pytest.mark.usefixtures("clean_db")
def test_anonymous_users_cannot_add_members(self):
def test_anonymous_users_cannot_add_members(self, app):
group = factories.Group()

app = helpers._get_test_app()

with app.flask_app.test_request_context():
app.get(url_for("group.member_new", id=group["id"]), status=403)

Expand Down
57 changes: 28 additions & 29 deletions ckan/tests/controllers/test_package.py
Expand Up @@ -1897,7 +1897,6 @@ def test_create_tag_directly(self, app):

@pytest.mark.usefixtures("clean_db")
def test_create_tag(self, app):
app = self._get_test_app()
user = factories.User()
dataset = factories.Dataset(user=user)
self._clear_activities()
Expand All @@ -1908,20 +1907,20 @@ def test_create_tag(self, app):

url = url_for("dataset.activity", id=dataset["id"])
response = app.get(url)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
assert (
'<a href="/user/{}">Mr. Test User'.format(user["name"]) in response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
assert "updated the dataset" in response
assert (
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"])
in response
)

activities = helpers.call_action(
"package_activity_list", id=dataset["id"]
)

assert_equal(len(activities), 1)
assert len(activities) == 1

@pytest.mark.usefixtures("clean_db")
def test_create_extra(self, app):
Expand All @@ -1935,20 +1934,20 @@ def test_create_extra(self, app):

url = url_for("dataset.activity", id=dataset["id"])
response = app.get(url)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
assert (
'<a href="/user/{}">Mr. Test User'.format(user["name"]) in response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
assert "updated the dataset" in response
assert (
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"])
in response
)

activities = helpers.call_action(
"package_activity_list", id=dataset["id"]
)

assert_equal(len(activities), 1)
assert len(activities) == 1

@pytest.mark.usefixtures("clean_db")
def test_create_resource(self, app):
Expand All @@ -1964,20 +1963,20 @@ def test_create_resource(self, app):

url = url_for("dataset.activity", id=dataset["id"])
response = app.get(url)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
assert (
'<a href="/user/{}">Mr. Test User'.format(user["name"]) in response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
assert "updated the dataset" in response
assert (
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"])
in response
)

activities = helpers.call_action(
"package_activity_list", id=dataset["id"]
)

assert_equal(len(activities), 1)
assert len(activities) == 1

@pytest.mark.usefixtures("clean_db")
def test_update_resource(self, app):
Expand All @@ -1996,20 +1995,20 @@ def test_update_resource(self, app):

url = url_for("dataset.activity", id=dataset["id"])
response = app.get(url)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
assert (
'<a href="/user/{}">Mr. Test User'.format(user["name"]) in response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
assert "updated the dataset" in response
assert (
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"])
in response
)

activities = helpers.call_action(
"package_activity_list", id=dataset["id"]
)

assert_equal(len(activities), 1)
assert len(activities) == 1

@pytest.mark.usefixtures("clean_db")
def test_delete_dataset(self, app):
Expand Down
3 changes: 1 addition & 2 deletions ckan/tests/legacy/functional/api/__init__.py
@@ -1,6 +1,5 @@
# encoding: utf-8

from nose.tools import assert_equal
import copy


Expand Down Expand Up @@ -43,4 +42,4 @@ def assert_dicts_equal_ignoring_ordering(dict1, dict2):
dicts = [copy.deepcopy(dict1), copy.deepcopy(dict2)]
for d in dicts:
d = change_lists_to_sets(d)
assert_equal(dicts[0], dicts[1])
assert dicts[0] == dicts[1]

0 comments on commit cb73287

Please sign in to comment.