Skip to content

Commit

Permalink
Verify correct request data sent for generic view
Browse files Browse the repository at this point in the history
  • Loading branch information
treyhunner committed Jun 11, 2013
1 parent 706533f commit 187ae59
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 60 deletions.
103 changes: 57 additions & 46 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@
from .mocks import cim_url_match, success_response


create_profile_success_data = {
'createCustomerProfileRequest': {
'xmlns': 'AnetApi/xml/v1/schema/AnetApiSchema.xsd',
'profile': {
'merchantCustomerId': '42',
'paymentProfiles': {
'billTo': {
'firstName': 'Danielle',
'lastName': 'Thompson',
'company': '',
'address': '101 Broadway Avenue',
'city': 'San Diego',
'state': 'CA',
'zip': '92101',
'country': 'US'
},
'payment': {
'creditCard': {
'cardCode': '123',
'cardNumber': "5586086832001747",
'expirationDate': '2020-05'
}
}
}
},
'merchantAuthentication': {
'transactionKey': 'key',
'name': 'loginid'
},
}
}


class PaymentProfileCreationTests(LiveServerTestCase):

def test_create_new_customer_get(self):
Expand All @@ -29,21 +62,29 @@ def test_create_new_customer_post_error(self):
self.assertIn("City", response.content)

def test_create_new_customer_post_success(self):
create_user(username='billy', password='password')
@cim_url_match
def create_customer_success(url, request):
request_xml = parseString(request.body)
self.assertEqual(xml_to_dict(request_xml),
create_profile_success_data)
return success_response.format('createCustomerProfileResponse')
create_user(id=42, username='billy', password='password')
self.client.login(username='billy', password='password')
response = self.client.post('/customers/create', {
'card_number': "5586086832001747",
'expiration_date_0': "4",
'expiration_date_1': "2020",
'card_code': "123",
'first_name': "Billy",
'last_name': "Monaco",
'address': "101 Broadway Ave",
'city': "San Diego",
'state': "CA",
'country': "US",
'zip': "92101",
}, follow=True)
self.maxDiff = None
with HTTMock(create_customer_success):
response = self.client.post('/customers/create', {
'card_number': "5586086832001747",
'expiration_date_0': "5",
'expiration_date_1': "2020",
'card_code': "123",
'first_name': "Danielle",
'last_name': "Thompson",
'address': "101 Broadway Avenue",
'city': "San Diego",
'state': "CA",
'country': "US",
'zip': "92101",
}, follow=True)
self.assertIn("success", response.content)


Expand Down Expand Up @@ -74,7 +115,7 @@ class AddProfileTests(TestCase):

def setUp(self):
self.payment_form_data = {
'card_number': "1111222233334444",
'card_number': "5586086832001747",
'expiration_date': datetime(2020, 5, 1),
'card_code': "123",
}
Expand All @@ -88,37 +129,7 @@ def setUp(self):
'country': "US",
'zip': "92101",
}
self.request_data = {
'createCustomerProfileRequest': {
'xmlns': 'AnetApi/xml/v1/schema/AnetApiSchema.xsd',
'profile': {
'merchantCustomerId': '42',
'paymentProfiles': {
'billTo': {
'firstName': 'Danielle',
'lastName': 'Thompson',
'company': '',
'address': '101 Broadway Avenue',
'city': 'San Diego',
'state': 'CA',
'zip': '92101',
'country': 'US'
},
'payment': {
'creditCard': {
'cardCode': '123',
'cardNumber': '1111222233334444',
'expirationDate': '2020-05'
}
}
}
},
'merchantAuthentication': {
'transactionKey': 'key',
'name': 'loginid'
},
}
}
self.request_data = create_profile_success_data

def test_add_profile_minimal(self):
"""Success test with minimal complexity"""
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib.auth.models import User


def create_user(username='', password=''):
def create_user(id=None, username='', password=''):
user = User(username=username)
user.id = id
user.set_password(password)
user.save()
return user
Expand Down
13 changes: 0 additions & 13 deletions tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@
from authorizenet.customers.views import PaymentProfileCreationView


from httmock import HTTMock
from .mocks import cim_url_match, success_response


@cim_url_match
def create_customer_success(url, request):
return success_response.format('createCustomerProfileResponse')


class CreateCustomerView(PaymentProfileCreationView):

def get_success_url(self):
return '/success'

def form_valid(self, *args, **kwargs):
with HTTMock(create_customer_success):
return super(CreateCustomerView, self).form_valid(*args, **kwargs)


def success_view(request):
return HttpResponse("success")

0 comments on commit 187ae59

Please sign in to comment.