# Path: authorizenet/cim.py
# def extract_form_data(data):
#     """
#     Convert all keys in data dictionary from underscore_format to
#     camelCaseFormat and return the new dict
#     """
#     to_upper = lambda match: match.group(1).upper()
#     to_camel = lambda x: re.sub("_([a-z])", to_upper, x)
#     return dict(map(lambda x: (to_camel(x[0]), x[1]), data.items()))
# 
# def extract_payment_form_data(data):
#     payment_data = extract_form_data(data)
#     if payment_data.get('expirationDate') is not None:
#         payment_data['expirationDate'] = \
#                 payment_data['expirationDate'].strftime('%Y-%m')
#     return payment_data
# 
# def add_profile(customer_id, payment_form_data, billing_form_data,
#                 shipping_form_data=None, customer_email=None,
#                 customer_description=None):
#     """
#     Add a customer profile with a single payment profile
#     and return a tuple of the CIMResponse, profile ID,
#     and single-element list of payment profile IDs.
# 
#     Arguments (required):
#     customer_id -- unique merchant-assigned customer identifier
#     payment_form_data -- dictionary with keys in CREDIT_CARD_FIELDS
#     billing_form_data -- dictionary with keys in BILLING_FIELDS
#     shipping_form_data -- dictionary with keys in SHIPPING_FIELDS
# 
#     Keyword Arguments (optional):
#     customer_email -- customer email
#     customer_description -- customer description
#     """
#     kwargs = {'customer_id': customer_id,
#               'credit_card_data': extract_payment_form_data(payment_form_data),
#               'billing_data': extract_form_data(billing_form_data),
#               'customer_email': customer_email,
#               'customer_description': customer_description}
#     if shipping_form_data:
#         kwargs['shipping_data'] = extract_form_data(shipping_form_data)
#     helper = CreateProfileRequest(**kwargs)
#     response = helper.get_response()
#     info = helper.customer_info
#     if response.success:
#         profile_id = helper.profile_id
#         payment_profile_ids = helper.payment_profile_ids
#         shipping_profile_ids = helper.shipping_profile_ids
#         customer_was_created.send(sender=response,
#                                   customer_id=info.get("merchantCustomerId"),
#                                   customer_description=info.get("description"),
#                                   customer_email=info.get("email"),
#                                   profile_id=helper.profile_id,
#                                   payment_profile_ids=helper.payment_profile_ids)
#     else:
#         profile_id = None
#         payment_profile_ids = None
#         shipping_profile_ids = None
#         customer_was_flagged.send(sender=response,
#                                   customer_id=customer_id)
#     return {'response': response,
#             'profile_id': profile_id,
#             'payment_profile_ids': payment_profile_ids,
#             'shipping_profile_ids': shipping_profile_ids}
# 
# Path: tests/tests/utils.py
# def xml_to_dict(node):
#     """Recursively convert minidom XML node to dictionary"""
#     node_data = {}
#     if node.nodeType == node.TEXT_NODE:
#         node_data = node.data
#     elif node.nodeType not in (node.DOCUMENT_NODE, node.DOCUMENT_TYPE_NODE):
#         node_data.update(node.attributes.items())
#     if node.nodeType not in (node.TEXT_NODE, node.DOCUMENT_TYPE_NODE):
#         for child in node.childNodes:
#             child_name, child_data = xml_to_dict(child)
#             if not child_data:
#                 child_data = ''
#             if child_name not in node_data:
#                 node_data[child_name] = child_data
#             else:
#                 if not isinstance(node_data[child_name], list):
#                     node_data[child_name] = [node_data[child_name]]
#                 node_data[child_name].append(child_data)
#         if node_data.keys() == ['#text']:
#             node_data = node_data['#text']
#     if node.nodeType == node.DOCUMENT_NODE:
#         return node_data
#     else:
#         return node.nodeName, node_data
# 
# Path: tests/tests/mocks.py

# 
# Path: tests/tests/test_data.py



from copy import deepcopy
from datetime import datetime
from django.test import TestCase
from xml.dom.minidom import parseString
from httmock import HTTMock
from authorizenet.cim import extract_form_data, extract_payment_form_data, \
    add_profile
from .utils import xml_to_dict
from .mocks import cim_url_match, customer_profile_success
from .test_data import create_profile_success
        })


class AddProfileTests(TestCase):

    """Tests for add_profile utility function"""

    def setUp(self):
        self.payment_form_data = {
            'card_number': "5586086832001747",
            'expiration_date': datetime(2020, 5, 1),
            'card_code': "123",
        }
        self.billing_form_data = {
            'first_name': "Danielle",
            'last_name': "Thompson",
            'company': "",
            'address': "101 Broadway Avenue",
            'city': "San Diego",
            'state': "CA",
            'country': "US",
            'zip': "92101",
        }
        self.request_data = deepcopy(create_profile_success)
        profile = self.request_data['createCustomerProfileRequest']['profile']
        del profile['paymentProfiles']['billTo']['phoneNumber']
        del profile['paymentProfiles']['billTo']['faxNumber']

    def test_add_profile_minimal(self):
        """Success test with minimal complexity"""

# Path: authorizenet/cim.py
# def extract_form_data(data):
#     """
#     Convert all keys in data dictionary from underscore_format to
#     camelCaseFormat and return the new dict
#     """
#     to_upper = lambda match: match.group(1).upper()
#     to_camel = lambda x: re.sub("_([a-z])", to_upper, x)
#     return dict(map(lambda x: (to_camel(x[0]), x[1]), data.items()))
# 
# def extract_payment_form_data(data):
#     payment_data = extract_form_data(data)
#     if payment_data.get('expirationDate') is not None:
#         payment_data['expirationDate'] = \
#                 payment_data['expirationDate'].strftime('%Y-%m')
#     return payment_data
# 
# def add_profile(customer_id, payment_form_data, billing_form_data,
#                 shipping_form_data=None, customer_email=None,
#                 customer_description=None):
#     """
#     Add a customer profile with a single payment profile
#     and return a tuple of the CIMResponse, profile ID,
#     and single-element list of payment profile IDs.
# 
#     Arguments (required):
#     customer_id -- unique merchant-assigned customer identifier
#     payment_form_data -- dictionary with keys in CREDIT_CARD_FIELDS
#     billing_form_data -- dictionary with keys in BILLING_FIELDS
#     shipping_form_data -- dictionary with keys in SHIPPING_FIELDS
# 
#     Keyword Arguments (optional):
#     customer_email -- customer email
#     customer_description -- customer description
#     """
#     kwargs = {'customer_id': customer_id,
#               'credit_card_data': extract_payment_form_data(payment_form_data),
#               'billing_data': extract_form_data(billing_form_data),
#               'customer_email': customer_email,
#               'customer_description': customer_description}
#     if shipping_form_data:
#         kwargs['shipping_data'] = extract_form_data(shipping_form_data)
#     helper = CreateProfileRequest(**kwargs)
#     response = helper.get_response()
#     info = helper.customer_info
#     if response.success:
#         profile_id = helper.profile_id
#         payment_profile_ids = helper.payment_profile_ids
#         shipping_profile_ids = helper.shipping_profile_ids
#         customer_was_created.send(sender=response,
#                                   customer_id=info.get("merchantCustomerId"),
#                                   customer_description=info.get("description"),
#                                   customer_email=info.get("email"),
#                                   profile_id=helper.profile_id,
#                                   payment_profile_ids=helper.payment_profile_ids)
#     else:
#         profile_id = None
#         payment_profile_ids = None
#         shipping_profile_ids = None
#         customer_was_flagged.send(sender=response,
#                                   customer_id=customer_id)
#     return {'response': response,
#             'profile_id': profile_id,
#             'payment_profile_ids': payment_profile_ids,
#             'shipping_profile_ids': shipping_profile_ids}
# 
# Path: tests/tests/utils.py
# def xml_to_dict(node):
#     """Recursively convert minidom XML node to dictionary"""
#     node_data = {}
#     if node.nodeType == node.TEXT_NODE:
#         node_data = node.data
#     elif node.nodeType not in (node.DOCUMENT_NODE, node.DOCUMENT_TYPE_NODE):
#         node_data.update(node.attributes.items())
#     if node.nodeType not in (node.TEXT_NODE, node.DOCUMENT_TYPE_NODE):
#         for child in node.childNodes:
#             child_name, child_data = xml_to_dict(child)
#             if not child_data:
#                 child_data = ''
#             if child_name not in node_data:
#                 node_data[child_name] = child_data
#             else:
#                 if not isinstance(node_data[child_name], list):
#                     node_data[child_name] = [node_data[child_name]]
#                 node_data[child_name].append(child_data)
#         if node_data.keys() == ['#text']:
#             node_data = node_data['#text']
#     if node.nodeType == node.DOCUMENT_NODE:
#         return node_data
#     else:
#         return node.nodeName, node_data
# 
# Path: tests/tests/mocks.py

# 
# Path: tests/tests/test_data.py



# Path: tests/tests/cim.py
from copy import deepcopy
from datetime import datetime
from django.test import TestCase
from xml.dom.minidom import parseString
from httmock import HTTMock
from authorizenet.cim import extract_form_data, extract_payment_form_data, \
    add_profile
from .utils import xml_to_dict
from .mocks import cim_url_match, customer_profile_success
from .test_data import create_profile_success

        })


class AddProfileTests(TestCase):

    """Tests for add_profile utility function"""

    def setUp(self):
        self.payment_form_data = {
            'card_number': "5586086832001747",
            'expiration_date': datetime(2020, 5, 1),
            'card_code': "123",
        }
        self.billing_form_data = {
            'first_name': "Danielle",
            'last_name': "Thompson",
            'company': "",
            'address': "101 Broadway Avenue",
            'city': "San Diego",
            'state': "CA",
            'country': "US",
            'zip': "92101",
        }
        self.request_data = deepcopy(create_profile_success)
        profile = self.request_data['createCustomerProfileRequest']['profile']
        del profile['paymentProfiles']['billTo']['phoneNumber']
        del profile['paymentProfiles']['billTo']['faxNumber']

    def test_add_profile_minimal(self):
        """Success test with minimal complexity"""

        @cim_url_match