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

Conversation

timechild
Copy link

This adds mock tests for methods that are harder to test: buy_limit, sell_limit, cancel, withdraw, get_order for API v1.1 and trade_sell and trade_buy for API v2.0.

Tests are using Python mock (Standard library 3.3+) module to replace _api_query method and return a JSON response according to Bittrex docs.
At the moment there is only a basic assertion testing, but this can be expanded in the future.

Few other minor assertion test were added as well.

This PR increases test coverage from 74% to 78%.

@ericsomdahl
Copy link
Owner

I have a love/hate relationship with mocks. This repo exemplifies 2 cases where mocks can be really deceptive: dynamic languages and external integrations.

I'm ok with mocking responses for the 1.1 API since it is stable. The 2.0 API is a moving target though and has changed multiple times in the last few months. Mocking those responses can lead us into a false sense of security about whether our code is working or not.

I suppose since the general shape of the responses (from even the 2.0 API) is stable, shallow testing against a canned response is fine - i.e. whether a list of results is present, success is true or false, etc. Let's just not take it any further then that 😄

Since your commit message is WIP I suppose you don't want this merged yet?

@timechild
Copy link
Author

I labelled it WIP as I wanted to add more detailed mock tests (parameter check etc), but if you want to leave it shallow then I would consider it done. I also wanted to hear your thoughts before going more deeply into the test suite.


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.

@timechild
Copy link
Author

I've moved the Json to separate file.
Travis tests are failing because of API v2.0 calls failing for:

  • get_markets
  • get_market_history
  • get_openorders
  • list_markets_by_currency

@ericsomdahl
Copy link
Owner

ericsomdahl commented Dec 13, 2017 via email

@ericsomdahl
Copy link
Owner

@timechild PR #104 has been merged to master -- it removed the broken 2.0 endpoints from the API altogether. It may be easiest to rebase this against master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants