Skip to content

Commit

Permalink
Modernize tests from ckan/tests/legacy/functional/test_activity.py
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Jan 20, 2019
1 parent 0463be5 commit fef5cea
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 252 deletions.
165 changes: 165 additions & 0 deletions ckan/tests/controllers/test_user.py
Expand Up @@ -689,3 +689,168 @@ def test_user_page_sysadmin_user(self):
user_list = search_response_html.select('ul.user-list li')
assert_equal(len(user_list), 1)
assert_equal(user_list[0].text.strip(), 'User One')


class TestActivity(helpers.FunctionalTestBase):
def test_simple(self):
'''Checking the template shows the activity stream.'''
app = self._get_test_app()
user = factories.User()

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('Mr. Test User', response)
assert_in('signed up', response)

def test_create_user(self):
app = self._get_test_app()
user = factories.User()

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('signed up', response)

def _clear_activities(self):
model.Session.query(model.ActivityDetail).delete()
model.Session.query(model.Activity).delete()
model.Session.flush()

def test_change_user(self):
app = self._get_test_app()
user = factories.User()
self._clear_activities()
user['fullname'] = 'Mr. Changed Name'
helpers.call_action(
'user_update', context={'user': user['name']}, **user)

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('<a href="/user/{}">Mr. Changed Name'.format(user['name']),
response)
assert_in('updated their profile', response)

def test_create_dataset(self):
app = self._get_test_app()
user = factories.User()
self._clear_activities()
dataset = factories.Dataset(user=user)

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('created the dataset', response)
assert_in('<a href="/dataset/{}">Test Dataset'.format(dataset['name']),
response)

def test_change_dataset(self):
app = self._get_test_app()
user = factories.User()
dataset = factories.Dataset(user=user)
self._clear_activities()
dataset['title'] = 'Dataset with changed title'
helpers.call_action(
'package_update', context={'user': user['name']}, **dataset)

url = url_for('user.activity',
id=user['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/{}">Dataset with changed title'
.format(dataset['name']),
response)

def test_delete_dataset(self):
app = self._get_test_app()
user = factories.User()
dataset = factories.Dataset(user=user)
self._clear_activities()
helpers.call_action(
'package_delete', context={'user': user['name']}, **dataset)

url = url_for('user.activity',
id=user['id'])
env = {'REMOTE_USER': user['name'].encode('ascii')}
response = app.get(url, extra_environ=env)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('deleted the dataset', response)
assert_in('<a href="/dataset/{}">Test Dataset'
.format(dataset['name']),
response)

def test_create_group(self):
app = self._get_test_app()
user = factories.User()
group = factories.Group(user=user)

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('created the group', response)
assert_in('<a href="/group/{}">Test Group'.format(
group['name']), response)

def test_change_group(self):
app = self._get_test_app()
user = factories.User()
group = factories.Group(user=user)
self._clear_activities()
group['title'] = 'Group with changed title'
helpers.call_action(
'group_update', context={'user': user['name']}, **group)

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('updated the group', response)
assert_in('<a href="/group/{}">Group with changed title'
.format(group['name']), response)

def test_delete_group_using_group_delete(self):
app = self._get_test_app()
user = factories.User()
group = factories.Group(user=user)
self._clear_activities()
helpers.call_action(
'group_delete', context={'user': user['name']}, **group)

url = url_for('user.activity',
id=user['id'])
response = app.get(url)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('deleted the group', response)
assert_in('<a href="/group/{}">Test Group'
.format(group['name']), response)

def test_delete_group_by_updating_state(self):
app = self._get_test_app()
user = factories.User()
group = factories.Group(user=user)
self._clear_activities()
group['state'] = 'deleted'
helpers.call_action(
'group_update', context={'user': user['name']}, **group)

url = url_for('group.activity',
id=group['id'])
env = {'REMOTE_USER': user['name'].encode('ascii')}
response = app.get(url, extra_environ=env)
assert_in('<a href="/user/{}">Mr. Test User'.format(user['name']),
response)
assert_in('deleted the group', response)
assert_in('<a href="/group/{}">Test Group'
.format(group['name']), response)

0 comments on commit fef5cea

Please sign in to comment.