def test_add_one_product_creates_stock_only_for_composite_1(self): self.product_1.move(from_location=self.lost_and_found, to_location=self.storage, quantity=1, price_multiplier=2) self.assertEqual(get_storage_quantity(product=self.composite_1), 1) self.assertEqual(get_storage_price(product=self.composite_1).amount, 2) self.assertEqual(get_storage_quantity(product=self.composite_2), 0) self.assertEqual(get_storage_quantity(product=self.product_1), 1)
def test_move_composite_right_quantities(self): self.product_1.move(from_location=self.lost_and_found, to_location=self.storage, quantity=2) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage, quantity=3) self.composite_2.move(from_location=self.storage, to_location=self.customer) self.assertEqual(get_storage_quantity(product=self.composite_2), 0) self.assertEqual(get_storage_quantity(product=self.product_1), 0) self.assertEqual(get_storage_quantity(product=self.product_2), 0) self.assertEqual(get_customer_quantity(product=self.composite_2), 1)
def test_remove_products_update_composite_quantity_correctly(self): self.product_1.move(from_location=self.lost_and_found, to_location=self.storage, quantity=2) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage, quantity=3) self.assertEqual(get_storage_quantity(product=self.composite_1), 2) self.assertEqual(get_storage_quantity(product=self.composite_2), 1) self.product_1.move(from_location=self.storage, to_location=self.output) self.assertEqual(get_storage_quantity(product=self.composite_1), 1) self.assertEqual(get_storage_quantity(product=self.composite_2), 0)
def test_move_composites_from_storage_to_output(self): self.product_1.move(from_location=self.lost_and_found, to_location=self.storage, quantity=2) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage, quantity=4) self.assertEqual(get_storage_quantity(product=self.composite_1), 2) self.assertEqual(get_storage_quantity(product=self.composite_2), 1) self.composite_1.move(from_location=self.storage, to_location=self.output) self.assertEqual(get_storage_quantity(product=self.composite_1), 1) self.assertEqual(get_storage_quantity(product=self.composite_2), 0) self.assertEqual(get_storage_quantity(product=self.product_1), 1)
def test_add_more_products_creates_correct_stocks_with_single_movement(self): self.product_1.move(from_location=self.lost_and_found, to_location=self.storage, quantity=2) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage, quantity=3) self.assertEqual(get_storage_quantity(product=self.composite_1), 2) self.assertEqual(get_storage_quantity(product=self.composite_2), 1) self.assertEqual(get_storage_price(product=self.composite_1).amount, 1) self.assertEqual(get_storage_price(product=self.composite_2).amount, 5) self.assertEqual(get_storage_quantity(product=self.product_1), 2) self.assertEqual(get_storage_quantity(product=self.product_2), 3)
def test_move_composites_not_negative_quantities(self): self.product_1.move(from_location=self.lost_and_found, to_location=self.storage) self.product_1.move(from_location=self.lost_and_found, to_location=self.storage) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage) self.product_2.move(from_location=self.lost_and_found, to_location=self.storage) self.assertEqual(get_storage_quantity(product=self.composite_1), 2) self.assertEqual(get_storage_quantity(product=self.composite_2), 1) self.composite_1.move(from_location=self.storage, to_location=self.output, quantity=3) self.assertEqual(get_storage_quantity(product=self.composite_1), 0) self.assertEqual(get_storage_quantity(product=self.composite_2), 0) self.assertEqual(get_storage_quantity(product=self.product_1), -1)
def is_highly_available(self): """ Return True when products stock has more elements than published one """ try: product_quantity = api.get_storage_quantity(self.product) except models.ObjectDoesNotExist: product_quantity = 0 for publishing in self.publishings.all(): if publishing.is_active(): if product_quantity - publishing.available_units > 2: return True return False
def is_unavailable(self): """ Returns True when products stock cannot satisfy published listings """ try: product_quantity = api.get_storage_quantity(self.product) except models.ObjectDoesNotExist: product_quantity = 0 for publishing in self.publishings.all(): if publishing.is_active(): if product_quantity < publishing.available_units: return True return False
def test_move_composite_with_not_allowed_locations(self): self.composite_1.move(from_location=self.lost_and_found, to_location=self.storage) self.assertEqual(get_storage_quantity(product=self.composite_1), 0) self.assertEqual(get_storage_quantity(product=self.composite_2), 0) self.assertEqual(get_storage_quantity(product=self.product_1), 0) self.assertEqual(get_storage_quantity(product=self.product_2), 0)
def available_units(self): """ Returns available units of the whole listing in the storage """ return api.get_storage_quantity(self.product)