# -*- coding: utf-8 -*-

"""
pqapiv2

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

import json
import dateutil.parser

from tests.controllers.controller_test_base import ControllerTestBase
from tests.test_helper import TestHelper
from pqapiv2.api_helper import APIHelper
from pqapiv2.models.bank_account_fields import BankAccountFields


class BankAccountsControllerTests(ControllerTestBase):

    @classmethod
    def setUpClass(cls):
        super(BankAccountsControllerTests, cls).setUpClass()
        cls.controller = cls.client.bank_accounts
        cls.response_catcher = cls.controller.http_call_back

    # Retrieve a list of bank accounts that supports filtering, sorting, and pagination through existing mechanisms.
    def test_list_bank_accounts(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        x_my_pay_quicker_version = '2020.02.24'
        page = None
        page_size = 20
        filter = '\'name\'*\'Fra\'||*\'Ger\',\'numericCode\'>\'5\''
        sort = '-name'
        language = 'en-US'

        # Perform the API call through the SDK function
        result = self.controller.list_bank_accounts(user_token, x_my_pay_quicker_version, page, page_size, filter, sort, language)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"payload":[{"token":"dest-7d8b1c83-01bb-40fb-87d7-26bd4c303f01","'
            'status":"DELETED","createdOn":"2020-02-21T22:00:00Z","bankAccountO'
            'wnershipType":"PERSONAL","type":"CHECKING","fields":[{"key":"BANK_'
            'ACH_ABA","value":"333333333"},{"key":"BANK_BBAN","value":"44444444'
            '44"}],"bankCurrency":"USD","bankCountry":"US","description":"My ac'
            'count","links":[{"params":{"rel":"self"},"href":"string"}]},{"toke'
            'n":"dest-efacd12b-a86e-4f44-bbea-927955ec1634","status":"ACTIVE","'
            'createdOn":"2020-02-21T22:00:00Z","bankAccountOwnershipType":"PERS'
            'ONAL","type":"CHECKING","fields":[{"key":"BANK_ACH_ABA","value":"0'
            '12346789"},{"key":"BANK_BBAN","value":"987654321"}],"bankCurrency"'
            ':"USD","bankCountry":"US","description":"Personal checking account'
            '","links":[{"params":{"rel":"self"},"href":"string"}]}],"links":[{'
            '"params":{"rel":"self"},"href":"string"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Create a quote for a bank account using a user token.
    def test_create_bank_account(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        x_my_pay_quicker_version = '2020.02.24'
        body = None

        # Perform the API call through the SDK function
        result = self.controller.create_bank_account(user_token, x_my_pay_quicker_version, body)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"token":"dest-efacd12b-a86e-4f44-bbea-927955ec1634","status":"ACT'
            'IVE","createdOn":"2020-02-21T22:00:00Z","bankAccountOwnershipType"'
            ':"PERSONAL","type":"CHECKING","fields":[{"key":"BANK_ACH_ABA","val'
            'ue":"012346789"},{"key":"BANK_BBAN","value":"987654321"}],"bankCur'
            'rency":"USD","bankCountry":"US","description":"Personal checking a'
            'ccount","links":[{"params":{"rel":"self"},"href":"string"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Retrieve a list of bank accounts using a destination token that supports filtering, sorting, and pagination through existing mechanisms.
    def test_retrieve_bank_account(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        dest_token = 'dest-4aed86e2-4929-45bf-814d-9030aef21e79'
        x_my_pay_quicker_version = '2020.02.24'
        page = None
        page_size = 20
        filter = '\'name\'*\'Fra\'||*\'Ger\',\'numericCode\'>\'5\''
        sort = '-name'
        language = 'en-US'

        # Perform the API call through the SDK function
        result = self.controller.retrieve_bank_account(user_token, dest_token, x_my_pay_quicker_version, page, page_size, filter, sort, language)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"token":"dest-efacd12b-a86e-4f44-bbea-927955ec1634","status":"ACT'
            'IVE","createdOn":"2020-02-21T22:00:00Z","bankAccountOwnershipType"'
            ':"PERSONAL","type":"CHECKING","fields":[{"key":"BANK_ACH_ABA","val'
            'ue":"012346789"},{"key":"BANK_BBAN","value":"987654321"}],"bankCur'
            'rency":"USD","bankCountry":"US","description":"Personal checking a'
            'ccount","links":[{"params":{"rel":"self"},"href":"string"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Update a bank account.
    def test_update_bank_account(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        dest_token = 'dest-4aed86e2-4929-45bf-814d-9030aef21e79'
        x_my_pay_quicker_version = '2020.02.24'
        body = None

        # Perform the API call through the SDK function
        result = self.controller.update_bank_account(user_token, dest_token, x_my_pay_quicker_version, body)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"token":"dest-efacd12b-a86e-4f44-bbea-927955ec1634","status":"ACT'
            'IVE","createdOn":"2020-02-21T22:00:00Z","bankAccountOwnershipType"'
            ':"PERSONAL","type":"CHECKING","fields":[{"key":"BANK_ACH_ABA","val'
            'ue":"012346789"},{"key":"BANK_BBAN","value":"987654321"}],"bankCur'
            'rency":"USD","bankCountry":"US","description":"Personal checking a'
            'ccount","links":[{"params":{"rel":"self"},"href":"string"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Delete (cloak) a user bank account.
    def test_delete_bank_account(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        dest_token = 'dest-4aed86e2-4929-45bf-814d-9030aef21e79'
        x_my_pay_quicker_version = '2020.02.24'

        # Perform the API call through the SDK function
        self.controller.delete_bank_account(user_token, dest_token, x_my_pay_quicker_version)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

    # Retrieve requirements for adding a bank account using the parameters provided (user context, given country of residence, supported EFT provider(s), destination currency, destination country, required fields, with names, and regex validation expression) for easy customer wire-up and validation.
    def test_get_bank_account_requirements(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        x_my_pay_quicker_version = '2020.02.24'
        page = None
        page_size = 20
        filter = '\'name\'*\'Fra\'||*\'Ger\',\'numericCode\'>\'5\''
        sort = '-name'
        language = 'en-US'

        # Perform the API call through the SDK function
        result = self.controller.get_bank_account_requirements(user_token, x_my_pay_quicker_version, page, page_size, filter, sort, language)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"payload":[{"bankCountry":"IT","bankCurrency":"EUR","requirements'
            '":[{"requirement":"BANK_IBAN","format":{"example":"IT43K0310412701'
            '000000820420","legend":[{"key":"IT43K0310412701000000820420","desc'
            'riptions":[{"language":"en-US","translation":"Example IBAN"},{"lan'
            'guage":"it-IT","translation":"Esempio IBAN"}]}]},"description":[{"'
            'language":"en-US","translation":"IBAN"},{"language":"it-IT","trans'
            'lation":"IBAN"}],"validators":[{"validatorType":"REGEX","expressio'
            'n":"^IT\\\\\\\\d{2}[A-Z]\\\\\\\\d{10}[0-9A-Z]{12}$"}]},{"requireme'
            'nt":"BANK_SWIFT_BIC","format":{"example":"01234567890","legend":[{'
            '"key":"01234567890","descriptions":[{"language":"en-US","translati'
            'on":"Example Swift/BIC"},{"language":"it-IT","translation":"Esempi'
            'o Swift/BIC"}]}]},"description":[{"language":"en-US","translation"'
            ':"Swift/BIC"},{"language":"it-IT","translation":"Swift/BIC"}],"val'
            'idators":[{"validatorType":"REGEX","expression":"^[a-z0-9A-Z]{8,11'
            '}$"}]}],"quote":{"formattedAmount":"$4.32 USD (USD, en-US), 0,00 €'
            ' EUR (EUR, fr-FR)","amount":4.32,"currency":"USD"},"links":[{"para'
            'ms":{"rel":"self"},"href":"string"}]}],"links":[{"params":{"rel":"'
            'self"},"href":"string"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

