Skip to content

Commit

Permalink
[#2304] Tests for starting to follow a user or dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Apr 28, 2012
1 parent 75f866d commit 162fcdf
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions ckan/tests/functional/api/test_follow.py
Expand Up @@ -20,6 +20,8 @@ def setup_class(self):
self.testsysadmin = ckan.model.User.get('testsysadmin')
self.annafan = ckan.model.User.get('annafan')
self.russianfan = ckan.model.User.get('russianfan')
self.tester = ckan.model.User.get('tester')
self.tester = ckan.model.User.get('joeadmin')
self.warandpeace = ckan.model.Package.get('warandpeace')
self.annakarenina = ckan.model.Package.get('annakarenina')
self.app = paste.fixture.TestApp(pylons.test.pylonsapp)
Expand All @@ -28,21 +30,22 @@ def setup_class(self):
def teardown_class(self):
ckan.model.repo.rebuild_db()

def _user_follow_user(self, follower_id, follower_api_key, object_id):
'''Test a user starting to follow another user via the API.'''
def _start_following(self, follower_id, follower_api_key, object_id,
object_type):
'''Test a user starting to follow an object via the API.'''

# Record the user's number of followers before.
# Record the object's number of followers before.
params = json.dumps({'id': object_id})
response = self.app.post('/api/action/follower_count',
params=params).json
assert response['success'] is True
count_before = response['result']

# Make one user start following another user.
# Make the user start following the object.
before = datetime.datetime.now()
params = json.dumps({
'object_id': object_id,
'object_type': 'user',
'object_type': object_type,
})
extra_environ = {
'Authorization': str(follower_api_key)
Expand All @@ -56,11 +59,11 @@ def _user_follow_user(self, follower_id, follower_api_key, object_id):
assert follower['follower_id'] == follower_id
assert follower['follower_type'] == 'user'
assert follower['object_id'] == object_id
assert follower['object_type'] == 'user'
assert follower['object_type'] == object_type
timestamp = datetime_from_string(follower['datetime'])
assert (timestamp >= before and timestamp <= after), str(timestamp)

# Check that the follower appears in the user's list of followers.
# Check that the user appears in the object's list of followers.
params = json.dumps({'id': object_id})
response = self.app.post('/api/action/follower_list',
params=params).json
Expand All @@ -71,24 +74,28 @@ def _user_follow_user(self, follower_id, follower_api_key, object_id):
follower = followers[0]
assert follower['id'] == follower_id

# Check that the user's follower count has increased by 1.
# Check that the object's follower count has increased by 1.
params = json.dumps({'id': object_id})
response = self.app.post('/api/action/follower_count',
params=params).json
assert response['success'] is True
assert response['result'] == count_before + 1

def test_user_follow_user(self):
self._user_follow_user(self.annafan.id, self.annafan.apikey,
self.russianfan.id)
self._start_following(self.annafan.id, self.annafan.apikey,
self.russianfan.id, 'user')

def test_user_follow_user_by_name(self):
self._user_follow_user(self.annafan.id, self.annafan.apikey,
self.russianfan.name)
self._start_following(self.annafan.id, self.annafan.apikey,
self.testsysadmin.name, 'user')

def test_user_follow_dataset(self):
'''Test a user following a dataset via the API.'''
raise NotImplementedError
self._start_following(self.annafan.id, self.annafan.apikey,
self.warandpeace.id, 'dataset')

def test_user_follow_dataset_by_name(self):
self._start_following(self.annafan.id, self.annafan.apikey,
self.annakarenina.name, 'dataset')

def test_follower_id_bad(self):
raise NotImplementedError
Expand Down

0 comments on commit 162fcdf

Please sign in to comment.