Skip to content

Commit

Permalink
[#356] Functional API tests
Browse files Browse the repository at this point in the history
* Remove the old commented functional tests testing against the
  templates.
* New tests that test against the API.
  • Loading branch information
nigelbabu committed Mar 26, 2013
1 parent 86cabe9 commit 56a87cc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
54 changes: 51 additions & 3 deletions ckan/tests/functional/api/test_user.py
@@ -1,20 +1,25 @@
import paste
from pylons import config
from nose.tools import assert_equal

import ckan.logic as logic
from ckan import model
from ckan.lib.create_test_data import CreateTestData
from ckan.tests import TestController as ControllerTestCase
from ckan.tests.pylons_controller import PylonsTestCase
from ckan.tests import url_for
import ckan.config.middleware
from ckan.common import json

class TestUserApi(ControllerTestCase):
@classmethod
def setup_class(cls):
CreateTestData.create()

@classmethod
def teardown_class(cls):
model.repo.rebuild_db()

def test_autocomplete(self):
response = self.app.get(
url=url_for(controller='api', action='user_autocomplete', ver=2),
Expand Down Expand Up @@ -51,8 +56,51 @@ def test_autocomplete_limit(self):
print response.json
assert_equal(len(response.json), 1)

def test_user_create_default(self):
params = {
'name': 'testinganewuser',
'email': 'testinganewuser@ckan.org',
'password': 'random',
}
res = self.app.post('/api/3/action/user_create', json.dumps(params))
res_dict = json.loads(res.body)
assert res_dict['success'] is True


class TestCreateUser(PylonsTestCase):
'''Tests for the creating user when anon_create_user is false.
'''
@classmethod
def setup_class(cls):
cls._original_config = config.copy()
config['ckan.auth.anon_create_user'] = False
wsgiapp = ckan.config.middleware.make_app(config['global_conf'],
**config)
cls.app = paste.fixture.TestApp(wsgiapp)
PylonsTestCase.setup_class()

@classmethod
def teardown_class(cls):
config.clear()
config.update(cls._original_config)
PylonsTestCase.teardown_class()
model.repo.rebuild_db()

def test_user_create_disabled(self):
params = {
'name': 'testinganewuser',
'email': 'testinganewuser@ckan.org',
'password': 'random',
}
res = self.app.post('/api/3/action/user_create', json.dumps(params),
expect_errors=True)
res_dict = res.json
assert res_dict['success'] is False


class TestUserActions(object):

@classmethod
def setup_class(cls):
CreateTestData.create()
Expand Down
34 changes: 0 additions & 34 deletions ckan/tests/functional/test_user.py
Expand Up @@ -985,37 +985,3 @@ def test_perform_reset_user_password_link_user_incorrect(self):
id='randomness', # i.e. incorrect
key='randomness')
res = self.app.get(offset, status=404)

# TODO: We will use the old templates in tests. These tests need to be
# enabled back when we start using the jinja2 templates.
#def test_home_page_register_button_exists(self):
#res = self.app.get(url_for(controller='home', action='index', id=None))
#assert 'Register' in res


#class TestCreateUser(PylonsTestCase):
#'''Tests for the ckan.activity_streams_email_notifications config setting.

#'''
#@classmethod
#def setup_class(cls):
#cls._original_config = config.copy()
#config['ckan.auth.create_user_via_web'] = False
#wsgiapp = ckan.config.middleware.make_app(config['global_conf'],
#**config)
#cls.app = paste.fixture.TestApp(wsgiapp)
#PylonsTestCase.setup_class()

#@classmethod
#def teardown_class(cls):
#config.clear()
#config.update(cls._original_config)
#PylonsTestCase.teardown_class()
#model.repo.rebuild_db()

#def test_home_page_register_button_hidden(self):
#res = self.app.get(url_for(controller='home', action='index', id=None))
## TODO: Test disabled as the config change isn't working
#from nose import SkipTest
#raise SkipTest
#assert 'Register' not in res

0 comments on commit 56a87cc

Please sign in to comment.