Skip to content

Commit

Permalink
[#2491] Move/refactor user edit tests from legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
brew committed Jun 23, 2015
1 parent f077267 commit 3e28a55
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 @@ -46,6 +46,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()
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 3e28a55

Please sign in to comment.