# -*- 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.webhook_subscription import WebhookSubscription


class WebhooksControllerTests(ControllerTestBase):

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

    # Retrieve a list of all webhook subscriptions that supports filtering, sorting, and pagination through existing mechanisms.
    def test_list_webhook_subscriptions(self):
        # Parameters for the API call
        x_my_pay_quicker_version = '2020.02.24'

        # Perform the API call through the SDK function
        result = self.controller.list_webhook_subscriptions(x_my_pay_quicker_version)

        # 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('{"links":[{"params":{"rel":"self"},"href":"string"}],"payload":[{"'
            'links":[{"params":{"rel":"self"},"href":"string"}],"url":"https://'
            'www.example.com/webhooks","namespace":"BANKACCOUNTS.UPDATED.STATUS'
            '.APPROVED","token":"webh-2dd54a53-3814-4ce1-862f-dc06b09ead4a","cr'
            'eated":"2020-01-01","lastUpdated":"2020-02-01"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Create a webhook subscription for a given URL and namespace. When this event fires, the webhook receives a call from the API.
    def test_create_webhook_subscription(self):
        # Parameters for the API call
        x_my_pay_quicker_version = '2020.02.24'
        body = None

        # Perform the API call through the SDK function
        result = self.controller.create_webhook_subscription(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('{"links":[{"params":{"rel":"self"},"href":"string"}],"url":"https:'
            '//www.example.com/webhooks","namespace":"BANKACCOUNTS.UPDATED.STAT'
            'US.APPROVED","token":"webh-2dd54a53-3814-4ce1-862f-dc06b09ead4a","'
            'created":"2020-01-01"}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Create a webhook subscription for a given URL and namespace. When this event fires, the webhook receives a call from the API.
    def test_create_webhook_subscription_1(self):
        # Parameters for the API call
        x_my_pay_quicker_version = '2020.02.24'
        body = None

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

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

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

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


