Skip to content

Commit

Permalink
Merge pull request #2491 from ckan/2491-user-edit-tests
Browse files Browse the repository at this point in the history
user edit controller tests
  • Loading branch information
joetsoi committed Jul 6, 2015
2 parents 6570cc7 + 3e28a55 commit 8e343eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
35 changes: 35 additions & 0 deletions ckan/tests/controllers/test_user.py
Expand Up @@ -57,6 +57,41 @@ def test_other_datasets_dont_show_up_on_user_dashboard(self):

assert_false(dataset_title in response)


class TestUserEdit(helpers.FunctionalTestBase):

def test_user_edit_no_user(self):
app = self._get_test_app()
response = app.get(
url_for(controller='user', action='edit', id=None),
status=400
)
assert_true('No user specified' in response)

def test_user_edit_unknown_user(self):
'''Attempt to read edit user for an unknown user redirects to login
page.'''
app = self._get_test_app()
response = app.get(
url_for(controller='user', action='edit', id='unknown_person'),
status=302 # redirect to login page
)
response = response.follow()
assert_true('Login' in response)

def test_user_edit_not_logged_in(self):
'''Attempt to read edit user for an existing, not-logged in user
redirects to login page.'''
app = self._get_test_app()
user = factories.User()
username = user['name']
response = app.get(
url_for(controller='user', action='edit', id=username),
status=302
)
response = response.follow()
assert_true('Login' in response)

def test_edit_user(self):
user = factories.User(password='pass')
app = self._get_test_app()
Expand Down
26 changes: 0 additions & 26 deletions ckan/tests/legacy/functional/test_user.py
Expand Up @@ -101,32 +101,6 @@ def test_apikey(self):
res = self.app.get(offset, extra_environ={'REMOTE_USER': 'okfntest'})
assert user.apikey in res, res


def test_user_edit_no_user(self):
offset = url_for(controller='user', action='edit', id=None)
res = self.app.get(offset, status=400)
assert 'No user specified' in res, res

def test_user_edit_unknown_user(self):
offset = url_for(controller='user', action='edit', id='unknown_person')
res = self.app.get(offset, status=302) # redirect to login page
res = res.follow()
assert 'Login' in res, res

def test_user_edit_not_logged_in(self):
# create user
username = 'testedit'
about = u'Test About'
user = model.User.by_name(unicode(username))
if not user:
model.Session.add(model.User(name=unicode(username), about=about,
password='letmein'))
model.repo.commit_and_remove()
user = model.User.by_name(unicode(username))

offset = url_for(controller='user', action='edit', id=username)
res = self.app.get(offset, status=302)

def test_perform_reset_user_password_link_key_incorrect(self):
CreateTestData.create_user(name='jack', password='test1')
# Make up a key - i.e. trying to hack this
Expand Down

0 comments on commit 8e343eb

Please sign in to comment.