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)
 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,
     })
Exemple #3
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)
Exemple #4
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()
Exemple #5
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)
Exemple #6
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)