def test_equal(self): resp1 = Response( status_code=200, text="{'a': 'b', 'c': 'd'}", headers={"User-Agent": "Stellar"}, url="https://httpbin.org", ) resp2 = Response( status_code=200, text="{'a': 'b', 'c': 'd'}", headers={"User-Agent": "Stellar"}, url="https://httpbin.org", ) resp3 = Response( status_code=404, text="{'a': 'b', 'c': 'd'}", headers={"User-Agent": "Stellar"}, url="https://httpbin.org", ) resp4 = "BAD TYPE" assert resp1 == resp2 != resp3 != resp4
def test_json(self): resp = Response( status_code=200, text='{"a": "b", "c": "d"}', headers={"User-Agent": "Stellar"}, url="https://httpbin.org", ) assert resp.json() == {"a": "b", "c": "d"}
def mock_load_account_no_account(account_id): if isinstance(account_id, Keypair): account_id = account_id.public_key if account_id not in [ Keypair.from_secret(v).public_key for v in [USD_DISTRIBUTION_SEED, ETH_DISTRIBUTION_SEED] ]: raise NotFoundError(response=Response(status_code=404, headers={}, url="", text=json.dumps(dict( status=404)))) account = Account(account_id, 1) account.signers = [] account.thresholds = Thresholds(0, 0, 0) return ( account, [{ "balances": [ { "asset_code": "USD", "asset_issuer": USD_ISSUER_ACCOUNT }, { "asset_code": "ETH", "asset_issuer": ETH_ISSUER_ACCOUNT }, ] }], )
def mock_load_not_exist_account(account_id): if account_id != settings.STELLAR_ISSUER_ACCOUNT_ADDRESS and account_id != settings.STELLAR_DISTRIBUTION_ACCOUNT_ADDRESS: raise NotFoundError(response=Response(status_code=404, headers={}, url="", text=json.dumps(dict( status=404)))) return Account(account_id, 1)
def mock_load_account_no_account(account_id): if account_id not in [ Keypair.from_secret(v).public_key for v in [USD_DISTRIBUTION_SEED, ETH_DISTRIBUTION_SEED] ]: raise NotFoundError(response=Response(status_code=404, headers={}, url="", text=json.dumps(dict( status=404)))) return Account(account_id, 1)
def mock_load_not_exist_account(account_id): accounts = [] for vals in settings.ASSETS.values(): accounts.extend(vals.values()) if account_id not in accounts: raise NotFoundError( response=Response( status_code=404, headers={}, url="", text=json.dumps(dict(status=404)) ) ) return Account(account_id, 1)
follow=True, ) content = json.loads(response.content) assert response.status_code == 400 assert content == {"error": "unknown asset: GBP"} @pytest.mark.django_db @patch("stellar_sdk.server.Server.fetch_base_fee", return_value=100) @patch( "stellar_sdk.server.Server.submit_transaction", side_effect=BadRequestError(response=Response( status_code=400, headers={}, url="", text=json.dumps( dict(status=400, extras=dict(result_xdr=TRUSTLINE_FAILURE_XDR))), )), ) def test_deposit_stellar_no_trustline( mock_submit, mock_base_fee, client, acc1_usd_deposit_transaction_factory, ): """ `create_stellar_deposit` sets the transaction with the provided `transaction_id` to status `pending_trust` if the provided transaction's Stellar account has no trustline for its asset. (We assume the asset's issuer is the server Stellar account.) """
def raise_not_found_error(): response = Response(9, '', {}, '') # dummy response raise stellar_sdk.exceptions.BadResponseError(response)
def raise_not_found(*_): response = Response(9, '', {}, '') raise NotFoundError(response)
assert transaction["status"] == Transaction.STATUS.pending_anchor assert float(transaction["amount_in"]) == amount assert int(transaction["status_eta"]) == 5 assert transaction["external_transaction_id"] == external_id @pytest.mark.django_db @patch("stellar_sdk.server.Server.fetch_base_fee", return_value=100) @patch( "stellar_sdk.server.Server.submit_transaction", side_effect=BadRequestError(response=Response( status_code=400, headers={}, url="", text=json.dumps({ "status": 400, "extras": { "result_xdr": TRUSTLINE_FAILURE_XDR } }), )), ) def test_deposit_stellar_no_trustline( mock_submit, mock_base_fee, client, acc1_usd_deposit_transaction_factory, ): """ `create_stellar_deposit` sets the transaction with the provided `transaction_id` to status `pending_trust` if the provided transaction's Stellar account has no trustline