Skip to content

Commit

Permalink
adding more tests for cryptopanic
Browse files Browse the repository at this point in the history
  • Loading branch information
lockefox committed Feb 20, 2018
1 parent 9a821b5 commit 68673c3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion prosper/datareader/cryptopanic/posts.py
Expand Up @@ -44,7 +44,7 @@ def fetch_posts(
params['currencies'] = ticker
if filters:
assert filters in CRYPTOPANIC_FILTERS
params['filter'] = filters
params['filter'] = filters.lower()
if public:
params['public'] = True
if not public and following:
Expand Down
43 changes: 43 additions & 0 deletions tests/test_cryptopanic.py
@@ -1,5 +1,6 @@
"""test_cryptopanic.py: validate behavior for datareader.cryptopanic"""
from os import path
import time

import pytest
import helpers
Expand All @@ -16,9 +17,51 @@ def test_fetch_posts_happypath(self):
"""validate expected behavior for cryptopanic.posts.fetch_posts()"""
if not CRYPTOPANIC_AUTH:
pytest.xfail('Lacking `auth_token` for cryptopanic')

time.sleep(0.5) # cryptopanic API is heavily rate-limited
articles = cryptopanic.posts.fetch_posts(
auth_token=CRYPTOPANIC_AUTH,
ticker=self.coin_ticker
)

helpers.validate_schema(articles, 'coins/cryptopanic_posts.schema')

def test_fetch_posts_complex(self):
"""hit all the things"""
if not CRYPTOPANIC_AUTH:
pytest.xfail('Lacking `auth_token` for cryptopanic')

time.sleep(0.5) # cryptopanic API is heavily rate-limited
articles = cryptopanic.posts.fetch_posts(
auth_token=CRYPTOPANIC_AUTH,
ticker=self.multi_ticker,
filters='hot',
public=False,
following=True
)

def test_fetch_posts_bad_filter(self):
"""validate error case for bad filter"""
if not CRYPTOPANIC_AUTH:
pytest.xfail('Lacking `auth_token` for cryptopanic')

time.sleep(0.5) # cryptopanic API is heavily rate-limited
with pytest.raises(AssertionError):
articles = cryptopanic.posts.fetch_posts(
auth_token=CRYPTOPANIC_AUTH,
ticker=self.coin_ticker,
filters='butts'
)

def test_fetch_posts_pagelimit(self):
"""validate pagination limit"""
if not CRYPTOPANIC_AUTH:
pytest.xfail('Lacking `auth_token` for cryptopanic')

time.sleep(0.5) # cryptopanic API is heavily rate-limited
with pytest.warns(exceptions.PaginationWarning):
articles = cryptopanic.posts.fetch_posts(
auth_token=CRYPTOPANIC_AUTH,
ticker=self.coin_ticker,
article_limit=50
)

0 comments on commit 68673c3

Please sign in to comment.