def setUp(self): self.user = get_user_model().objects.create_user(username='******', email='*****@*****.**', password='******') self.product = f.ProductFactory(name='product1', price=2, description='the best you can have!') # Move products to the warehouse self.product.move(get_lost_and_found(), get_storage(), quantity=5) self.product.move(get_lost_and_found(), get_storage(), quantity=10)
def test_cost_sort(self): """ Test that sort by cost works correctly """ product2 = f.ProductFactory(name='product2', price=1, description='the best you can have!') api.move(get_lost_and_found(), get_storage(), product2, 1, 5000) self.client.login(username=self.user.username, password='******') response = self.client.get("/products/?&order_by=purchase_price") self.assertEqual(response.status_code, status.HTTP_200_OK) products = response.context_data['product_list'] self.assertEqual(products.count(), 2) self.assertEqual(products[0].name, 'product1')