Skip to content

Commit

Permalink
Merge pull request #2 from misdirectedpuffin/add-setup
Browse files Browse the repository at this point in the history
Add setup.py configuration
  • Loading branch information
uoshvis committed Mar 5, 2018
2 parents a631965 + efcfb9a commit ba6abbc
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 22 deletions.
4 changes: 1 addition & 3 deletions cryptowatch/api_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Module contining the interface to the API client."""
"""Module related to the client interface to cryptowat.ch API."""

from urllib.parse import quote_plus, urlencode

import requests

from cryptowatch.exceptions import (
CryptowatchAPIException,
CryptowatchResponseException
Expand Down
2 changes: 2 additions & 0 deletions cryptowatch/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CryptowatchAPIException(Exception):
"""Raised when the API response is not 2xx."""

def __init__(self, response):
super(CryptowatchAPIException, self).__init__()
self.status_code = response.status_code
self.reason = response.reason
self.response = response
Expand All @@ -17,6 +18,7 @@ class CryptowatchResponseException(Exception):
"""Raised for an invalid json response from the API"""

def __init__(self, message):
super(CryptowatchResponseException, self).__init__()
self.message = message

def __str__(self):
Expand Down
3 changes: 3 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest==3.4.1
requests-mock==1.4.0
pylint==1.8.2
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[aliases]
test=pytest

[tool:pytest]
addopts=--pylint --ignore=docs
36 changes: 36 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Package setup file."""
import os

from pip.req import parse_requirements
from setuptools import find_packages, setup


def get_version():
"""Return the current version."""
curr_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(curr_dir, 'version.txt')) as version_file:
return version_file.read().strip()


def get_requirements(file):
"""Return a list of requirements from a file."""
requirements = parse_requirements(file, session=False)
return [str(ir.req) for ir in requirements if not None]


setup(
name='cryptowatch',
version=get_version(),
description='Unofficial wrapper for for the Cryptowatch public Data API.',
author='uoshvis',
url='https://github.com/uoshvis/python-cryptowatch',
packages=find_packages(),
include_package_data=True,
install_requires=get_requirements('requirements.txt'),
setup_requires=[
'pytest-runner',
'pytest-pylint'
],
tests_require=get_requirements('requirements_test.txt'),
platforms='any'
)
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Test fixtures."""
import pytest


@pytest.fixture
def assets_keys(scope='module'):
"""Mock keys fixture."""
return ['result', 'allowance']
35 changes: 16 additions & 19 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from cryptowatch.api_client import Client
from cryptowatch.exceptions import CryptowatchAPIException, CryptowatchResponseException

"""Unit tests related to the api_client module."""
import pytest
import requests_mock

import requests_mock
from cryptowatch.api_client import Client
from cryptowatch.exceptions import (CryptowatchAPIException,
CryptowatchResponseException)

client = Client()


@pytest.fixture
def assets_keys(scope='module'):
return ['result', 'allowance']


def test_get_assets(assets_keys, symbol=None):
"""Test an API call to get assets' info """
response = client.get_assets(symbol)
Expand All @@ -27,13 +23,13 @@ def test_get_assets_symbol(assets_keys, symbol='btc'):
assert set(assets_keys).issubset(response.keys())


def test_api_exception(assets_keys, symbol='invalid'):
def test_api_exception(symbol='invalid'):
"""Test API response Exception"""
with pytest.raises(CryptowatchAPIException):
client.get_assets(symbol)


def test_invalid_json(assets_keys, symbol='btc'):
def test_invalid_json(symbol='btc'):
"""Test Invalid response Exception"""

with pytest.raises(CryptowatchResponseException):
Expand Down Expand Up @@ -72,23 +68,24 @@ def test_get_price(assets_keys):
assert set(assets_keys).issubset(response.keys())


def test_get_agg_prices(assets_keys):
response = client.get_aggregates('prices')
assert isinstance(response, dict)
assert set(assets_keys).issubset(response.keys())


def test_get_agg_summaries(assets_keys):
response = client.get_aggregates('summaries')
@pytest.mark.parametrize('route', [
'prices',
'summaries',
])
def test_routes(assets_keys, route):
"""It returns a dict and contains expected keys"""
response = client.get_aggregates(route)
assert isinstance(response, dict)
assert set(assets_keys).issubset(response.keys())


def test_get_agg_summaries_exception():
"""It raises ValueError with an incorrect argument."""
with pytest.raises(ValueError):
client.get_aggregates('test')


def test_get_agg_summaries_exception_no_arg():
"""It raises ValueError when no argument is passed."""
with pytest.raises(ValueError):
client.get_aggregates()
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1

0 comments on commit ba6abbc

Please sign in to comment.