Open icook opened 4 years ago
A few more things.
python3.7 -m pip install --user pytest-cov
python3.7 -m pytest --cov-report html --cov-report term --cov=qtrade_client tests/ --cov-branch
google-chrome htmlcov/index.html
Will let you see the test coverage report. Looking over that I spot a few things that would be good to cover:
from qtrade_client.api import QtradeAPI
# String is of the format "[key_id]:[key]"
hmac_keypair = "1:1111111111111111111111111111111111111111111111111111111111111111"
client = QtradeAPI("https://api1.qtex.dev", key=hmac_keypair)
client.orders(open=False)
And inject a print statement in the HMAC code to extract your desired assertion. Specifically we're trying to exercise line 41.
assert_called_with
usage that has been added in various places, and this would make good sense to be added to the order tests since that will actually test the logic of the order wrapper.
Tests could use some improvement. In no specific order, some issues I see:
api._markets_map
is set to the exact same value twice, and they're copy and pasted. Just define them as a nicely named global and set them inside the test as needed. If you need specific values to test particular functionality, setapi._markets_map
to the reusable fixture usingdeep_copy
, and then modify it explicitly as needed as I did on 1195.test_refresh_common
could be made much clearer by setting up the mock return value, then referencing it in your assertions. For instance,assert api.markets["GRIN_BTC"] == req_return['markets'][0]
. This makes your intent much clearer, and the test more flexible and less cluttered. Similar patterns could benefit several of the functions.req_1
,req_2
pattern intest_orders
could be improved by observing thatMagicMock
doesn't require a function as the side effect, and will accept a return value. If each mockapi._req
is setup for a single test, then there is no need to assert anything about call parameters, so I would do something like:In addition, your assertions should be specific instead of general. It's okay to have one test that asserts the entire return value, but other tests should make assertions only about the specific logic that they intend to test, not all logic.
@Henelik