示例#1
0
    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
示例#2
0
 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")
示例#3
0
 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")
示例#4
0
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)
示例#5
0
    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())
示例#6
0
    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())
示例#7
0
    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())
示例#8
0
    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},
        )
示例#9
0
    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"},
        )
示例#10
0
    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},
        )
示例#11
0
    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)
示例#12
0
    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(),
        )
示例#13
0
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)
示例#14
0
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)
示例#15
0
    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"
            },
        )
示例#16
0
    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
            },
        )
示例#17
0
    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"
            },
        )
示例#18
0
    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
            },
        )
示例#19
0
    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"
            },
        )
示例#20
0
    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
            },
        )
示例#21
0
    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
            },
        )
示例#22
0
    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"
            },
        )
示例#23
0
    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
            },
        )
示例#24
0
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)
示例#25
0
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)
示例#26
0
 def __init__(self, requestor=None):
     self._requestor = requestor
     if requestor is None:
         self._requestor = Requestor()
示例#27
0
 def requestor(self, http_client):
     return Requestor("fake_api_key", client=http_client)
示例#28
0
    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())
示例#29
0
 def __init__(self, requestor=None):
     self._requestor = requestor
     if requestor is None:
         self._requestor = Requestor(skip_app_id=True)
示例#30
0
 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")