Created
November 3, 2014 11:40
-
-
Save PritishC/ef31010cda195ed58243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_0055_guest_checkout(self): | |
""" | |
Test for guest checkout. | |
""" | |
with Transaction().start(DB_NAME, USER, CONTEXT): | |
self.setup_defaults() | |
self.create_test_products() | |
app = self.get_app() | |
product1, = self.ProductTemplate.search([ | |
('name', '=', 'product 1') | |
]) | |
product2, = self.ProductTemplate.search([ | |
('name', '=', 'product 2') | |
]) | |
country = self.Country(self.available_countries[0]) | |
subdivision = country.subdivisions[0] | |
with app.test_client() as c: | |
rv = c.post( | |
'/cart/add', | |
data={ | |
'product': product1.products[0].id, | |
'quantity': 5 | |
} | |
) | |
self.assertEqual(rv.status_code, 302) | |
rv = c.get('/checkout/sign-in') | |
self.assertEqual(rv.status_code, 200) | |
# Trying to checkout with a registered email. | |
# In LN, guest checkout with registered email is allowed. | |
# Should redirect to shipping. | |
rv = c.post( | |
'/checkout/sign-in', | |
data={ | |
'email': 'email@example.com' | |
} | |
) | |
self.assertEqual(rv.status_code, 302) | |
self.assertIn( | |
'shipping', | |
rv.location | |
) | |
with app.test_client() as c: | |
# Now with a new email. | |
rv = c.post( | |
'/cart/add', | |
data={ | |
'product': product1.products[0].id, | |
'quantity': 5 | |
} | |
) | |
self.assertEqual(rv.status_code, 302) | |
rv = c.get('/checkout/sign-in') | |
self.assertEqual(rv.status_code, 200) | |
rv = c.post( | |
'/checkout/sign-in', | |
data={ | |
'email': 'new@example.com', | |
'checkout_mode': 'guest' | |
} | |
) | |
self.assertEqual(rv.status_code, 302) | |
self.assertTrue( | |
rv.location.endswith('/checkout/shipping-address') | |
) | |
# Shipping address page should render. | |
rv = c.get('/checkout/shipping-address') | |
self.assertEqual(rv.status_code, 200) | |
# Copied from nereid-checkout - adding shipping address. | |
rv = c.post( | |
'/checkout/shipping-address', | |
data={ | |
'name': 'Sharoon Thomas', | |
'street': 'Biscayne Boulevard', | |
'streetbis': 'Apt. 1906, Biscayne Park', | |
'zip': '33137', | |
'city': 'Miami', | |
'phone': '1234567890', | |
'country': country.id, | |
'subdivision': subdivision.id, | |
} | |
) | |
self.assertEqual(rv.status_code, 302) | |
self.assertTrue( | |
rv.location.endswith('/checkout/delivery-method') | |
) | |
# Delivery method. | |
mailclass, = self.EndiciaMailclass.create([{ | |
"name": "Priority Mail", | |
"value": "Priority", | |
"method_type": "domestic", | |
}]) | |
rv = c.post( | |
'/checkout/delivery-method', | |
data={'carrier_json': json.dumps({ | |
'carrier': self.carrier.id, | |
'endicia_mailclass': mailclass.id, | |
})} | |
) | |
self.assertEqual(rv.status_code, 302) | |
self.assertTrue( | |
rv.location.endswith('/checkout/payment') | |
) | |
with Transaction().set_context(company=self.company.id): | |
self._create_auth_net_gateway_for_site() | |
# Try to pay using credit card | |
rv = c.post( | |
'/checkout/payment', | |
data={ | |
'owner': 'Joe Blow', | |
'number': '4111111111111111', | |
'expiry_year': '2018', | |
'expiry_month': '01', | |
'cvv': '911', | |
'add_card_to_profiles': 'y', | |
'use_shipment_address': 'y', | |
} | |
) | |
self.assertEqual(rv.status_code, 302) | |
print(rv.location) | |
print(rv.data) | |
self.assertTrue('/order/' in rv.location) | |
self.assertTrue('access_code' in rv.location) | |
sale, = self.Sale.search([('state', '=', 'confirmed')]) | |
payment_transaction, = sale.gateway_transactions | |
self.assertEqual(payment_transaction.amount, sale.total_amount) | |
rv = c.get('/order/{0}'.format(sale.id)) | |
self.assertEqual(rv.status_code, 302) # Orders page redirect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment