def init_db(): user = factories.UserFactory(email='*****@*****.**', username='******') order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email='*****@*****.**', username='******', is_staff=True) employees, _ = Group.objects.get_or_create(name='Employees') cs_user.groups.add(employees) return user, order, cs_user
def init_db(): user = factories.UserFactory(email="*****@*****.**", first_name="John", last_name="Smith") order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email="*****@*****.**", first_name="Adam", last_name="Ford", is_staff=True) employees, _ = Group.objects.get_or_create(name="Employees") cs_user.groups.add(employees) return user, order, cs_user
def test_create_order_works(self): p1 = factories.ProductFactory() p2 = factories.ProductFactory() user1 = factories.UserFactory() billing = factories.AddressFactory(user=user1) shipping = factories.AddressFactory(user=user1) basket = models.Basket.objects.create(user=user1) models.BasketLine.objects.create(basket=basket, product=p1) models.BasketLine.objects.create(basket=basket, product=p2) with self.assertLogs("main.models", level="INFO") as cm: order = basket.create_order(billing, shipping) self.assertGreaterEqual(len(cm.output), 1) order.refresh_from_db() self.assertEqual(order.user, user1) self.assertEqual(order.billing_address1, billing.address1) self.assertEqual(order.shipping_address1, shipping.address1) self.assertEqual(order.lines.all().count(), 2) lines = order.lines.all() self.assertEqual(lines[0].product, p1) self.assertEqual(lines[1].product, p2)
def test_orderlines_are_saved(self): p1 = factories.ProductFactory() a1 = factories.AddressFactory() user1 = factories.UserFactory() order_data = { "status":10, "billing_name":"test1", "billing_address1":a1.address1, "billing_address2":a1.address2, "billing_zip_code":a1.zip_code, "billing_city":a1.city, "billing_country":a1.country, "shipping_name":"hello", "shipping_address1": a1.address1, "shipping_address2": a1.address2, "shipping_zip_code": a1.zip_code, "shipping_city": a1.city, "shipping_country": a1.country, } order = models.Order.objects.create( user=user1, **order_data ) orderline = models.OrderLine.objects.create( product=p1, order=order, status=10 ) orderline.status=30 orderline.save() orderline.refresh_from_db() self.assertEqual(order.status,30)
def test_with_other_user_debit(self): user = factories.UserFactory(username='******', password='******') debit = factories.DebitFactory(user=user, name='shop') response = self.client.get( reverse('main:customer-log', kwargs={'debit_pk': debit.id})) self.assertEqual(response.status_code, 403)
def test_mobile_flow(self): user = factories.UserFactory(email="*****@*****.**") token = Token.objects.get(user=user) self.client.credentials(HTTP_AUTHORIZATION="Token " + token.key) orders = factories.OrderFactory.create_batch(2, user=user) a = factories.ProductFactory(name="The book of A", active=True, price=12.00) b = factories.ProductFactory(name="The B Book", active=True, price=14.00) factories.OrderLineFactory.create_batch(2, order=orders[0], product=a) factories.OrderLineFactory.create_batch(2, order=orders[1], product=b) response = self.client.get(reverse("mobile_my_orders")) self.assertEqual(response.status_code, status.HTTP_200_OK) expected = [ { "id": orders[1].id, "image": None, "price": 28.0, "summary": "2 x The B Book", }, { "id": orders[0].id, "image": None, "price": 24.0, "summary": "2 x The book of A", }, ] self.assertEqual(response.json(), expected)
def init_db(): user = factories.UserFactory( email='*****@*****.**', first_name='Top', last_name='Secret', ) order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email='*****@*****.**', first_name='Off', last_name='Records', is_staff=True, ) employees, _ = Group.objects.get_or_create(name='Employees') cs_user.groups.add(employees) return user, order, cs_user
def init_db(): user = factories.UserFactory( email="*****@*****.**", first_name="John", last_name="Doe", ) order = factories.OrderFactory() return user, order
def init_db(): user = factories.UserFactory( email="*****@*****.**", first_name="John", last_name="Smith", ) order = factories.OrderFactory() return user, order
def init_db(): """ Initialize required <users> & <one 'order'> """ user = factories.UserFactory( email="*****@*****.**", first_name="John", last_name="Doe", ) order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email="*****@*****.**", first_name="Almighty", last_name="God", is_staff=True, ) employees, _ = Group.objects.get_or_create(name="Employees") cs_user.groups.add(employees) return user, order, cs_user
def test_mobile_flow(self): user = factories.UserFactory(email='*****@*****.**') token = Token.objects.get(user=user) self.client.credentials( HTTP_AUTHORIZATION='Token ' + token.key ) orders = factories.OrderFactory.create_batch( 2, user=user ) a = factories.ProductFactory( name='Yet another book', active=True, price=18.00 ) b = factories.ProductFactory( name='Masterpiece', active=True, price=12.00 ) factories.OrderLineFactory.create_batch( 2, order=orders[0], product=a ) factories.OrderLineFactory.create_batch( 2, order=orders[1], product=b ) response = self.client.get(reverse('mobile_my_orders')) self.assertEqual( response.status_code, status.HTTP_200_OK ) expected = [ { 'id': orders[1].id, 'image': None, 'summary': '2 x Masterpiece', 'price': 24.0, }, { 'id': orders[0].id, 'image': None, 'summary': '2 x Yet another book', 'price': 36.0, }, ] self.assertEqual(response.json(), expected)
def test_mobile_flow(self): user = factories.UserFactory() token = Token.objects.get(user=user) self.client.credentials(HTTP_AUTHORIZATION="Token " + token.key) a = factories.ProductFactory(title='Sausage', slug='sausage', is_active=True, price=12.00) b = factories.ProductFactory(title='meat', slug='meat', is_active=True, price=14.00) order_item_a = factories.OrderItemFactory.create_batch(1, quantity=2, item=a, user=user) print('orderitem_a:', order_item_a[0].id) order_item_b = factories.OrderItemFactory.create_batch(1, quantity=2, item=b, user=user) print('orderitem_b:', order_item_b) response = self.client.get(reverse('me2ushop:mobile_my_orders')) self.assertEqual(response.status_code, status.HTTP_200_OK) expected = [ { 'id': order_item_b[0].id, 'image': None, 'price': 28.0, 'summary': '2 x meat', }, { 'id': order_item_a[0].id, 'image': None, 'price': 24.0, 'summary': '2 x Sausage', }, ] self.assertEqual(response.json(), expected)
def test_create_order_works(self): """ """ prod_one = factories.ProductFactory() prod_two = factories.ProductFactory() user_one = factories.UserFactory() billing = factories.AddressFactory(user=user_one) shipping = factories.AddressFactory(user=user_one) basket = models.Basket.objects.create(user=user_one) models.BasketLine.objects.create(basket=basket, product=prod_one) models.BasketLine.objects.create(basket=basket, product=prod_two) with self.assertLogs("main.models", level="INFO") as cm: order = basket.create_order(billing, shipping) self.assertGreaterEqual(len(cm.output), 1) order.refresh_from_db() # user_one's order self.assertEquals(order.user, user_one) # correct billing|shipping addresses self.assertEquals(order.billing_address1, billing.address1) self.assertEquals(order.shipping_address1, shipping.address1) # two products while checking out self.assertEquals(order.lines.all().count(), 2) # same as the prev line, just break it down as a list lines = order.lines.all() self.assertEquals(lines[0].product, prod_one) self.assertEquals(lines[1].product, prod_two)
def init_db(): user = factories.UserFactory(email='*****@*****.**', username='******') order = factories.OrderFactory() return user, order
def init_db(): user = factories.UserFactory(email="*****@*****.**") order = factories.OrderFactory(user=user) return user, order
def init_db(): user = factories.UserFactory(username='******', email='*****@*****.**') order = factories.OrderFactory(user=user) return user, order
def setUp(self): self.user = factories.UserFactory(username='******', password='******') self.client.force_login(self.user)
def setUp(self): self.client = APIClient() self.user = factories.UserFactory() self.client.force_authenticate(self.user)