Ejemplo n.º 1
0
 def test_to_dict(self):
     product = Product(bar_code='5738951475903',
                       cost_price=50,
                       description='d',
                       name='My test product',
                       product_group=ProductGroup(product_group_number=1),
                       product_number='500',
                       recommended_price=50,
                       sales_price=100,
                       barred=False)
     expected = {
         'barCode': '5738951475903',
         'costPrice': 50,
         'description': 'd',
         'name': 'My test product',
         'productGroup': {
             'productGroupNumber': 1
         },
         'productNumber': '500',
         'recommendedPrice': 50,
         'salesPrice': 100,
         'inventory': {
             'recommendedCostPrice': 50
         },
         'barred': False
     }
     self.assertDictEqual(expected, product.to_dict())
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    def block(product_number, listener):
        get_api = GetProduct()
        response = get_api.get(product_number)
        if response.status_code == 200:
            product = json.loads(response.content.decode('utf-8'))
            inventory = product['inventory']
            try:
                in_stock = int(inventory['inStock'])
                ordered_from_suppliers = int(inventory['orderedFromSuppliers'])
                ordered_by_customers = int(inventory['orderedByCustomers'])
                if in_stock == 0 and ordered_by_customers == 0 and ordered_from_suppliers == 0:
                    _product = Product.from_dict(product)
                    _product.barred = True
                    response = PutProduct().put(_product)
                    if response.status_code == 200:
                        listener.on_success()
                        return
                    else:
                        listener.on_unknown_error(response.status_code, response.content)
                        return
                else:
                    listener.on_product_in_stock()
                    return
            except ValueError:
                listener.on_unable_to_convert_to_int()
                return

        elif response.status_code == 404:
            listener.on_does_not_exist()
        else:
            listener.on_unknown_error(response.status_code, response.content)
Ejemplo n.º 4
0
 def setUp(self) -> None:
     self.product = Product.from_dict({
         'barCode': '5738951475903',
         'costPrice': 50,
         'description': 'd',
         'name': 'My test product',
         'productGroup': {
             'productGroupNumber': 1
         },
         'productNumber': 'h123iqwjd2enwef',
         'recommendedPrice': 50,
         'salesPrice': 20.3,
         'barred': False,
     })
Ejemplo n.º 5
0
 def test_can_convert_barred_to_boolean(self):
     product = Product.from_dict({
         'barCode': '5738951475903',
         'costPrice': '10',
         'description': 'd',
         'name': 'My test product',
         'productGroup': {
             'productGroupNumber': 1
         },
         'productNumber': '500',
         'recommendedPrice': '100',
         'salesPrice': 'illegal',  # illegal price,
         'barred': 'True',
     })
     self.assertTrue(product.barred)
Ejemplo n.º 6
0
 def test_when_cost_price_is_not_float_Should_raise_error(self):
     product = Product.from_dict({
         'barCode': '5738951475903',
         'costPrice': 'illegal',  # illegal price
         'description': 'd',
         'name': 'My test product',
         'productGroup': {
             'productGroupNumber': 1
         },
         'productNumber': '500',
         'recommendedPrice': '100',
         'salesPrice': 100,
         'barred': False,
     })
     with self.assertRaises(ProductValidationError):
         product.validate()
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def test_when_valid_validation_Should_have_converted_fields_to_correct_types(
         self):
     product = Product.from_dict({
         'barCode': '5738951475903',
         'costPrice': '10',
         'description': 'd',
         'name': 'My test product',
         'productGroup': {
             'productGroupNumber': '1'
         },
         'productNumber': '500',
         'recommendedPrice': '100',
         'salesPrice': '2.2',
         'barred': False,
     })
     product.validate()
     self.assertEqual(10.00, product.cost_price)
     self.assertEqual(1, product.product_group.product_group_number)
     self.assertEqual(100.00, product.recommended_price)
     self.assertEqual(2.20, product.sales_price)
     self.assertFalse(product.barred)
Ejemplo n.º 9
0
 def test_from_dict(self):
     product = Product.from_dict({
         'barCode': '5738951475903',
         'costPrice': 50,
         'description': 'd',
         'name': 'My test product',
         'productGroup': {
             'productGroupNumber': 1
         },
         'productNumber': '500',
         'recommendedPrice': 50,
         'salesPrice': 100,
         'barred': False
     })
     self.assertEqual('5738951475903', product.bar_code)
     self.assertEqual(50, product.cost_price)
     self.assertEqual('d', product.description)
     self.assertEqual('My test product', product.name)
     self.assertDictEqual(
         ProductGroup(1).to_dict(), product.product_group.to_dict())
     self.assertEqual('500', product.product_number)
     self.assertEqual(50, product.recommended_price)
     self.assertEqual(100, product.sales_price)
Ejemplo n.º 10
0
 def post(self, product: Product):
     response = requests.post(url=self.ECONOMIC_URL,
                              data=product.to_json(),
                              headers=self.headers)
     return response
Ejemplo n.º 11
0
 def test_from_empty_request(self):
     request = RequestFactory().post('', data={})
     product = Product.from_request(request)
     self.assertIsNotNone(product)
Ejemplo n.º 12
0
 def put(self, product: Product):
     self.ECONOMIC_URL += '/' + product.product_number
     response = requests.put(url=self.ECONOMIC_URL,
                             data=product.to_json(),
                             headers=self.headers)
     return response