Skip to content

Commit

Permalink
Continue with stateful tests...
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Oct 1, 2019
1 parent 4afac59 commit 06d0a3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
58 changes: 29 additions & 29 deletions ckan/tests/legacy/logic/test_action.py
Expand Up @@ -80,7 +80,7 @@ def test_01_package_list(self):
assert 'warandpeace' in res['result']
assert 'annakarenina' in res['result']

def test_01_package_list_private(self):
# def test_01_package_list_private(self):
tests.call_action_api(self.app, 'organization_create',
name='test_org_2',
apikey=self.sysadmin_user.apikey)
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_01_package_list_private(self):
assert 'public_dataset' in res
assert 'private_dataset' not in res

def test_02_package_autocomplete_match_name(self):
# def test_02_package_autocomplete_match_name(self):
postparams = '%s=1' % json.dumps({'q': 'war', 'limit': 5})
res = self.app.post('/api/action/package_autocomplete', params=postparams)
res_obj = json.loads(res.body)
Expand All @@ -121,7 +121,7 @@ def test_02_package_autocomplete_match_name(self):
assert_equal(res_obj['result'][0]['match_field'], 'name')
assert_equal(res_obj['result'][0]['match_displayed'], 'warandpeace')

def test_02_package_autocomplete_match_title(self):
# def test_02_package_autocomplete_match_title(self):
postparams = '%s=1' % json.dumps({'q': 'won', 'limit': 5})
res = self.app.post('/api/action/package_autocomplete', params=postparams)
res_obj = json.loads(res.body)
Expand All @@ -132,7 +132,7 @@ def test_02_package_autocomplete_match_title(self):
assert_equal(res_obj['result'][0]['match_field'], 'title')
assert_equal(res_obj['result'][0]['match_displayed'], 'A Wonderful Story (warandpeace)')

def test_03_create_private_package(self):
# def test_03_create_private_package(self):

# Make an organization, because private datasets must belong to one.
organization = tests.call_action_api(self.app, 'organization_create',
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_03_create_private_package(self):
**package_dict)
assert package_created_private['private'] is True

def test_41_create_resource(self):
# def test_41_create_resource(self):

anna_id = model.Package.by_name(u'annakarenina').id
resource = {'package_id': anna_id, 'url': 'http://new_url'}
Expand All @@ -204,7 +204,7 @@ def test_41_create_resource(self):

assert resource['url'] == 'http://new_url'

def test_42_create_resource_with_error(self):
# def test_42_create_resource_with_error(self):

anna_id = model.Package.by_name(u'annakarenina').id
resource = {'package_id': anna_id, 'url': 'new_url', 'created': 'bad_date'}
Expand All @@ -218,7 +218,7 @@ def test_42_create_resource_with_error(self):
assert json.loads(res.body)['error'] == {"__type": "Validation Error", "created": ["Date format incorrect"]}


def test_10_user_create_parameters_missing(self):
# def test_10_user_create_parameters_missing(self):
user_dict = {}

postparams = '%s=1' % json.dumps(user_dict)
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_10_user_create_parameters_missing(self):
assert_equal(res_obj['error'], { '__type': 'Validation Error',
'password': ['Your password must be 8 characters or longer']})

def test_12_user_update(self):
# def test_12_user_update(self):
normal_user_dict = {'id': self.normal_user.id,
'name': self.normal_user.name,
'fullname': 'Updated normal user full name',
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_12_user_update(self):
assert res_obj['error']['__type'] == 'Authorization Error'
assert res_obj['success'] is False

def test_12_user_update_errors(self):
# def test_12_user_update_errors(self):
test_calls = (
# Empty name
{'user_dict': {'id': self.normal_user.id,
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_12_user_update_errors(self):
for expected_message in test_call['messages']:
assert expected_message[1] in ''.join(res_obj['error'][expected_message[0]])

def test_user_delete(self):
# def test_user_delete(self):
name = 'normal_user'
CreateTestData.create_user(name)
user = model.User.get(name)
Expand All @@ -382,7 +382,7 @@ def test_user_delete(self):
assert res_obj['success'] is False
assert res_obj['error']['id'] == ['Missing value']

def test_16_user_autocomplete(self):
# def test_16_user_autocomplete(self):
# Create deleted user to make sure he won't appear in the user_list
deleted_user = CreateTestData.create_user('joe')
deleted_user.delete()
Expand All @@ -405,7 +405,7 @@ def test_16_user_autocomplete(self):
assert res_obj['result'][0]['name'] == 'joeadmin'
assert 'id','fullname' in res_obj['result'][0]

def test_17_bad_action(self):
# def test_17_bad_action(self):
#Empty query
postparams = '%s=1' % json.dumps({})
res = self.app.post('/api/action/bad_action_name', params=postparams,
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_17_bad_action(self):
task_status_updated_2.pop('last_updated')
assert task_status_updated_2 == task_status_updated

def test_21_task_status_update_many(self):
# def test_21_task_status_update_many(self):
package_created = self._add_basic_package(u'test_task_status_update_many')
task_statuses = {
'data': [
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_21_task_status_update_many(self):
task_status_updated.pop('last_updated')
assert task_status == task_status_updated, (task_status_updated, task_status, i)

def test_22_task_status_normal_user_not_authorized(self):
# def test_22_task_status_normal_user_not_authorized(self):
task_status = {}
postparams = '%s=1' % json.dumps(task_status)
res = self.app.post(
Expand All @@ -497,7 +497,7 @@ def test_22_task_status_normal_user_not_authorized(self):
assert res_obj['success'] is False
assert res_obj['error']['__type'] == 'Authorization Error'

def test_23_task_status_validation(self):
# def test_23_task_status_validation(self):
task_status = {}
postparams = '%s=1' % json.dumps(task_status)
res = self.app.post(
Expand All @@ -506,7 +506,7 @@ def test_23_task_status_validation(self):
status=StatusCodes.STATUS_409_CONFLICT
)

def test_24_task_status_show(self):
# def test_24_task_status_show(self):
package_created = self._add_basic_package(u'test_task_status_show')

task_status = {
Expand Down Expand Up @@ -552,7 +552,7 @@ def test_24_task_status_show(self):
task_status_show.pop('last_updated')
assert task_status_show == task_status_updated, (task_status_show, task_status_updated)

def test_25_task_status_delete(self):
# def test_25_task_status_delete(self):
package_created = self._add_basic_package(u'test_task_status_delete')

task_status = {
Expand All @@ -579,7 +579,7 @@ def test_25_task_status_delete(self):
task_status_delete = json.loads(res.body)
assert task_status_delete['success'] == True

def test_26_resource_show(self):
# def test_26_resource_show(self):
pkg = model.Package.get('annakarenina')
resource = pkg.resources[0]
postparams = '%s=1' % json.dumps({'id': resource.id})
Expand All @@ -589,7 +589,7 @@ def test_26_resource_show(self):
resource_dict = resource_dictize(resource, {'model': model})
assert result == resource_dict, (result, resource_dict)

def test_27_get_site_user_not_authorized(self):
# def test_27_get_site_user_not_authorized(self):
assert_raises(NotAuthorized,
get_action('get_site_user'),
{'model': model, 'user': ''}, {})
Expand Down Expand Up @@ -620,42 +620,42 @@ def test_27_get_site_user_not_authorized(self):
assert group_names == set(['annakarenina', 'warandpeace']), group_names


def test_30_status_show(self):
# def test_30_status_show(self):
postparams = '%s=1' % json.dumps({})
res = self.app.post('/api/action/status_show', params=postparams)
status = json.loads(res.body)['result']
assert_equal(status['site_title'], 'CKAN')
assert_equal(status['ckan_version'], ckan.__version__)
assert_equal(status['site_url'], 'http://test.ckan.net')

def test_31_bad_request_format(self):
# def test_31_bad_request_format(self):
postparams = '%s=1' % json.dumps('not a dict')
res = self.app.post('/api/action/package_list', params=postparams,
status=400)
assert "Bad request - JSON Error: Request data JSON decoded to 'not a dict' but it needs to be a dictionary." in res.body, res.body

def test_31_bad_request_format_not_json(self):
# def test_31_bad_request_format_not_json(self):
postparams = '=1'
res = self.app.post('/api/action/package_list', params=postparams,
status=400)
assert "Bad request - JSON Error: Error decoding JSON data." in res.body, res.body

def test_32_get_domain_object(self):
# def test_32_get_domain_object(self):
anna = model.Package.by_name(u'annakarenina')
assert_equal(get_domain_object(model, anna.name).name, anna.name)
assert_equal(get_domain_object(model, anna.id).name, anna.name)
group = model.Group.by_name(u'david')
assert_equal(get_domain_object(model, group.name).name, group.name)
assert_equal(get_domain_object(model, group.id).name, group.name)

def test_41_missing_action(self):
# def test_41_missing_action(self):
try:
get_action('unicorns')
assert False, "We found a non-existent action"
except KeyError:
assert True

def test_42_resource_search_with_single_field_query(self):
# def test_42_resource_search_with_single_field_query(self):
request_body = {
'query': ["description:index"],
}
Expand All @@ -672,7 +672,7 @@ def test_42_resource_search_with_single_field_query(self):
for resource in result:
assert "index" in resource['description'].lower()

def test_42_resource_search_across_multiple_fields(self):
# def test_42_resource_search_across_multiple_fields(self):
request_body = {
'query': ["description:index", "format:json"],
}
Expand All @@ -690,7 +690,7 @@ def test_42_resource_search_across_multiple_fields(self):
assert "index" in resource['description'].lower()
assert "json" in resource['format'].lower()

def test_42_resource_search_test_percentage_is_escaped(self):
# def test_42_resource_search_test_percentage_is_escaped(self):
request_body = {
'query': ["description:index%"],
}
Expand All @@ -704,7 +704,7 @@ def test_42_resource_search_test_percentage_is_escaped(self):
# unescaped wildcard.
assert count == 0

def test_42_resource_search_fields_parameter_still_accepted(self):
# def test_42_resource_search_fields_parameter_still_accepted(self):
'''The fields parameter is deprecated, but check it still works.
Remove this test when removing the fields parameter. (#2603)
Expand All @@ -726,7 +726,7 @@ def test_42_resource_search_fields_parameter_still_accepted(self):
for resource in result:
assert "index" in resource['description'].lower()

def test_42_resource_search_accessible_via_get_request(self):
# def test_42_resource_search_accessible_via_get_request(self):
response = self.app.get('/api/action/resource_search'
'?query=description:index&query=format:json')

Expand Down
12 changes: 12 additions & 0 deletions ckanext/datastore/tests/test_delete.py
@@ -1,6 +1,7 @@
# encoding: utf-8

import json
import pytest
from nose.tools import assert_equal, assert_not_equal, assert_raises

import sqlalchemy.orm as orm
Expand All @@ -17,7 +18,9 @@
DatastoreFunctionalTestBase, DatastoreLegacyTestBase)


@pytest.mark.usefixtures('reset_all', 'app')
class TestDatastoreDelete(DatastoreFunctionalTestBase):
@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_delete_basic(self):
resource = factories.Resource()
data = {
Expand Down Expand Up @@ -50,6 +53,7 @@ def test_delete_basic(self):
resource['id'])
assert results.rowcount == 0

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_calculate_record_count_is_false(self):
resource = factories.Resource()
data = {
Expand All @@ -70,6 +74,7 @@ def test_calculate_record_count_is_false(self):
last_analyze = when_was_last_analyze(resource['id'])
assert_equal(last_analyze, None)

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_calculate_record_count(self):
resource = factories.Resource()
data = {
Expand Down Expand Up @@ -143,6 +148,7 @@ def _delete(self):
assert res_dict['result'] == data
return res_dict

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_datastore_deleted_during_resource_deletion(self):
package = factories.Dataset()
data = {
Expand All @@ -161,6 +167,7 @@ def test_datastore_deleted_during_resource_deletion(self):
NotFound, helpers.call_action, 'datastore_search',
resource_id=resource_id)

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_datastore_deleted_during_resource_only_for_deleted_resource(self):
package = factories.Dataset()
data = {
Expand Down Expand Up @@ -200,6 +207,7 @@ def test_datastore_deleted_during_resource_only_for_deleted_resource(self):
assert not res_1.extras['datastore_active']
assert res_2.extras['datastore_active']

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_delete_invalid_resource_id(self):
postparams = '%s=1' % json.dumps({'resource_id': 'bad'})
auth = {'Authorization': str(self.sysadmin_user.apikey)}
Expand All @@ -208,6 +216,7 @@ def test_delete_invalid_resource_id(self):
res_dict = json.loads(res.body)
assert res_dict['success'] is False

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_delete_filters(self):
self._create()
resource_id = self.data['resource_id']
Expand Down Expand Up @@ -264,6 +273,7 @@ def test_delete_filters(self):

self._delete()

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_delete_is_unsuccessful_when_called_with_invalid_filters(self):
self._create()

Expand All @@ -283,6 +293,7 @@ def test_delete_is_unsuccessful_when_called_with_invalid_filters(self):

self._delete()

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_delete_is_unsuccessful_when_called_with_filters_not_as_dict(self):
self._create()

Expand All @@ -300,6 +311,7 @@ def test_delete_is_unsuccessful_when_called_with_filters_not_as_dict(self):

self._delete()

@pytest.mark.ckan_config('ckan.plugins', 'datastore')
def test_delete_with_blank_filters(self):
self._create()

Expand Down

0 comments on commit 06d0a3f

Please sign in to comment.