Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added mock test skeleton for buy, sell and withdraw functions #95

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions bittrex/test/bittrex_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import os
from bittrex.bittrex import Bittrex, API_V2_0, API_V1_1, BUY_ORDERBOOK, TICKINTERVAL_ONEMIN

try:
from unittest import mock
except ImportError:
import mock

IS_CI_ENV = True if 'IN_CI' in os.environ else False


Expand All @@ -18,6 +23,48 @@ def test_auth_basic_failures(unit_test, result, test_type):
unit_test.assertIsNone(result['result'], "{0:s} failed response result not None".format(test_type))


def mocked_buy_sell_withdraw_query(protection=None, path_dict=None, options=None):
return {"success": "true", "message": "", "result": {"uuid": "e606d53c-8d70-11e3-94b5-425861b86ab6"}}


def mocked_cancel_query(protection=None, path_dict=None, options=None):
return {"success": "true", "message": "", "result": "null"}


def mocked_get_order_query(protection=None, path_dict=None, options=None):
return json.loads(
'{\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe import a multiline string from somewhere else or put it in a file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will change it to make the test file more readable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for in the event the format changes we can just paste in what Bittrex gives us in the future.

"success" : "true", \
"message" : "", \
"result" : { \
"AccountId" : null, \
"OrderUuid" : "0cb4c4e4-bdc7-4e13-8c13-430e587d2cc1", \
"Exchange" : "BTC-SHLD", \
"Type" : "LIMIT_BUY", \
"Quantity" : 1000.00000000, \
"QuantityRemaining" : 1000.00000000, \
"Limit" : 0.00000001, \
"Reserved" : 0.00001000, \
"ReserveRemaining" : 0.00001000, \
"CommissionReserved" : 0.00000002, \
"CommissionReserveRemaining" : 0.00000002,\
"CommissionPaid" : 0.00000000, \
"Price" : 0.00000000, \
"PricePerUnit" : null, \
"Opened" : "2014-07-13T07:45:46.27", \
"Closed" : null, \
"IsOpen" : true, \
"Sentinel" : "6c454604-22e2-4fb4-892e-179eede20972", \
"CancelInitiated" : false, \
"ImmediateOrCancel" : false, \
"IsConditional" : false, \
"Condition" : "NONE", \
"ConditionTarget" : null \
} \
}'
)


class TestBittrexV11PublicAPI(unittest.TestCase):
"""
Integration tests for the Bittrex public API.
Expand Down Expand Up @@ -118,6 +165,8 @@ def test_get_markets(self):
def test_get_currencies(self):
actual = self.bittrex.get_currencies()
test_basic_response(self, actual, "get_currencies")
self.assertTrue(isinstance(actual['result'], list), "result is not a list")
self.assertTrue('BTC' in str(actual['result']), 'BTC not in result list')

def test_get_ticker(self):
self.assertRaisesRegexp(Exception, 'method call not available', self.bittrex.get_ticker,
Expand Down Expand Up @@ -271,6 +320,32 @@ def test_get_pending_deposits(self):
def test_generate_deposit_address(self):
self.assertRaisesRegexp(Exception, 'method call not available', self.bittrex.generate_deposit_address, currency='BTC')

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_buy_sell_withdraw_query)
def test_buy_limit(self, mock_buy):
actual = self.bittrex.buy_limit(market='BTC-LTC', quantity=0.00015, rate=0.00865)
test_basic_response(self, actual, "test_buy_limit")

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_buy_sell_withdraw_query)
def test_sell_limit(self, mock_sell):
actual = self.bittrex.sell_limit(market='BTC-LTC', quantity=0.00015, rate=0.00865)
test_basic_response(self, actual, "test_sell_limit")

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_cancel_query)
def test_cancel(self, mock_cancel):
actual = self.bittrex.cancel(uuid='e606d53c-8d70-11e3-94b5-425861b86ab6')
test_basic_response(self, actual, "test_cancel")

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_buy_sell_withdraw_query)
def test_withdrawl(self, mock_withdraw):
actual = self.bittrex.withdraw(currency='BTC', quantity=0.0001, address='3QtaHWctjScd17uewd5LDpjKfmoAeyo9Lj')
test_basic_response(self, actual, "test_withdrawl")

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_get_order_query)
def test_get_order(self, mock_order):
actual = self.bittrex.get_order(uuid='e606d53c-8d70-11e3-94b5-425861b86ab6')
test_basic_response(self, actual, "test_get_order")
self.assertIsInstance(actual['result'], dict, "result is not a dict")


@unittest.skipIf(IS_CI_ENV, 'no account secrets uploaded in CI envieonment, TODO')
class TestBittrexV20AccountAPI(unittest.TestCase):
Expand Down Expand Up @@ -393,6 +468,28 @@ def test_generate_deposit_address(self):
test_basic_response(self, actual, "generate_deposit_address")
self.assertIsInstance(actual['result'], list, "result is not a list")

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_buy_sell_withdraw_query)
def test_trade_sell(self, mock_trade_sell):
actual = self.bittrex.trade_sell(market='BTC-LTC',
order_type='MARKET',
quantity=0.0001,
rate=0.00865,
time_in_effect='IMMEDIATE_OR_CANCEL',
condition_type='LESS_THAN',
target=0.00876)
test_basic_response(self, actual, "test_trade_sell")

@mock.patch('bittrex.Bittrex._api_query', side_effect=mocked_buy_sell_withdraw_query)
def test_trade_buy(self, mock_trade_buy):
actual = self.bittrex.trade_buy(market='BTC-LTC',
order_type='MARKET',
quantity=0.00015,
rate=0.00899,
time_in_effect='IMMEDIATE_OR_CANCEL',
condition_type='MORE_THAN',
target=0.00899)
test_basic_response(self, actual, "test_trade_buy")


if __name__ == '__main__':
unittest.main()