Coverage for bookie.tests.test_api : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Test that we're meeting delicious API specifications"""
"""Test the Bookie API"""
global API_KEY "SELECT api_key FROM users WHERE username = 'admin'").fetchone()
"""We need to empty the bmarks table on each run"""
"""Return the basics for a good add bookmark request"""
# the main bookmark, added second to prove popular will sort correctly 'url': u'http://google.com', 'description': u'This is my google desc', 'extended': u'And some extended notes about it in full form', 'tags': u'python search', 'api_key': API_KEY, 'username': 'admin', 'inserted_by': 'chrome_ext', }
# if we want to test the readable fulltext side we want to make sure we # pass content into the new bookmark
# req_params = urllib.urlencode(prms) '/api/v1/admin/bmark?', content_type='application/json', params=json.dumps(prms), )
'url': u'http://bmark.us', 'description': u'Bookie', 'extended': u'Exteded notes', 'tags': u'bookmarks', 'api_key': API_KEY, 'username': 'admin', 'inserted_by': 'chrome_ext', }
# if we want to test the readable fulltext side we want to make # sure we pass content into the new bookmark
# req_params = urllib.urlencode(prms) '/api/v1/admin/bmark?', content_type='application/json', params=json.dumps(prms) )
# Run the celery task for indexing this bookmark.
"""We should be able to add a new bookmark to the system""" # we need to know what the current admin's api key is so we can try to # add "SELECT api_key FROM users WHERE username = 'admin'").fetchone()
'url': u'http://bmark.us', 'description': u'Bookie', 'extended': u'Extended notes', 'tags': u'bookmarks', 'api_key': key, }
params=test_bmark, status=200)
"Should have a location result: " + res.body) "Should have Bookie in description: " + res.body)
"""Test that we can get a bookmark and it's details""" GOOGLE_HASH, API_KEY), status=200)
# make sure we can decode the body "The hash_id should match: " + str(bmark[u'hash_id']))
"We should have a list of tags in the bmark returned")
"Tag should be either python or search:" + str(bmark[u'tags'][0][u'name']))
"We should not have readable content")
"tag_str should be populated: " + str(dict(bmark)))
# to get readble content we need to pass the flash with_content '/api/v1/admin/bmark/{0}?api_key={1}&with_content=true'.format( GOOGLE_HASH, API_KEY), status=200)
# make sure we can decode the body
"We should have readable content")
"We should have 'dude' in our content: " + bmark['readable']['content'])
"""Verify we get a failed response when wrong bookmark"""
# test that we get a 404 '/api/v1/admin/bmark/{0}?api_key={1}'.format(BMARKUS_HASH, API_KEY), status=404)
"""A delete call should remove the bookmark from the system"""
# now let's delete the google bookmark '/api/v1/admin/bmark/{0}?api_key={1}'.format( GOOGLE_HASH, API_KEY), status=200)
"Should have a message of done: " + res.body)
# we're going to cheat like mad, use the sync call to get the hash_ids # of bookmarks in the system and verify that only the bmark.us hash_id # is in the response body params={'api_key': API_KEY}, status=200)
"Should not have the google hash: " + res.body) "Should have the bmark.us hash: " + res.body)
"""Test that we can get list of bookmarks with details""" status=200)
# make sure we can decode the body "The hash_id should match: " + str(bmark[u'hash_id']))
"We should have a list of tags in the bmark returned")
"Tag should be either python or search:" + str(bmark[u'tags'][0][u'name']))
'/api/v1/admin/bmarks?with_content=true&api_key=' + API_KEY, status=200)
# make sure we can decode the body # @todo this is out because of the issue noted in the code. We'll # clean this up at some point. # bmark = json.loads(res.body)['bmarks'][0] # ok_('here dude' in bmark[u'readable']['content'], # "There should be content: " + str(bmark))
"""Test that we can get list of bookmarks with details""" status=200)
# make sure we can decode the body "The hash_id should match: " + str(bmark[u'hash_id']))
"We should have a list of tags in the bmark returned")
"Tag should be either python or search:" + str(bmark[u'tags'][0][u'name']))
'/api/v1/admin/bmarks?with_content=true&api_key=' + API_KEY, status=200)
# make sure we can decode the body # @todo this is out because of the issue noted in the code. We'll # clean this up at some point. # bmark = json.loads(res.body)['bmarks'][0] # ok_('here dude' in bmark[u'readable']['content'], # "There should be content: " + str(bmark))
"""Test that we can get the sync list from the server"""
# test that we only get one resultback params={'api_key': API_KEY}, status=200)
msg='Get status is 200, ' + res.status)
"The google hash id should be in the json: " + res.body) "The bmark.us hash id should be in the json: " + res.body)
"""Test that we can get list of bookmarks ordered by clicks"""
# make sure we can decode the body "We should have one result coming back: {0}".format(len(results)))
"The hash_id {0} should match: {1} ".format( str(GOOGLE_HASH), str(bmark[u'hash_id'])))
"The clicks field should be in there")
"""Test we can complete tags in the system
By default we should have tags for python, search, bookmarks
"""
'/api/v1/admin/tags/complete', params={ 'tag': 'py', 'api_key': API_KEY}, status=200)
"Should have python as a tag completion: " + res.body)
# we shouldn't get python as an option if we supply bookmarks as the # current tag. No bookmarks have both bookmarks & python as tags '/api/v1/admin/tags/complete', params={ 'tag': 'py', 'current': 'bookmarks', 'api_key': API_KEY }, status=200)
"Should not have python as a tag completion: " + res.body)
"""Test getting a user's account information""" status=200)
# make sure we can decode the body
"Should have a username of admin {0}".format(user))
'Should not have a field password {0}'.format(user)) 'Should not have a field password {0}'.format(user)) 'Should not have a field password {0}'.format(user))
"""Test updating a user's account information""" 'name': u'Test Admin' } str("/api/v1/admin/account?api_key=" + str(API_KEY)), content_type='application/json', params=json.dumps(params), status=200)
# make sure we can decode the body
"Should have a username of admin {0}".format(user)) "Should have a new name of Test Admin {0}".format(user))
"Should not have a field password {0}".format(user)) "Should not have a field password {0}".format(user)) "Should not have a field password {0}".format(user))
"""Fetching a user's api key""" status=200)
# make sure we can decode the body
"Should have a username of admin {0}".format(user)) "Should have an api key in there: {0}".format(user))
"""Change a user's password""" 'current_password': 'admin', 'new_password': 'not_testing' }
"/api/v1/admin/password?api_key=" + str(API_KEY), params=params, status=200)
# make sure we can decode the body
"Should have a username of admin {0}".format(user)) "Should have a message key in there: {0}".format(user))
'current_password': 'not_testing', 'new_password': 'admin' } "/api/v1/admin/password?api_key=" + str(API_KEY), params=params, status=200)
"""Change a user's password, in bad ways""" 'current_password': 'test', 'new_password': 'not_testing' }
"/api/v1/admin/password?api_key=" + str(API_KEY), params=params, status=403)
# make sure we can decode the body
"Should have a username of admin {0}".format(user)) "Should have a error key in there: {0}".format(user)) "Should have a error key in there: {0}".format(user))
"""We should be able to ping and make sure we auth'd and are ok""" status=200)
"Should success be true")
"""If you don't supply a username, you've failed the ping""" status=200)
"Success should be false")
"""If you don't supply a username, you've failed the ping""" status=200)
"Success should be false") |