示例#1
0
 def test_order_patch_200(self, apiclient):
     pizza = self.create_pizza((FlavourFactory(),))
     customer = CustomerFactory()
     order = self.create_order((pizza,), customer)
     pizza2 = self.create_pizza((FlavourFactory(),), size=PizzaSize.SIZE_XXL)
     data = {'pizzas': [pizza2.id]}
     response = apiclient.patch(self.detail_url(order.id), data=data)
     assert response.status_code == 200
示例#2
0
 def test_order_patch(self, apiclient):
     pizza = self.create_pizza((FlavourFactory(),))
     customer = CustomerFactory()
     order = self.create_order((pizza,), customer)
     pizza2 = self.create_pizza((FlavourFactory(name='some_flavour'),), size=PizzaSize.SIZE_XXL)
     data = {'pizzas': [pizza2.id]}
     result = apiclient.patch(self.detail_url(order.id), data=data).json()
     assert result['pizzas'][0] == pizza2.id
     pizza_obj = Pizza.objects.get(pk=pizza2.id)
     assert pizza_obj
示例#3
0
    def test_orders_list_get(self, apiclient):
        pizza = self.create_pizza((FlavourFactory(),))
        customer = CustomerFactory()
        self.create_order((pizza,), customer)
        response = apiclient.get(self.list_url)

        expected_data = [{'id': 1, 'total_sum': 15,
                         'customer': {'id': 1,
                                      'name': 'customer-0',
                                      'phone_number': '+11111111111111',
                                      'address': 'some address'},
                          'pizzas': [
                             {'id': 1,
                              'size': 'l',
                              'price': 15,
                              'flavours': [
                                  {'id': 1, 'name':
                                      'flavour-0',
                                   'added_price': 5}
                              ]
                              }
                         ],
                         'pizza_count': 1,
                         'status': 'init'}]
        assert response.json() == expected_data
示例#4
0
 def test_order_price_standard(self, apiclient):
     pizza = self.create_pizza((FlavourFactory(added_price=100),))
     # pizza base_price = 10 + flavours added price
     assert pizza.price == 110
     customer = CustomerFactory()
     order = self.create_order((pizza,), customer)
     assert order.total_sum == 110
示例#5
0
    def test_order_post(self, apiclient):
        pizza = self.create_pizza((FlavourFactory(),))
        customer = CustomerFactory()
        data = {'pizzas': [pizza.id], 'status': OrderStatus.STATUS_INIT, 'customer': customer.id}
        result = apiclient.post(self.list_url, data=data).json()

        assert result['pizzas'] == [pizza.id]
        assert result['status'] == 'init'
        assert result['customer'] == customer.id
        assert result['total_sum'] == 15
示例#6
0
 def test_order_delete(self, apiclient):
     pizza = self.create_pizza((FlavourFactory(),))
     customer = CustomerFactory()
     order = self.create_order((pizza,), customer)
     result = apiclient.get(self.detail_url(order.id)).json()
     assert result['id'] == order.id
     response = apiclient.delete(self.detail_url(order.id))
     assert response.status_code == 204
     response = apiclient.get(self.detail_url(order.id))
     assert response.status_code == 404
     assert not Order.objects.filter(pk=order.pk).exists()
示例#7
0
 def test_order_post_201(self, apiclient):
     pizza = self.create_pizza((FlavourFactory(),))
     customer = CustomerFactory()
     data = {'pizzas': [pizza.id], 'status': OrderStatus.STATUS_INIT, 'customer': customer.id}
     response = apiclient.post(self.list_url, data=data)
     assert response.status_code == 201
示例#8
0
 def test_order_price_xxl(self, apiclient):
     # XXL size has coefficient 1.5
     pizza = self.create_pizza((FlavourFactory(added_price=100),), size=PizzaSize.SIZE_XXL)
     customer = CustomerFactory()
     order = self.create_order((pizza,), customer)
     assert order.total_sum == 165