def put(self, request): product = Product.from_request(request) listener = SyncProductListener() PutProductUseCase.put(product, listener) response = listener.get_response() return JsonResponse(data=response.to_dict(), status=response.status_code)
def test_from_request_with_data(self): request = RequestFactory().post('', data={ 'ean': '5738951475903', 'sale_price': 100, 'cost_price': 50, 'description': 'd', 'name': 'My test product', 'company_group_number': 1, 'hash_value': '500', }) product = Product.from_request(request) self.assertEqual('5738951475903', product.bar_code) self.assertEqual('100', product.sales_price) self.assertEqual('50', product.cost_price) self.assertEqual('d', product.description) self.assertEqual('My test product', product.name) self.assertEqual('500', product.product_number) self.assertEqual('100', product.recommended_price)
def test_from_empty_request(self): request = RequestFactory().post('', data={}) product = Product.from_request(request) self.assertIsNotNone(product)