Skip to content

Commit

Permalink
Fix tests after changing cache key code
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuykendall committed Jul 29, 2017
1 parent 2898c90 commit 9644327
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -50,7 +50,7 @@ marvelous - Marvel API wrapper for python 3
Contributing
------------

- To run the test suite, run `python -m nose` in the `tests` folder
- To run the test suite, run `python -m nose` in this folder
- When running a new test for the first time, set the environment variables
``PUBLIC_KEY`` and ``PRIVATE_KEY`` to any Marel API keys. The result will be
stored in the `tests/testing_mock.sqlite` database without your keys.
4 changes: 3 additions & 1 deletion marvelous/session.py
Expand Up @@ -21,6 +21,8 @@ def call(self, endpoint, params=None):

# Generate part of cache key before hash, apikey and timestamp added
cache_params = urllib.parse.urlencode(params)
if cache_params == '?':
cache_params = ''

now_string = datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S')
auth_hash = hashlib.md5()
Expand All @@ -33,7 +35,7 @@ def call(self, endpoint, params=None):
params['ts'] = now_string

url = self.api_url.format('/'.join([str(e) for e in endpoint]))
cache_key = '{url}?{cache_params}'.format(
cache_key = '{url}{cache_params}'.format(
url=url, cache_params=cache_params)

if self.cache:
Expand Down
14 changes: 10 additions & 4 deletions tests/cache_test.py
Expand Up @@ -54,11 +54,17 @@ def test_sql_store(self):

self.assertTrue(fresh_cache.get(url) is None)

with requests_mock.Mocker() as r:
r.get(url, text=json.dumps(test_cache.get(url)))
m.series(466)
try:
with requests_mock.Mocker() as r:
r.get(url, text=json.dumps(test_cache.get(url)))
m.series(466)

self.assertTrue(fresh_cache.get(url) is not None)
self.assertTrue(fresh_cache.get(url) is not None)
except TypeError:
print(
'This test will fail after cache db deleted.\n'
'It should pass if you now re-run the test suite without deleting the database.')
assert(False)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/series_test.py
Expand Up @@ -18,7 +18,7 @@ def test_known_series(self):
self.assertTrue(usms.title == "Ultimate Spider-Man (2000 - 2009)")
self.assertTrue(usms.id == 466)
comics = usms.comics()
self.assertTrue(comics[0].id == 23931)
self.assertTrue(23931 in [c.id for c in comics])

self.assertTrue(len(comics[:5]) == 5)
self.assertTrue(len(comics) == len([x for x in comics if x.id > 3]))
Expand Down
Binary file modified tests/testing_mock.sqlite
Binary file not shown.

0 comments on commit 9644327

Please sign in to comment.