def test_get(self): client = RequestsClient() url = "https://testhorizon.paydex.io//get" params = {"hello": "world", "Paydex": "sdk"} resp = client.get(url, params=params) assert resp.status_code == 200 json = resp.json() assert json["args"] == params assert json["headers"]["User-Agent"] == USER_AGENT
def test_stream(self): client = RequestsClient() resp = [] for msg in client.stream("https://horizon.Paydex.org/ledgers", {"cursor": "now"}): assert isinstance(msg, dict) resp.append(msg) if len(resp) == 2: break
def test_submit_transaction_with_xdr(self): xdr = "AAAAAHI7fpgo+b7tgpiFyYWimjV7L7IOYLwmQS7k7F8SronXAAAAZAE+QT4AAAAJAAAAAQAAAAAAAAAAAAAAAF1MG8cAAAAAAAAAAQAAAAAAAAAAAAAAAOvi1O/HEn+QgZJw+EMZBtwvTVNmpgvE9p8IRfwp0GY4AAAAAAExLQAAAAAAAAAAARKuidcAAABAJVc1ASGp35hUquGNbzzSqWPoTG0zgc89zc4p+19QkgbPqsdyEfHs7+ng9VJA49YneEXRa6Fv7pfKpEigb3VTCg==" horizon_url = "https://testhorizon.paydex.io/" client = RequestsClient() with Server(horizon_url, client) as server: resp = server.submit_transaction(xdr) assert resp["envelope_xdr"] == xdr
def test_get_data_no_link(self): url = "https://testhorizon.paydex.io/get" client = RequestsClient() call_builder = (BaseCallBuilder( url, client).limit(10).cursor(10086).order(desc=True)) call_builder.call() assert call_builder.next_href is None assert call_builder.prev_href is None
def test_post(self): client = RequestsClient() url = "https://testhorizon.paydex.io//post" data = { "tx": "AAAAABa3N0+hJk17vP/AnYK5xV4o/PhOnEfgi36HlYo4g+3nAAAAZQFDfjoAAaTSAAAAAA" "AAAAEAAAAJX3VwZGF0ZWRfAAAAAAAAAQAAAAEAAAAAFrc3T6EmTXu8/8CdgrnFXij8+E6cR+" "CLfoeVijiD7ecAAAADAAAAAAAAAAFFVFgAAAAAAIhWSba8wLvB8YFRdzLJPkoyQSFmvRMQeaD" "Kym9JD6yTAAAAAAfjgC8NOvYPAA7nFwAAAAAGU5P1AAAAAAAAAAE4g+3nAAAAQOlPDNg4a76N/4" "VQh5oKc+RaUZVlK3Pr1HJphQn/yMthQh9gVGUbg/MHKl1RnKPuvmpzyqpBgb1zBVgyAYfIaQI=" } resp = client.post(url, data=data) assert resp.status_code == 200 json = resp.json() assert json["headers"][ "Content-Type"] == "application/x-www-form-urlencoded" assert json["form"] == data
def test_stream_data_sync(self): url = "https://testhorizon.paydex.io/ledgers" client = RequestsClient() resp = BaseCallBuilder(url, client).cursor("now").stream() messages = [] for msg in resp: assert isinstance(msg, dict) messages.append(msg) if len(messages) == 2: break
def test_get_data_not_pageable_raise(self): url = "https://testhorizon.paydex.io/get" client = RequestsClient() call_builder = (BaseCallBuilder( url, client).limit(10).cursor(10086).order(desc=True)) call_builder.call() with pytest.raises(NotPageableError, match="The next page does not exist."): call_builder.next() with pytest.raises(NotPageableError, match="The prev page does not exist."): call_builder.prev()
def test_get_data_page(self): url = "https://testhorizon.paydex.io/transactions" client = RequestsClient() call_builder = (BaseCallBuilder( url, client).cursor(81058917781504).limit(10).order(desc=True)) first_resp = call_builder.call() assert first_resp["_links"] == { "self": { "href": "https://testhorizon.paydex.io/transactions?cursor=81058917781504&limit=10&order=desc" }, "next": { "href": "https://testhorizon.paydex.io/transactions?cursor=12884905984&limit=10&order=desc" }, "prev": { "href": "https://testhorizon.paydex.io/transactions?cursor=80607946215424&limit=10&order=asc" }, } next_resp = call_builder.next() assert next_resp["_links"] == { "self": { "href": "https://testhorizon.paydex.io/transactions?cursor=12884905984&limit=10&order=desc" }, "next": { "href": "https://testhorizon.paydex.io/transactions?cursor=12884905984&limit=10&order=desc" }, "prev": { "href": "https://testhorizon.paydex.io/transactions?cursor=12884905984&limit=10&order=asc" }, } prev_page = call_builder.prev() assert prev_page["_links"] == { "self": { "href": "https://testhorizon.paydex.io/transactions?cursor=12884905984&limit=10&order=asc" }, "next": { "href": "https://testhorizon.paydex.io/transactions?cursor=81827716927488&limit=10&order=asc" }, "prev": { "href": "https://testhorizon.paydex.io/transactions?cursor=33676838572032&limit=10&order=desc" }, }
def test_status_400_raise_sync(self): url = "https://testhorizon.paydex.io/accounts/BADACCOUNTID" client = RequestsClient() with pytest.raises(BadRequestError) as err: BaseCallBuilder(url, client).call() exception = err.value assert exception.status == 400 assert exception.type == "https://paydex.org/horizon-errors/bad_request" assert exception.title == "Bad Request" assert exception.detail == "The request you sent was invalid in some way." assert exception.extras == { "invalid_field": "account_id", "reason": "invalid address", }
def test_status_404_raise_sync(self): url = "https://testhorizon.paydex.io/not_found" client = RequestsClient() with pytest.raises(NotFoundError) as err: BaseCallBuilder(url, client).call() exception = err.value assert exception.status == 404 assert exception.type == "https://paydex.org/horizon-errors/not_found" assert exception.title == "Resource Missing" assert ( exception.detail == "The resource at the url requested was not found. This " "usually occurs for one of two reasons: The url requested is not valid, " "or no data in our database could be found with the parameters provided." ) assert exception.extras is None
def test_get_data_sync(self): url = "https://testhorizon.paydex.io/get" client = RequestsClient() resp = (BaseCallBuilder( url, client).limit(10).cursor(10086).order(desc=True).call()) assert resp["args"] == { "cursor": "10086", "limit": "10", "order": "desc" } assert resp["headers"][ "User-Agent"] == "py-paydex-sdk/{}/RequestsClient".format( __version__) assert resp["headers"]["X-Client-Name"] == "py-paydex-sdk" assert resp["headers"]["X-Client-Version"] == __version__ assert resp[ "url"] == "https://testhorizon.paydex.io/get?limit=10&cursor=10086&order=desc"
def test_endpoint(self): horizon_url = "https://testhorizon.paydex.io/" client = RequestsClient() with Server(horizon_url, client) as server: assert server.accounts() == AccountsCallBuilder( horizon_url, client) assert server.assets() == AssetsCallBuilder(horizon_url, client) assert server.data( "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D", "hello") == DataCallBuilder( horizon_url, client, "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D", "hello", ) assert server.effects() == EffectsCallBuilder(horizon_url, client) assert server.fee_stats() == FeeStatsCallBuilder( horizon_url, client) assert server.ledgers() == LedgersCallBuilder(horizon_url, client) assert server.offers() == OffersCallBuilder(horizon_url, client) assert server.operations() == OperationsCallBuilder( horizon_url, client) buying = Asset.native() selling = Asset( "MOE", "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D") assert server.orderbook(buying, selling) == OrderbookCallBuilder( horizon_url, client, buying, selling) source_account = "GABUVMDURJFF477AEDAXOG5TL7JBHGDAKJQLH5K6FB5QONMLEV52C6IO" destination_account = ( "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D") destination_asset = Asset.native() destination_amount = "100.0" assert server.paths( source_account, destination_account, destination_asset, destination_amount, ) == PathsCallBuilder( horizon_url, client, source_account, destination_account, destination_asset, destination_amount, ) source = "GAYSHLG75RPSMXWJ5KX7O7STE6RSZTD6NE4CTWAXFZYYVYIFRUVJIBJH" destination_asset = Asset( "EUR", "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN") destination_amount = "20.0" assert server.strict_receive_paths( source, destination_asset, destination_amount) == StrictReceivePathsCallBuilder( horizon_url, client, source, destination_asset, destination_amount) source_asset = Asset( "EUR", "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN") source_amount = "10.25" destination = "GARSFJNXJIHO6ULUBK3DBYKVSIZE7SC72S5DYBCHU7DKL22UXKVD7MXP" assert server.strict_send_paths( source_asset, source_amount, destination) == StrictSendPathsCallBuilder( horizon_url, client, source_asset, source_amount, destination) assert server.payments() == PaymentsCallBuilder( horizon_url, client) assert server.root() == RootCallBuilder(horizon_url, client) base = Asset.native() counter = Asset( "MOE", "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D") resolution = 3600000 start_time = 1565272000000 end_time = 1565278000000 offset = 3600000 assert server.trade_aggregations( base, counter, resolution, start_time, end_time, offset) == TradeAggregationsCallBuilder( horizon_url, client, base, counter, resolution, start_time, end_time, offset, ) assert server.trades() == TradesCallBuilder(horizon_url, client) assert server.transactions() == TransactionsCallBuilder( horizon_url, client)
from paydex_base_sdk.client.requests_client import RequestsClient horizon_url = "https://testhorizon.paydex.io//" client = RequestsClient()