-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from k0t3n/feature/min-max-amounts
Feature/min max amounts
- Loading branch information
Showing
7 changed files
with
119 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
API_ROOT_URL = 'https://api.changelly.com' | ||
|
||
INVALID_AMOUNT_ERROR_CODE = -32600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from changelly_api import ChangellyAPI | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def api(): | ||
return ChangellyAPI('key', 'secret') | ||
|
||
|
||
@pytest.fixture() | ||
def get_fix_rate_for_amount_data(): | ||
return { | ||
'response': { | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": { | ||
"id": "test", | ||
"from": "btc", | ||
"to": "eth", | ||
"result": "48.520938768637152700759353642", | ||
"amountFrom": "1", | ||
"amountTo": "48.520938768637152700" | ||
} | ||
}, | ||
'request': { | ||
'from': 'btc', | ||
'to': 'eth', | ||
'amountFrom': 1, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
import requests_mock | ||
|
||
from changelly_api.conf import API_ROOT_URL | ||
from changelly_api.exceptions import AmountGreaterThanMaximum, AmountLessThanMinimum | ||
|
||
|
||
@requests_mock.Mocker(kw='requests_mock') | ||
def test(api, get_fix_rate_for_amount_data, **kwargs): | ||
r_mock = kwargs['requests_mock'] | ||
r_mock.post(API_ROOT_URL, json=get_fix_rate_for_amount_data['response']) | ||
response = api.get_fix_rate_for_amount(get_fix_rate_for_amount_data['request']) | ||
|
||
assert response == get_fix_rate_for_amount_data['response']['result'] | ||
|
||
|
||
@requests_mock.Mocker(kw='requests_mock') | ||
def test_invalid_minimum_amount(api, get_fix_rate_for_amount_data, **kwargs): | ||
minimum_amount = 10 | ||
r_mock = kwargs['requests_mock'] | ||
data = { | ||
'error': { | ||
'code': -32600, | ||
'message': f'invalid amount: minimal amount is {minimum_amount}' | ||
} | ||
} | ||
r_mock.post(API_ROOT_URL, json=data) | ||
|
||
with pytest.raises(AmountLessThanMinimum) as error: | ||
api.get_fix_rate_for_amount(get_fix_rate_for_amount_data['request']) | ||
|
||
assert error.value.threshold_value == minimum_amount | ||
|
||
|
||
@requests_mock.Mocker(kw='requests_mock') | ||
def test_invalid_maximum_amount(api, get_fix_rate_for_amount_data, **kwargs): | ||
maximum_amount = 10 | ||
r_mock = kwargs['requests_mock'] | ||
response = { | ||
'error': { | ||
'code': -32600, | ||
'message': f'invalid amount: maximal amount is {maximum_amount}' | ||
} | ||
} | ||
r_mock.post(API_ROOT_URL, json=response) | ||
|
||
with pytest.raises(AmountGreaterThanMaximum) as error: | ||
api.get_fix_rate_for_amount(get_fix_rate_for_amount_data['request']) | ||
|
||
assert error.value.threshold_value == maximum_amount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pytest-cov | ||
codecov | ||
pytest | ||
pytest | ||
mock | ||
requests_mock |