# -*- coding: utf-8 -*-
"""Define the cert_manager.domain.Domain unit tests."""
# Don't warn about things that happen as that is part of unit testing
# pylint: disable=protected-access
# pylint: disable=no-member

import json

from requests.exceptions import HTTPError
from testtools import TestCase

import responses

from cert_manager.domain import Domain, DomainCreationResponseError

from .lib.testbase import ClientFixture


class TestDomain(TestCase):  # pylint: disable=too-few-public-methods
    """Serve as a Base class for all tests of the Domain class."""

    def setUp(self):  # pylint: disable=invalid-name
        """Initialize the class."""
        # Call the inherited setUp method
        super().setUp()

        # Make sure the Client fixture is created and setup
        self.cfixt = self.useFixture(ClientFixture())
        self.client = self.cfixt.client

        self.api_url = f"{self.cfixt.base_url}/domain/v1"

        # Setup a test response one would expect normally
        self.valid_response = [
            {"id": 1234, "name": "example.com"},
            {"id": 4321, "name": "*.example.com"},
            {"id": 4322, "name": "subdomain.example.com"},
        ]

        # Setup a test response for getting a specific Domain
        self.valid_individual_response = self.valid_response[0]
        self.valid_individual_response["status"] = "Active"

        # Setup JSON to return in an error
        self.error_response = {"description": "domain error"}


class TestInit(TestDomain):
    """Test the class initializer."""

    @responses.activate
    def test_param(self):
        """The URL should change if api_version is passed as a parameter."""
        # Set a new version
        version = "v3"
        api_url = f"{self.cfixt.base_url}/domain/{version}"

        # Setup the mocked response
        responses.add(responses.GET, api_url, json=self.valid_response, status=200)

        domain = Domain(client=self.client, api_version=version)
        data = domain.all()

        # Verify all the query information
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, api_url)

        self.assertEqual(data, self.valid_response)

    def test_need_client(self):
        """The class should raise an exception without a client parameter."""
        self.assertRaises(TypeError, Domain)


class TestAll(TestDomain):
    """Test the .all method."""

    @responses.activate
    def test_cached(self):
        """The function should return all the data, but should not query the API twice."""
        # Setup the mocked response
        responses.add(responses.GET, self.api_url, json=self.valid_response, status=200)

        domain = Domain(client=self.client)
        data = domain.all()
        data = domain.all()

        # Verify all the query information
        # There should only be one call the first time "all" is called.
        # Due to pagination, this is only guaranteed as long as the number of
        # entries returned is less than the page size
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, self.api_url)
        self.assertEqual(data, self.valid_response)

    @responses.activate
    def test_forced(self):
        """The function should return all the data, but should query the API twice."""
        # Setup the mocked response
        responses.add(responses.GET, self.api_url, json=self.valid_response, status=200)

        domain = Domain(client=self.client)
        data = domain.all()
        data = domain.all(force=True)

        # Verify all the query information
        # There should only be one call the first time "all" is called.
        # Due to pagination, this is only guaranteed as long as the number of
        # entries returned is less than the page size
        self.assertEqual(len(responses.calls), 2)
        self.assertEqual(responses.calls[0].request.url, self.api_url)
        self.assertEqual(responses.calls[1].request.url, self.api_url)
        self.assertEqual(data, self.valid_response)

    @responses.activate
    def test_bad_http(self):
        """The function should raise an HTTPError exception if domains cannot be retrieved from the API."""
        # Setup the mocked response
        responses.add(responses.GET, self.api_url, json=self.error_response, status=400)

        domain = Domain(client=self.client)
        self.assertRaises(HTTPError, domain.all)

        # Verify all the query information
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, self.api_url)


class TestFind(TestDomain):
    """Test the .find method."""

    @responses.activate
    def test_no_params(self):
        """Without parameters, the method will return all domains"""
        # Setup the mocked response
        responses.add(responses.GET, self.api_url, json=self.valid_response, status=200)

        domain = Domain(client=self.client)
        data = domain.find()

        self.assertEqual(data, self.valid_response)

    @responses.activate
    def test_params(self):
        """Parameters will be passed to API"""
        # Setup the mocked response
        responses.add(responses.GET, self.api_url, json=self.valid_response[0], status=200)

        api_url = f"{self.api_url}?name=example.com"
        domain = Domain(client=self.client)
        data = domain.find(name="example.com")

        # Verify all the query information

        self.assertEqual(responses.calls[0].request.url, api_url)
        self.assertEqual(data, self.valid_response[0])

    @responses.activate
    def test_bad_http(self):
        """The function should raise an HTTPError exception if domains cannot be retrieved from the API."""
        # Setup the mocked response
        responses.add(responses.GET, self.api_url, json=self.error_response, status=400)

        domain = Domain(client=self.client)
        self.assertRaises(HTTPError, domain.find)

        # Verify all the query information
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, self.api_url)


class TestCount(TestDomain):
    """Test the .count method."""

    @responses.activate
    def test_no_params(self):
        """Without parameters, the method will count all domains"""
        # Setup the mocked response
        count = {"count": len(self.valid_response)}
        api_url = f"{self.api_url}/count"
        responses.add(responses.GET, api_url, json=count, status=200)

        domain = Domain(client=self.client)
        data = domain.count()

        self.assertEqual(data, count)
        self.assertEqual(responses.calls[0].request.url, api_url)

    @responses.activate
    def test_params(self):
        """Parameters will be passed to API"""
        # Setup the mocked response
        count = {"count": len(self.valid_response[0])}
        api_url = f"{self.api_url}/count"
        responses.add(responses.GET, api_url, json=count, status=200)

        domain = Domain(client=self.client)
        data = domain.count(name="example.com")

        # Verify all the query information
        self.assertEqual(responses.calls[0].request.url, f"{api_url}?name=example.com")
        self.assertEqual(data, count)

    @responses.activate
    def test_bad_http(self):
        """The function should raise an HTTPError exception if counts cannot be retrieved from the API."""
        # Setup the mocked response
        api_url = f"{self.api_url}/count"
        responses.add(responses.GET, api_url, json=self.error_response, status=400)

        domain = Domain(client=self.client)
        self.assertRaises(HTTPError, domain.count)

        # Verify all the query information
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, api_url)


class TestGet(TestDomain):
    """Test the .get method."""

    @responses.activate
    def test_need_domain_id(self):
        """The function should raise an exception without an domain_id parameter."""

        domain = Domain(client=self.client)
        self.assertRaises(TypeError, domain.get)

    @responses.activate
    def test_domain_id(self):
        """The function should return data about the specified Domain ID."""

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}"

        # Setup the mocked response
        responses.add(responses.GET, api_url, json=self.valid_individual_response, status=200)

        domain = Domain(client=self.client)
        data = domain.get(domain_id)

        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, api_url)
        self.assertEqual(data, self.valid_individual_response)

    @responses.activate
    def test_ne_domain_id(self):
        """The function should raise an HTTPError exception if the specified Domain ID does not exist."""

        domain_id = 2345
        api_url = f"{self.api_url}/{str(domain_id)}"

        # Setup the mocked response
        responses.add(responses.GET, api_url, status=404)

        domain = Domain(client=self.client)
        self.assertRaises(HTTPError, domain.get, domain_id)


class TestCreate(TestDomain):
    """Test the .create method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # Not going to check every permutation of missing parameters,
        # but verify that something is required
        self.assertRaises(TypeError, domain.create)

    @responses.activate
    def test_create_success(self):
        """
        The function should return the created domain ID,
        as well as add all parameters to the request body
        """

        # Setup the mocked response
        domain_id = 1234
        org_id = 4321
        types = ["SSL"]
        location = f"{self.api_url}/{str(domain_id)}"
        responses.add(responses.POST, self.api_url, headers={"Location": location}, status=201)

        domain = Domain(client=self.client)
        post_data = {
            "name": "sub2.example.com",
            "delegations": [{"orgId": org_id, "certTypes": types}]
        }
        response = domain.create("sub2.example.com", org_id, types)

        self.assertEqual(response, {"id": domain_id})
        self.assertEqual(responses.calls[0].request.body, json.dumps(post_data).encode("utf8"))

    @responses.activate
    def test_create_success_optional_params(self):
        """
        The function should return the created domain ID when additional params are specified,
        as well add the non-required parameters to the request body
        """

        # Setup the mocked response
        domain_id = 1234
        location = f"{self.api_url}/{str(domain_id)}"
        responses.add(responses.POST, self.api_url, headers={"Location": location}, status=201)

        domain = Domain(client=self.client)
        post_data = {
            "name": "sub2.example.com",
            "delegations": [{"orgId": 4321, "certTypes": ["SSL"]}],
            "description": "Example sub domain"
        }
        response = domain.create("sub2.example.com", 4321, ["SSL"], description="Example sub domain")

        self.assertEqual(response, {"id": domain_id})
        self.assertEqual(responses.calls[0].request.body, json.dumps(post_data).encode("utf8"))

    @responses.activate
    def test_create_failure_http_error(self):
        """
        The function should return an error code and description if the Domain
        creation failed.
        """

        # Setup the mocked response
        responses.add(responses.POST, self.api_url, json=self.error_response,
                      status=400)

        domain = Domain(client=self.client)

        create_args = {
            "name": "sub2.example.com",
            "org_id": 4321,
            "cert_types": ["other"]
        }
        self.assertRaises(ValueError, domain.create, **create_args)

    @responses.activate
    def test_create_failure_http_status_unexpected(self):
        """
        The function should return an error code and description if the Domain
        creation failed with DomainCreationResponseError
        (unexpected HTTP status code).
        """

        # Setup the mocked response
        responses.add(responses.POST, self.api_url, json=self.error_response,
                      status=200)

        domain = Domain(client=self.client)

        create_args = {
            "name": "sub2.example.com",
            "org_id": 4321,
            "cert_types": ["SSL"]
        }
        self.assertRaises(DomainCreationResponseError, domain.create, **create_args)

    @responses.activate
    def test_create_failure_missing_location_header(self):
        """
        The function should return an error code and description if the Domain
        creation failed with DomainCreationResponseError
        (no Location header in response).
        """

        # Setup the mocked response
        responses.add(responses.POST, self.api_url, status=201)

        domain = Domain(client=self.client)

        create_args = {
            "name": "sub2.example.com",
            "org_id": 4321,
            "cert_types": ["SSL"]
        }
        self.assertRaises(DomainCreationResponseError, domain.create, **create_args)

    @responses.activate
    def test_create_failure_domain_id_not_found(self):
        """
        The function should return an error code and description if the Domain
        creation failed with DomainCreationResponseError
        (Domain ID not found in response).
        """

        # Setup the mocked response
        responses.add(responses.POST, self.api_url, headers={"Location": "not a url"}, status=201)

        domain = Domain(client=self.client)

        create_args = {
            "name": "sub2.example.com",
            "org_id": 4321,
            "cert_types": ["SSL"]
        }
        self.assertRaises(DomainCreationResponseError, domain.create, **create_args)


class TestDelete(TestDomain):
    """Test the .delete method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.delete)

    @responses.activate
    def test_delete_success(self):
        """The function should return True if the deletion succeeded."""

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}"

        # Setup the mocked response
        responses.add(responses.DELETE, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.delete(domain_id)

        self.assertEqual(True, response)

    @responses.activate
    def test_delete_failure_http_error(self):
        """
        The function should raise an HTTPError exception if the deletion
        failed.
        """

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}"

        # Setup the mocked response
        responses.add(responses.DELETE, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.delete, domain_id)


class TestActivate(TestDomain):
    """Test the .activate method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.activate)

    @responses.activate
    def test_activate_success(self):
        """The function should return True if the activation succeeded."""

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}/activate"

        # Setup the mocked response
        responses.add(responses.PUT, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.activate(domain_id)

        self.assertEqual(True, response)

    @responses.activate
    def test_activate_failure_http_error(self):
        """
        The function should raise an HTTPError exception if the deletion
        failed.
        """

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}/activate"

        # Setup the mocked response
        responses.add(responses.PUT, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.activate, domain_id)


class TestSuspend(TestDomain):
    """Test the .suspend method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.suspend)

    @responses.activate
    def test_suspend_success(self):
        """The function should return True if the suspension succeeded."""

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}/suspend"

        # Setup the mocked response
        responses.add(responses.PUT, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.suspend(domain_id)

        self.assertEqual(True, response)

    @responses.activate
    def test_suspend_failure_http_error(self):
        """
        The function should raise an HTTPError exception if the suspension
        failed.
        """

        domain_id = 1234
        api_url = f"{self.api_url}/{str(domain_id)}/suspend"

        # Setup the mocked response
        responses.add(responses.PUT, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.suspend, domain_id)


class TestDelegate(TestDomain):
    """Test the .delegate method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.delegate)

    @responses.activate
    def test_delegate_success(self):
        """The function should return True if the delegation succeeded."""

        domain_id = 1234
        org_id = 4321
        types = ["SSL"]
        api_url = f"{self.api_url}/{str(domain_id)}/delegation"

        # Setup the mocked response
        responses.add(responses.POST, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.delegate(domain_id, org_id, types)
        post_data = {
            "orgId": org_id,
            "certTypes": types
        }

        self.assertEqual(True, response)
        self.assertEqual(responses.calls[0].request.body, json.dumps(post_data).encode("utf8"))

    @responses.activate
    def test_delegate_failure_http_error(self):
        """The function should raise an HTTPError exception if the delegation failed."""

        domain_id = 1234
        org_id = 4321
        types = ["SSL"]
        api_url = f"{self.api_url}/{str(domain_id)}/delegation"

        # Setup the mocked response
        responses.add(responses.POST, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.delegate, domain_id, org_id, types)


class TestRemoveDelegation(TestDomain):
    """Test the .remove_delegation method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.remove_delegation)

    @responses.activate
    def test_remove_delegation_success(self):
        """The function should return True if the delegation removal succeeded."""

        domain_id = 1234
        org_id = 4321
        types = ["SSL"]
        api_url = f"{self.api_url}/{str(domain_id)}/delegation"

        # Setup the mocked response
        responses.add(responses.DELETE, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.remove_delegation(domain_id, org_id, types)
        post_data = {
            "orgId": org_id,
            "certTypes": types
        }

        self.assertEqual(True, response)
        self.assertEqual(responses.calls[0].request.body, json.dumps(post_data).encode("utf8"))

    @responses.activate
    def test_remove_delegation_failure_http_error(self):
        """The function should raise an HTTPError exception if the delegation removal failed."""

        domain_id = 1234
        org_id = 4321
        types = ["SSL"]
        api_url = f"{self.api_url}/{str(domain_id)}/delegation"

        # Setup the mocked response
        responses.add(responses.DELETE, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.remove_delegation, domain_id, org_id, types)


class TestApproveDelegation(TestDomain):
    """Test the .approve_delegation method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.approve_delegation)

    @responses.activate
    def test_approve_delegation_success(self):
        """The function should return True if the approval succeeded."""

        domain_id = 1234
        org_id = 4321
        api_url = f"{self.api_url}/{str(domain_id)}/delegation/approve"

        # Setup the mocked response
        responses.add(responses.POST, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.approve_delegation(domain_id, org_id)
        post_data = {
            "orgId": org_id,
        }

        self.assertEqual(True, response)
        self.assertEqual(responses.calls[0].request.body, json.dumps(post_data).encode("utf8"))

    @responses.activate
    def test_approval_failure_http_error(self):
        """The function should raise an HTTPError exception if the approval failed."""

        domain_id = 1234
        org_id = 4321
        api_url = f"{self.api_url}/{str(domain_id)}/delegation/approve"

        # Setup the mocked response
        responses.add(responses.POST, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.approve_delegation, domain_id, org_id)


class TestRejectDelegation(TestDomain):
    """Test the .reject_delegation method."""

    @responses.activate
    def test_need_params(self):
        """
        The function should raise an exception when called without required
        parameters.
        """

        domain = Domain(client=self.client)
        # missing domain_id
        self.assertRaises(TypeError, domain.reject_delegation)

    @responses.activate
    def test_reject_delegation_success(self):
        """The function should return True if the rejection succeeded."""

        domain_id = 1234
        org_id = 4321
        api_url = f"{self.api_url}/{str(domain_id)}/delegation/reject"

        # Setup the mocked response
        responses.add(responses.POST, api_url, status=200)

        domain = Domain(client=self.client)
        response = domain.reject_delegation(domain_id, org_id)
        post_data = {
            "orgId": org_id,
        }

        self.assertEqual(True, response)
        self.assertEqual(responses.calls[0].request.body, json.dumps(post_data).encode("utf8"))

    @responses.activate
    def test_reject_failure_http_error(self):
        """The function should raise an HTTPError exception if the rejection failed."""

        domain_id = 1234
        org_id = 4321
        api_url = f"{self.api_url}/{str(domain_id)}/delegation/reject"

        # Setup the mocked response
        responses.add(responses.POST, api_url, status=404)

        domain = Domain(client=self.client)

        self.assertRaises(HTTPError, domain.reject_delegation, domain_id, org_id)

[((1842, 1917), 'responses.add', 'responses.add', (['responses.GET', 'api_url'], {'json': 'self.valid_response', 'status': '(200)'}), '(responses.GET, api_url, json=self.valid_response, status=200)\n', (1855, 1917), False, 'import responses\n'), ((1936, 1983), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client', 'api_version': 'version'}), '(client=self.client, api_version=version)\n', (1942, 1983), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((2629, 2714), 'responses.add', 'responses.add', (['responses.GET', 'self.api_url'], {'json': 'self.valid_response', 'status': '(200)'}), '(responses.GET, self.api_url, json=self.valid_response, status=200\n    )\n', (2642, 2714), False, 'import responses\n'), ((2728, 2754), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (2734, 2754), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((3415, 3500), 'responses.add', 'responses.add', (['responses.GET', 'self.api_url'], {'json': 'self.valid_response', 'status': '(200)'}), '(responses.GET, self.api_url, json=self.valid_response, status=200\n    )\n', (3428, 3500), False, 'import responses\n'), ((3514, 3540), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (3520, 3540), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((4305, 4390), 'responses.add', 'responses.add', (['responses.GET', 'self.api_url'], {'json': 'self.error_response', 'status': '(400)'}), '(responses.GET, self.api_url, json=self.error_response, status=400\n    )\n', (4318, 4390), False, 'import responses\n'), ((4404, 4430), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (4410, 4430), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((4876, 4961), 'responses.add', 'responses.add', (['responses.GET', 'self.api_url'], {'json': 'self.valid_response', 'status': '(200)'}), '(responses.GET, self.api_url, json=self.valid_response, status=200\n    )\n', (4889, 4961), False, 'import responses\n'), ((4975, 5001), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (4981, 5001), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((5227, 5314), 'responses.add', 'responses.add', (['responses.GET', 'self.api_url'], {'json': 'self.valid_response[0]', 'status': '(200)'}), '(responses.GET, self.api_url, json=self.valid_response[0],\n    status=200)\n', (5240, 5314), False, 'import responses\n'), ((5382, 5408), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (5388, 5408), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((5828, 5913), 'responses.add', 'responses.add', (['responses.GET', 'self.api_url'], {'json': 'self.error_response', 'status': '(400)'}), '(responses.GET, self.api_url, json=self.error_response, status=400\n    )\n', (5841, 5913), False, 'import responses\n'), ((5927, 5953), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (5933, 5953), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((6495, 6556), 'responses.add', 'responses.add', (['responses.GET', 'api_url'], {'json': 'count', 'status': '(200)'}), '(responses.GET, api_url, json=count, status=200)\n', (6508, 6556), False, 'import responses\n'), ((6575, 6601), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (6581, 6601), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((6977, 7038), 'responses.add', 'responses.add', (['responses.GET', 'api_url'], {'json': 'count', 'status': '(200)'}), '(responses.GET, api_url, json=count, status=200)\n', (6990, 7038), False, 'import responses\n'), ((7057, 7083), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (7063, 7083), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((7549, 7624), 'responses.add', 'responses.add', (['responses.GET', 'api_url'], {'json': 'self.error_response', 'status': '(400)'}), '(responses.GET, api_url, json=self.error_response, status=400)\n', (7562, 7624), False, 'import responses\n'), ((7643, 7669), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (7649, 7669), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((8105, 8131), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (8111, 8131), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((8437, 8527), 'responses.add', 'responses.add', (['responses.GET', 'api_url'], {'json': 'self.valid_individual_response', 'status': '(200)'}), '(responses.GET, api_url, json=self.valid_individual_response,\n    status=200)\n', (8450, 8527), False, 'import responses\n'), ((8542, 8568), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (8548, 8568), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((9074, 9123), 'responses.add', 'responses.add', (['responses.GET', 'api_url'], {'status': '(404)'}), '(responses.GET, api_url, status=404)\n', (9087, 9123), False, 'import responses\n'), ((9142, 9168), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (9148, 9168), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((9491, 9517), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (9497, 9517), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((10058, 10149), 'responses.add', 'responses.add', (['responses.POST', 'self.api_url'], {'headers': "{'Location': location}", 'status': '(201)'}), "(responses.POST, self.api_url, headers={'Location': location},\n    status=201)\n", (10071, 10149), False, 'import responses\n'), ((10164, 10190), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (10170, 10190), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((10936, 11027), 'responses.add', 'responses.add', (['responses.POST', 'self.api_url'], {'headers': "{'Location': location}", 'status': '(201)'}), "(responses.POST, self.api_url, headers={'Location': location},\n    status=201)\n", (10949, 11027), False, 'import responses\n'), ((11042, 11068), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (11048, 11068), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((11754, 11839), 'responses.add', 'responses.add', (['responses.POST', 'self.api_url'], {'json': 'self.error_response', 'status': '(400)'}), '(responses.POST, self.api_url, json=self.error_response,\n    status=400)\n', (11767, 11839), False, 'import responses\n'), ((11876, 11902), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (11882, 11902), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((12437, 12522), 'responses.add', 'responses.add', (['responses.POST', 'self.api_url'], {'json': 'self.error_response', 'status': '(200)'}), '(responses.POST, self.api_url, json=self.error_response,\n    status=200)\n', (12450, 12522), False, 'import responses\n'), ((12559, 12585), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (12565, 12585), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((13139, 13194), 'responses.add', 'responses.add', (['responses.POST', 'self.api_url'], {'status': '(201)'}), '(responses.POST, self.api_url, status=201)\n', (13152, 13194), False, 'import responses\n'), ((13213, 13239), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (13219, 13239), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((13790, 13884), 'responses.add', 'responses.add', (['responses.POST', 'self.api_url'], {'headers': "{'Location': 'not a url'}", 'status': '(201)'}), "(responses.POST, self.api_url, headers={'Location':\n    'not a url'}, status=201)\n", (13803, 13884), False, 'import responses\n'), ((13899, 13925), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (13905, 13925), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((14410, 14436), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (14416, 14436), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((14774, 14826), 'responses.add', 'responses.add', (['responses.DELETE', 'api_url'], {'status': '(200)'}), '(responses.DELETE, api_url, status=200)\n', (14787, 14826), False, 'import responses\n'), ((14845, 14871), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (14851, 14871), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((15266, 15318), 'responses.add', 'responses.add', (['responses.DELETE', 'api_url'], {'status': '(404)'}), '(responses.DELETE, api_url, status=404)\n', (15279, 15318), False, 'import responses\n'), ((15337, 15363), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (15343, 15363), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((15694, 15720), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (15700, 15720), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((16073, 16122), 'responses.add', 'responses.add', (['responses.PUT', 'api_url'], {'status': '(200)'}), '(responses.PUT, api_url, status=200)\n', (16086, 16122), False, 'import responses\n'), ((16141, 16167), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (16147, 16167), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((16575, 16624), 'responses.add', 'responses.add', (['responses.PUT', 'api_url'], {'status': '(404)'}), '(responses.PUT, api_url, status=404)\n', (16588, 16624), False, 'import responses\n'), ((16643, 16669), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (16649, 16669), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((17000, 17026), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (17006, 17026), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((17376, 17425), 'responses.add', 'responses.add', (['responses.PUT', 'api_url'], {'status': '(200)'}), '(responses.PUT, api_url, status=200)\n', (17389, 17425), False, 'import responses\n'), ((17444, 17470), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (17450, 17470), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((17877, 17926), 'responses.add', 'responses.add', (['responses.PUT', 'api_url'], {'status': '(404)'}), '(responses.PUT, api_url, status=404)\n', (17890, 17926), False, 'import responses\n'), ((17945, 17971), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (17951, 17971), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((18303, 18329), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (18309, 18329), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((18730, 18780), 'responses.add', 'responses.add', (['responses.POST', 'api_url'], {'status': '(200)'}), '(responses.POST, api_url, status=200)\n', (18743, 18780), False, 'import responses\n'), ((18799, 18825), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (18805, 18825), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((19460, 19510), 'responses.add', 'responses.add', (['responses.POST', 'api_url'], {'status': '(404)'}), '(responses.POST, api_url, status=404)\n', (19473, 19510), False, 'import responses\n'), ((19529, 19555), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (19535, 19555), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((19920, 19946), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (19926, 19946), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((20373, 20425), 'responses.add', 'responses.add', (['responses.DELETE', 'api_url'], {'status': '(200)'}), '(responses.DELETE, api_url, status=200)\n', (20386, 20425), False, 'import responses\n'), ((20444, 20470), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (20450, 20470), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((21131, 21183), 'responses.add', 'responses.add', (['responses.DELETE', 'api_url'], {'status': '(404)'}), '(responses.DELETE, api_url, status=404)\n', (21144, 21183), False, 'import responses\n'), ((21202, 21228), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (21208, 21228), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((21604, 21630), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (21610, 21630), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((22033, 22083), 'responses.add', 'responses.add', (['responses.POST', 'api_url'], {'status': '(200)'}), '(responses.POST, api_url, status=200)\n', (22046, 22083), False, 'import responses\n'), ((22102, 22128), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (22108, 22128), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((22717, 22767), 'responses.add', 'responses.add', (['responses.POST', 'api_url'], {'status': '(404)'}), '(responses.POST, api_url, status=404)\n', (22730, 22767), False, 'import responses\n'), ((22786, 22812), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (22792, 22812), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((23180, 23206), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (23186, 23206), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((23607, 23657), 'responses.add', 'responses.add', (['responses.POST', 'api_url'], {'status': '(200)'}), '(responses.POST, api_url, status=200)\n', (23620, 23657), False, 'import responses\n'), ((23676, 23702), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (23682, 23702), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((24288, 24338), 'responses.add', 'responses.add', (['responses.POST', 'api_url'], {'status': '(404)'}), '(responses.POST, api_url, status=404)\n', (24301, 24338), False, 'import responses\n'), ((24357, 24383), 'cert_manager.domain.Domain', 'Domain', ([], {'client': 'self.client'}), '(client=self.client)\n', (24363, 24383), False, 'from cert_manager.domain import Domain, DomainCreationResponseError\n'), ((10511, 10532), 'json.dumps', 'json.dumps', (['post_data'], {}), '(post_data)\n', (10521, 10532), False, 'import json\n'), ((11472, 11493), 'json.dumps', 'json.dumps', (['post_data'], {}), '(post_data)\n', (11482, 11493), False, 'import json\n'), ((19079, 19100), 'json.dumps', 'json.dumps', (['post_data'], {}), '(post_data)\n', (19089, 19100), False, 'import json\n'), ((20733, 20754), 'json.dumps', 'json.dumps', (['post_data'], {}), '(post_data)\n', (20743, 20754), False, 'import json\n'), ((22354, 22375), 'json.dumps', 'json.dumps', (['post_data'], {}), '(post_data)\n', (22364, 22375), False, 'import json\n'), ((23927, 23948), 'json.dumps', 'json.dumps', (['post_data'], {}), '(post_data)\n', (23937, 23948), False, 'import json\n')]