# WARNING: Do not edit by hand, this file was generated by Crank:
#
#   https://github.com/gocardless/crank
#

import json

import pytest
import requests
import responses

from gocardless_pro.errors import MalformedResponseError
from gocardless_pro import resources
from gocardless_pro import list_response

from .. import helpers
  

@responses.activate
def test_bank_details_lookups_create():
    fixture = helpers.load_fixture('bank_details_lookups')['create']
    helpers.stub_response(fixture)
    response = helpers.client.bank_details_lookups.create(*fixture['url_params'])
    body = fixture['body']['bank_details_lookups']

    assert isinstance(response, resources.BankDetailsLookup)
    assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None
    assert response.available_debit_schemes == body.get('available_debit_schemes')
    assert response.bank_name == body.get('bank_name')
    assert response.bic == body.get('bic')

@responses.activate
def test_timeout_bank_details_lookups_create_retries():
    fixture = helpers.load_fixture('bank_details_lookups')['create']
    with helpers.stub_timeout_then_response(fixture) as rsps:
      response = helpers.client.bank_details_lookups.create(*fixture['url_params'])
      assert len(rsps.calls) == 2
      assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key')
    body = fixture['body']['bank_details_lookups']

    assert isinstance(response, resources.BankDetailsLookup)

def test_502_bank_details_lookups_create_retries():
    fixture = helpers.load_fixture('bank_details_lookups')['create']
    with helpers.stub_502_then_response(fixture) as rsps:
      response = helpers.client.bank_details_lookups.create(*fixture['url_params'])
      assert len(rsps.calls) == 2
      assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key')
    body = fixture['body']['bank_details_lookups']

    assert isinstance(response, resources.BankDetailsLookup)
  
