def test_skip_app_id(self, http_client, mock_response): data = {"base": "USD"} mock_response(200, data) requestor = Requestor(None, client=http_client, skip_app_id=True) result = requestor.get("usage", {}) assert result.code == 200 assert result.body == data
def test_get_timeseries_returns_invalid_app_id(self, client): result = TimeSeries(Requestor("0", client)).get("2012-07-10", "2012-07-12", base="USD") assert isinstance(result, Response) assert result.code == 401 assert result.body == content("tests/fixtures/invalid_app_id.json")
def test_get_ohlc_returns_invalid_app_id(self, client): result = Ohlc(Requestor("0", client)).get("2017-07-17T11:00:00Z", "30m", base="USD") assert isinstance(result, Response) assert result.code == 401 assert result.body == content("tests/fixtures/invalid_app_id.json")
class Ohlc: def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor() def get( self, start_time, period, base=None, pretty_print=False, symbols=None, ): params = { "prettyprint": pretty_print, "period": period, "start_time": start_time, } if base is not None: params["base"] = base if symbols is not None: params["symbols"] = symbols return self._requestor.get("ohlc.json", params)
def test_get_convert_is_called_with_defaults(self, mocker, client_get_mock): client = client_get_mock(200, self.convert()) requestor = Requestor("fake_app_id", client) Convert(requestor).get(10, "USD", "EUR") client.get.assert_called_with(self.url(), params=self.params())
def test_get_timeseries_is_called_with_defaults(self, mocker, client_get_mock): client = client_get_mock(200, self.series()) requestor = Requestor("fake_app_id", client) TimeSeries(requestor).get("2012-07-10", "2012-07-12") client.get.assert_called_with(self.url(), params=self.params())
def test_get_currencies_is_called_with_defaults(self, mocker, client_get_mock): client = client_get_mock(200, self.currencies()) requestor = Requestor("fake_app_id", client, skip_app_id=True) Currency(requestor).get() client.get.assert_called_with(self.url(), params=self.params())
def test_get_historical_with_alternative(self, mocker, client_get_mock): client = client_get_mock(200, self.historical()) requestor = Requestor("fake_app_id", client) Historical(requestor).get("2012-07-10", show_alternative=True) client.get.assert_called_with( self.url(), params={**self.params(), "show_alternative": True}, )
def test_get_historical_with_symbols(self, mocker, client_get_mock): client = client_get_mock(200, self.historical()) requestor = Requestor("fake_app_id", client) Historical(requestor).get("2012-07-10", symbols="USD,EUR") client.get.assert_called_with( self.url(), params={**self.params(), "symbols": "USD,EUR"}, )
def test_get_historical_with_pretty_print(self, mocker, client_get_mock): client = client_get_mock(200, self.historical()) requestor = Requestor("fake_app_id", client) Historical(requestor).get("2012-07-10", pretty_print=True) client.get.assert_called_with( self.url(), params={**self.params(), "prettyprint": True}, )
def test_missing_api_id_exception(self, http_client): import coinoxr coinoxr.app_id = None message = "No API key provided. Setup coinoxr.app_id = <API-Key> or app_id argument.You can get the API key from open exchange rates dashboard." with pytest.raises(AppIdError) as ex: Requestor(None, client=http_client) assert message in str(ex.value)
def test_get_usage_called_with_defaults(self, client_get_mock): client = client_get_mock(200, self.usage()) requestor = Requestor("fake_app_id", client) Usage(requestor).get() client.get.assert_called_with( self.url(), params=self.params(), )
class Usage: def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor() def get(self, pretty_print=False): params = {"prettyprint": pretty_print} return self._requestor.get("usage.json", params)
class Convert: def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor() def get(self, amount, from_currency, to_currency, pretty_print=False): path = "convert/%s/%s/%s" % (amount, from_currency, to_currency) params = {"prettyprint": pretty_print} return self._requestor.get(path, params)
def test_get_latest_with_base(self, mocker, client_get_mock): client = client_get_mock(200, self.latest()) requestor = Requestor("fake_app_id", client) Latest(requestor).get(base="EUR") client.get.assert_called_with( self.url(), params={ **self.params(), "base": "EUR" }, )
def test_get_latest_with_alternative(self, mocker, client_get_mock): client = client_get_mock(200, self.latest()) requestor = Requestor("fake_app_id", client) Latest(requestor).get(show_alternative=True) client.get.assert_called_with( self.url(), params={ **self.params(), "show_alternative": True }, )
def test_get_timeseries_with_base(self, mocker, client_get_mock): client = client_get_mock(200, self.series()) requestor = Requestor("fake_app_id", client) TimeSeries(requestor).get("2012-07-10", "2012-07-12", base="EUR") client.get.assert_called_with( self.url(), params={ **self.params(), "base": "EUR" }, )
def test_get_currencies_with_inactive(self, mocker, client_get_mock): client = client_get_mock(200, self.currencies()) requestor = Requestor("fake_app_id", client, skip_app_id=True) Currency(requestor).get(show_inactive=True) client.get.assert_called_with( self.url(), params={ **self.params(), "show_inactive": True }, )
def test_get_latest_with_symbols(self, mocker, client_get_mock): client = client_get_mock(200, self.latest()) requestor = Requestor("fake_app_id", client) Latest(requestor).get(symbols="USD,EUR") client.get.assert_called_with( self.url(), params={ **self.params(), "symbols": "USD,EUR" }, )
def test_get_usage_with_pretty_print(self, client_get_mock): client = client_get_mock(200, self.usage()) requestor = Requestor("fake_app_id", client) Usage(requestor).get(pretty_print=True) client.get.assert_called_with( self.url(), params={ **self.params(), "prettyprint": True }, )
def test_get_convert_with_pretty_print(self, mocker, client_get_mock): client = client_get_mock(200, self.convert()) requestor = Requestor("fake_app_id", client) Convert(requestor).get(10, "USD", "EUR", pretty_print=True) client.get.assert_called_with( self.url(), params={ **self.params(), "prettyprint": True }, )
def test_get_ohlc_with_symbols(self, mocker, client_get_mock): client = client_get_mock(200, self.historical()) requestor = Requestor("fake_app_id", client) Ohlc(requestor).get("2017-07-17T11:00:00Z", "30m", symbols="USD,EUR") client.get.assert_called_with( self.url(), params={ **self.params(), "symbols": "USD,EUR" }, )
def test_get_ohlc_with_pretty_print(self, mocker, client_get_mock): client = client_get_mock(200, self.historical()) requestor = Requestor("fake_app_id", client) Ohlc(requestor).get("2017-07-17T11:00:00Z", "30m", pretty_print=True) client.get.assert_called_with( self.url(), params={ **self.params(), "prettyprint": True }, )
class Currency: def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor(skip_app_id=True) def get( self, pretty_print=False, show_alternative=False, show_inactive=False, ): params = { "prettyprint": pretty_print, "show_alternative": show_alternative, "show_inactive": show_inactive, } return self._requestor.get("currencies.json", params)
class Latest: def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor() def get(self, base=None, pretty_print=False, symbols=None, show_alternative=False): params = { "prettyprint": pretty_print, "show_alternative": show_alternative } if base is not None: params["base"] = base if symbols is not None: params["symbols"] = symbols return self._requestor.get("latest.json", params)
def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor()
def requestor(self, http_client): return Requestor("fake_api_key", client=http_client)
def test_get_ohlc_is_called_with_defaults(self, mocker, client_get_mock): client = client_get_mock(200, self.historical()) requestor = Requestor("fake_app_id", client) Ohlc(requestor).get("2017-07-17T11:00:00Z", "30m") client.get.assert_called_with(self.url(), params=self.params())
def __init__(self, requestor=None): self._requestor = requestor if requestor is None: self._requestor = Requestor(skip_app_id=True)
def test_get_convert_returns_missing_app_id(self, client): result = Convert(Requestor("missing_app_id", client)).get(10, "USD", "EUR") assert isinstance(result, Response) assert result.code == 401 assert result.body == content("tests/fixtures/missing_app_id.json")