def test_succesful_order_with_flagged_payment_invalid_receiver_email(self): """Tests a succesful paypal transaction that is flagged with an invalide receiver email """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country.objects.get(code="ie") order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS incorrect_receiver_email_update = {"receiver_email": "*****@*****.**"} post_params.update(incorrect_receiver_email_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_COMPLETED) self.assertEqual(ipn_obj.flag, True) self.assertEqual(ipn_obj.flag_info, u'Invalid receiver_email. ([email protected])') order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FLAGGED)
def test_successful_order_transaction_created(self): """Tests we have a transaction associated with an order after payment """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.flag, False) order = Order.objects.all()[0] self.assertEqual(order.state, PAID)
def setUp(): country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country ) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country ) order = Order( invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid ) self.assertEqual(order.state, SUBMITTED) order.save()
def test_failed_order_transaction_created(self): """Tests a failed paypal transaction """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'INVALID' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS payment_status_update = {"payment_status": ST_PP_DENIED} post_params.update(payment_status_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_DENIED) self.assertEqual(ipn_obj.flag, True) order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FAILED)
def test_succesful_order_with_flagged_payment_invalid_receiver_email(self): """Tests a succesful paypal transaction that is flagged with an invalide receiver email """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country(code="ie", name="Ireland") country.save() order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS incorrect_receiver_email_update = { "receiver_email": "*****@*****.**" } post_params.update(incorrect_receiver_email_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_COMPLETED) self.assertEqual(ipn_obj.flag, True) self.assertEqual( ipn_obj.flag_info, u'Invalid receiver_email ([email protected]).') order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FLAGGED)
def test_failed_order_transaction_created(self): """Tests a failed paypal transaction """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'INVALID' PayPalIPN._postback = fake_postback country = Country.objects.get(code="ie") order = Order(invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS payment_status_update = {"payment_status": ST_PP_DENIED} post_params.update(payment_status_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_DENIED) self.assertEqual(ipn_obj.flag, True) order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FAILED)
def test_correct_address_fields_set_on_checkout(self): country = Country.objects.get(code="us") order = Order(invoice_firstname="bill", invoice_lastname="blah", invoice_line1="bills house", invoice_line2="bills street", invoice_city="bills town", invoice_state="bills state", invoice_code="bills zip code", invoice_country=country, shipping_country=country, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() url = get_paypal_link_for_order(order) # test unique id self.assertEqual(('custom=' + self.uuid) in url, True) # test address stuff self.assertEqual('first_name=bill' in url, True) self.assertEqual('last_name=blah' in url, True) self.assertEqual('address1=bills house' in url, True) self.assertEqual('address2=bills street' in url, True) self.assertEqual('state=bills state' in url, True) self.assertEqual('zip=bills zip code' in url, True)
def test_calc_hash(self): order = Order() order.price = 875.18 order.customer_email = '*****@*****.**' order.get_name = Mock(return_value='Order omschrijving') order.number = '3418683' hash = calculate_hash(order=order, valid_util='2014-04-21T12:57:04Z') self.assertEqual("b4c2204290b720f1e1dd57cf2bdf7cddecbf2c07", hash)
def test_failed_order_transaction_created(self): """Tests a failed moip transaction """ def fake_postback(self, test=True): """Perform a Fake MoIP NIT Postback request.""" return 'INVALID' MoipNIT._postback = fake_postback country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(MoipNIT.objects.all()), 0) self.assertEqual(len(MoipOrderTransaction.objects.all()), 0) post_params = self.NIT_POST_PARAMS payment_status_update = {"payment_status": ST_MOIP_DENIED} post_params.update(payment_status_update) response = self.client.post(reverse('moip-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(MoipNIT.objects.all()), 1) self.assertEqual(len(MoipOrderTransaction.objects.all()), 1) ipn_obj = MoipNIT.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_MOIP_DENIED) self.assertEqual(ipn_obj.flag, True) order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FAILED)
def test_failed_order_transaction_created(self): """Tests a failed paypal transaction """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'INVALID' PayPalIPN._postback = fake_postback country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS payment_status_update = {"payment_status": ST_PP_DENIED} post_params.update(payment_status_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_DENIED) self.assertEqual(ipn_obj.flag, True) order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FAILED)
def test_succesful_order_with_flagged_payment_invalid_receiver_email(self): """Tests a succesful moip transaction that is flagged with an invalide receiver email """ def fake_postback(self, test=True): """Perform a Fake MoIP NIT Postback request.""" return 'VERIFIED' MoipNIT._postback = fake_postback country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(MoipNIT.objects.all()), 0) self.assertEqual(len(MoipOrderTransaction.objects.all()), 0) post_params = self.NIT_POST_PARAMS incorrect_receiver_email_update = {"receiver_email": "*****@*****.**"} post_params.update(incorrect_receiver_email_update) response = self.client.post(reverse('moip-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(MoipNIT.objects.all()), 1) self.assertEqual(len(MoipOrderTransaction.objects.all()), 1) ipn_obj = MoipNIT.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_MOIP_COMPLETED) self.assertEqual(ipn_obj.flag, True) self.assertEqual(ipn_obj.flag_info, u'Invalid receiver_email. ([email protected])') order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FLAGGED)
def test_succesful_order_with_flagged_payment_invalid_receiver_email(self): """Tests a succesful paypal transaction that is flagged with an invalide receiver email """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS incorrect_receiver_email_update = {"receiver_email": "*****@*****.**"} post_params.update(incorrect_receiver_email_update) response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.payment_status, ST_PP_COMPLETED) self.assertEqual(ipn_obj.flag, True) self.assertEqual(ipn_obj.flag_info, u'Invalid receiver_email. ([email protected])') order = Order.objects.all()[0] self.assertEqual(order.state, PAYMENT_FLAGGED)
def test_successful_order_transaction_created(self): """Tests we have a transaction associated with an order after payment """ def fake_postback(self, test=True): """Perform a Fake PayPal IPN Postback request.""" return 'VERIFIED' PayPalIPN._postback = fake_postback country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(PayPalIPN.objects.all()), 0) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 0) post_params = self.IPN_POST_PARAMS response = self.client.post(reverse('paypal-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(PayPalIPN.objects.all()), 1) self.assertEqual(len(PayPalOrderTransaction.objects.all()), 1) ipn_obj = PayPalIPN.objects.all()[0] self.assertEqual(ipn_obj.flag, False) order = Order.objects.all()[0] self.assertEqual(order.state, PAID)
def test_successful_order_transaction_created(self): """Tests we have a transaction associated with an order after payment """ def fake_postback(self, test=True): """Perform a Fake MoIP NIT Postback request.""" return 'VERIFIED' MoipNIT._postback = fake_postback country = Country.objects.get(code="ie") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) order.save() self.assertEqual(len(MoipNIT.objects.all()), 0) self.assertEqual(len(MoipOrderTransaction.objects.all()), 0) post_params = self.NIT_POST_PARAMS response = self.client.post(reverse('moip-ipn'), post_params) self.assertEqual(response.status_code, 200) self.assertEqual(len(MoipNIT.objects.all()), 1) self.assertEqual(len(MoipOrderTransaction.objects.all()), 1) ipn_obj = MoipNIT.objects.all()[0] self.assertEqual(ipn_obj.flag, False) order = Order.objects.all()[0] self.assertEqual(order.state, PAID)
def test_correct_address_fields_set_on_checkout(self): country = Country.objects.get(code="us") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) pm = PaymentMethod.objects.create( active=True, module="lfs_moip.MoipProcessor", ) order.payment_method = pm order.save() url = order.get_pay_link(None) # test unique id self.assertEqual(('custom=' + self.uuid) in url, True) # test address stuff self.assertEqual('first_name=bill' in url, True) self.assertEqual('last_name=blah' in url, True) self.assertEqual('address1=bills house' in url, True) self.assertEqual('address2=bills street' in url, True) self.assertEqual('state=bills state' in url, True) self.assertEqual('zip=bills zip code' in url, True)
def test_ga_ecommerce_tracking(self): """ """ shop = lfs.core.utils.get_default_shop() shop.google_analytics_id = "" shop.ga_site_tracking = False shop.ga_ecommerce_tracking = False shop.save() session = SessionStore() rf = RequestFactory() request = rf.get('/') request.session = session template = get_template_from_string( """{% load lfs_tags %}{% google_analytics_ecommerce %}""") content = template.render(Context({"request": request})) self.failIf(content.find("pageTracker") != -1) # Enter a google_analytics_id shop.google_analytics_id = "UA-XXXXXXXXXX" shop.save() # Simulating a new request rf = RequestFactory() request = rf.get('/') request.session = session # But this is not enough content = template.render(Context({"request": request})) self.failIf(content.find("pageTracker") != -1) # It has to be activated first shop.ga_ecommerce_tracking = True shop.save() # Simulating a new request rf = RequestFactory() request = rf.get('/') request.session = session # But this is still not enough content = template.render(Context({"request": request})) self.failIf(content.find("pageTracker") != -1) # There has to be an order within the session session["order"] = Order() # Now it works and "pageTracker" is found content = template.render(Context({"request": request})) self.failIf(content.find("_trackPageview") == -1)
def test_correct_address_fields_set_on_checkout(self): country = Country.objects.get(code="us") shipping_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) invoice_address = Address.objects.create( firstname="bill", lastname="blah", line1="bills house", line2="bills street", city="bills town", state="bills state", zip_code="bills zip code", country=country) order = Order(invoice_address=invoice_address, shipping_address=shipping_address, uuid=self.uuid) self.assertEqual(order.state, SUBMITTED) pm = PaymentMethod.objects.create( active=True, module="lfs_paypal.PayPalProcessor", ) order.payment_method = pm order.save() url = order.get_pay_link(None) # test unique id self.assertEqual(('custom=' + self.uuid) in url, True) # test address stuff self.assertEqual('first_name=bill' in url, True) self.assertEqual('last_name=blah' in url, True) self.assertEqual('address1=bills house' in url, True) self.assertEqual('address2=bills street' in url, True) self.assertEqual('state=bills state' in url, True) self.assertEqual('zip=bills zip code' in url, True)