Skip to content

Commit

Permalink
Remove few extra nose asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 18, 2019
1 parent 02a1242 commit f04c2da
Show file tree
Hide file tree
Showing 10 changed files with 580 additions and 492 deletions.
2 changes: 1 addition & 1 deletion ckan/tests/controllers/test_admin.py
Expand Up @@ -337,7 +337,7 @@ def test_trash_purge_deleted_datasets(self, app):

# how many datasets after purge
pkgs_after_purge = model.Session.query(model.Package).count()
assert_equal(pkgs_after_purge, 1)
assert pkgs_after_purge == 1


class TestAdminConfigUpdate(object):
Expand Down
184 changes: 89 additions & 95 deletions ckan/tests/controllers/test_package.py
Expand Up @@ -146,30 +146,6 @@ def test_complete_package_with_two_resources(self, app):
assert pkg.resources[1].url == u"http://example.com/resource1"
assert pkg.state == "active"

# def test_resource_uploads(self):
# app = self._get_test_app()
# env, response = _get_package_new_page(app)
# form = response.forms['dataset-edit']
# form['name'] = u'complete-package-with-two-resources'

# response = submit_and_follow(app, form, env, 'save')
# form = response.forms['resource-edit']
# form['upload'] = ('README.rst', b'data')

# response = submit_and_follow(app, form, env, 'save', 'go-metadata')
# pkg = model.Package.by_name(u'complete-package-with-two-resources')
# assert_equal(pkg.resources[0].url_type, u'upload')
# assert_equal(pkg.state, 'active')
# response = app.get(
# url_for(
# controller='package',
# action='resource_download',
# id=pkg.id,
# resource_id=pkg.resources[0].id
# ),
# )
# assert_equal('data', response.body)

@pytest.mark.usefixtures("clean_db")
def test_previous_button_works(self, app):
env, response = _get_package_new_page(app)
Expand Down Expand Up @@ -620,6 +596,7 @@ def test_read_dataset_as_it_used_to_be_but_is_unmigrated(self, app):
model.Session.query(model.Activity)
.filter_by(object_id=dataset["id"])
.one()
)
modern_activity.delete()

# Create an Activity object as it was in earlier versions of CKAN.
Expand Down Expand Up @@ -1862,7 +1839,6 @@ def test_create_dataset(self, app):
in response
)

@pytest.mark.usefixtures("clean_db")
def _clear_activities(self):
model.Session.query(model.Activity).delete()
model.Session.flush()
Expand Down Expand Up @@ -1891,132 +1867,150 @@ def test_change_dataset(self, app):
in response
)

def test_create_tag_directly(self):
app = self._get_test_app()
@pytest.mark.usefixtures("clean_db")
def test_create_tag_directly(self, app):

user = factories.User()
dataset = factories.Dataset(user=user)
self._clear_activities()
dataset['tags'] = [{'name': 'some_tag'}]
dataset["tags"] = [{"name": "some_tag"}]
helpers.call_action(
'package_update', context={'user': user['name']}, **dataset)
"package_update", context={"user": user["name"]}, **dataset
)

url = url_for('dataset.activity',
id=dataset['id'])
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_in('updated the dataset', response)
assert_in('<a href="/dataset/{}">{}'
.format(dataset['id'], dataset['title']),
response)
assert (
'<a href="/user/{}">Mr. Test User'.format(user["name"]) in 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'])
"package_activity_list", id=dataset["id"]
)

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

def test_create_tag(self):
@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()
dataset['tags'] = [{'name': 'some_tag'}]
dataset["tags"] = [{"name": "some_tag"}]
helpers.call_action(
'package_update', context={'user': user['name']}, **dataset)
"package_update", context={"user": user["name"]}, **dataset
)

url = url_for('dataset.activity',
id=dataset['id'])
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_in('updated the dataset', response)
assert_in('<a href="/dataset/{}">{}'
.format(dataset['id'], dataset['title']),
response)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
)

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

assert_equal(len(activities), 1)

def test_create_extra(self):
app = self._get_test_app()
@pytest.mark.usefixtures("clean_db")
def test_create_extra(self, app):
user = factories.User()
dataset = factories.Dataset(user=user)
self._clear_activities()
dataset['extras'] = [{'key': 'some', 'value': 'extra'}]
dataset["extras"] = [{"key": "some", "value": "extra"}]
helpers.call_action(
'package_update', context={'user': user['name']}, **dataset)
"package_update", context={"user": user["name"]}, **dataset
)

url = url_for('dataset.activity',
id=dataset['id'])
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_in('updated the dataset', response)
assert_in('<a href="/dataset/{}">{}'
.format(dataset['id'], dataset['title']),
response)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
)

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

assert_equal(len(activities), 1)

def test_create_resource(self):
app = self._get_test_app()
@pytest.mark.usefixtures("clean_db")
def test_create_resource(self, app):
user = factories.User()
dataset = factories.Dataset(user=user)
self._clear_activities()
helpers.call_action(
'resource_create', context={'user': user['name']},
name='Test resource',
package_id=dataset['id'])
"resource_create",
context={"user": user["name"]},
name="Test resource",
package_id=dataset["id"],
)

url = url_for('dataset.activity',
id=dataset['id'])
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_in('updated the dataset', response)
assert_in('<a href="/dataset/{}">{}'
.format(dataset['id'], dataset['title']),
response)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
)

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

assert_equal(len(activities), 1)

def test_update_resource(self):
app = self._get_test_app()
@pytest.mark.usefixtures("clean_db")
def test_update_resource(self, app):
user = factories.User()
dataset = factories.Dataset(user=user)
resource = factories.Resource(package_id=dataset['id'])
resource = factories.Resource(package_id=dataset["id"])
self._clear_activities()

helpers.call_action(
'resource_update', context={'user': user['name']},
id=resource['id'],
name='Test resource updated',
package_id=dataset['id'])
"resource_update",
context={"user": user["name"]},
id=resource["id"],
name="Test resource updated",
package_id=dataset["id"],
)

url = url_for('dataset.activity',
id=dataset['id'])
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_in('updated the dataset', response)
assert_in('<a href="/dataset/{}">{}'
.format(dataset['id'], dataset['title']),
response)
assert_in(
'<a href="/user/{}">Mr. Test User'.format(user["name"]), response
)
assert_in("updated the dataset", response)
assert_in(
'<a href="/dataset/{}">{}'.format(dataset["id"], dataset["title"]),
response,
)

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

assert_equal(len(activities), 1)


@pytest.mark.usefixtures("clean_db")
def test_delete_dataset(self, app):
user = factories.User()
Expand Down
6 changes: 2 additions & 4 deletions ckan/tests/logic/test_validators.py
@@ -1,4 +1,3 @@

# encoding: utf-8
"""Unit tests for ckan/logic/validators.py.
Expand Down Expand Up @@ -747,17 +746,16 @@ def call_validator(*args, **kwargs):
call_validator(key, {key: url}, errors, None)



class TestOneOfValidator(object):

def test_val_in_list(self):
cont = [1, 2, 3, 4]
func = validators.one_of(cont)
assert_equals(func(1), 1)
assert func(1) == 1

def test_val_not_in_list(self):
cont = [1, 2, 3, 4]
func = validators.one_of(cont)
raises_Invalid(func)(5)


# TODO: Need to test when you are not providing owner_org and the validator queries for the dataset with package_show

0 comments on commit f04c2da

Please sign in to comment.