Skip to content

Commit

Permalink
[#3005] Add tests for group following on delete cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Oct 24, 2012
1 parent ee9eb3d commit e55ca20
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions ckan/tests/functional/api/test_follow.py
Expand Up @@ -1077,13 +1077,20 @@ def setup_class(self):
self.testsysadmin['apikey'], self.warandpeace['id'],
self.warandpeace['id'])

follow_group(self.app, self.testsysadmin['id'],
self.testsysadmin['apikey'], self.davids_group['id'],
self.davids_group['id'])

session = ckan.model.Session()
session.delete(ckan.model.User.get('joeadmin'))
session.commit()

session.delete(ckan.model.Package.get('warandpeace'))
session.commit()

session.delete(ckan.model.Group.get('david'))
session.commit()

@classmethod
def teardown_class(self):
ckan.model.repo.rebuild_db()
Expand All @@ -1108,6 +1115,13 @@ def test_01_on_delete_cascade_api(self):
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to get david's follower list.
params = json.dumps({'id': 'david'})
response = self.app.post('/api/action/group_follower_list',
params=params, status=409).json
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to get joeadmin's follower count.
params = json.dumps({'id': 'joeadmin'})
response = self.app.post('/api/action/user_follower_count',
Expand All @@ -1122,6 +1136,13 @@ def test_01_on_delete_cascade_api(self):
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to get david's follower count.
params = json.dumps({'id': 'david'})
response = self.app.post('/api/action/group_follower_count',
params=params, status=409).json
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to get am_following for joeadmin.
params = json.dumps({'id': 'joeadmin'})
extra_environ = {'Authorization': str(self.testsysadmin['apikey'])}
Expand All @@ -1138,6 +1159,14 @@ def test_01_on_delete_cascade_api(self):
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to get am_following for david.
params = json.dumps({'id': 'david'})
extra_environ = {'Authorization': str(self.testsysadmin['apikey'])}
response = self.app.post('/api/action/am_following_group',
params=params, extra_environ=extra_environ, status=409).json
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to unfollow joeadmin.
params = json.dumps({'id': 'joeadmin'})
extra_environ = {'Authorization': str(self.tester['apikey'])}
Expand All @@ -1154,6 +1183,14 @@ def test_01_on_delete_cascade_api(self):
assert response['success'] is False
assert response['error']['id'] == ['Not found: Dataset']

# It should no longer be possible to unfollow david.
params = json.dumps({'id': 'david'})
extra_environ = {'Authorization': str(self.testsysadmin['apikey'])}
response = self.app.post('/api/action/unfollow_group',
params=params, extra_environ=extra_environ, status=409).json
assert response['success'] is False
assert response['error']['id'] == ['Not found: Group']

# It should no longer be possible to follow joeadmin.
params = json.dumps({'id': 'joeadmin'})
extra_environ = {'Authorization': str(self.annafan['apikey'])}
Expand All @@ -1170,6 +1207,14 @@ def test_01_on_delete_cascade_api(self):
assert response['success'] is False
assert response['error'].has_key('id')

# It should no longer be possible to follow david.
params = json.dumps({'id': 'david'})
extra_environ = {'Authorization': str(self.annafan['apikey'])}
response = self.app.post('/api/action/follow_group',
params=params, extra_environ=extra_environ, status=409).json
assert response['success'] is False
assert response['error'].has_key('id')

# Users who joeadmin was following should no longer have him in their
# follower list.
params = json.dumps({'id': self.testsysadmin['id']})
Expand All @@ -1194,7 +1239,7 @@ def test_02_on_delete_cascade_db(self):

# After the previous test above there should be no rows with joeadmin's
# id in the UserFollowingUser or UserFollowingDataset tables.
from ckan.model import UserFollowingUser, UserFollowingDataset
from ckan.model import UserFollowingUser, UserFollowingDataset, UserFollowingGroup
session = ckan.model.Session()

query = session.query(UserFollowingUser)
Expand All @@ -1209,11 +1254,16 @@ def test_02_on_delete_cascade_db(self):
query = query.filter(UserFollowingUser.follower_id==self.joeadmin['id'])
assert query.count() == 0

# There should be no rows with warandpeace's id either.
query = session.query(UserFollowingUser)
query = query.filter(UserFollowingUser.object_id==self.warandpeace['id'])
# There should be no rows with warandpeace's id in the
# UserFollowingDataset table.
query = session.query(UserFollowingDataset)
query = query.filter(
UserFollowingDataset.object_id==self.warandpeace['id'])
assert query.count() == 0

query = session.query(UserFollowingDataset)
query = query.filter(UserFollowingUser.object_id==self.warandpeace['id'])
# There should be no rows with david's id in the
# UserFollowingGroup table.
query = session.query(UserFollowingGroup)
query = query.filter(
UserFollowingGroup.object_id==self.davids_group['id'])
assert query.count() == 0

0 comments on commit e55ca20

Please sign in to comment.