def test_get_subtotal_error_with_catalogue_empty(self): test_pricer = basket_pricer.BasketPricer() filepath_basket = "shopping_basket/data/basket_test_1.txt" dict_basket = helpers.basket_textfile_to_dict(filepath_basket) dict_catalog = {} with self.assertRaises(NotImplementedError): test_pricer.calculate_subtotal(dict_basket, dict_catalog)
def test_get_basket_from_textfile(self): filepath = "shopping_basket/data/basket_test_1.txt" basket = {"Baked Beans": 4, "Biscuits": 1} dict_basket = helpers.basket_textfile_to_dict(filepath) self.assertEqual( dict_basket, basket, "The basket is not correct.", )
def test_get_all_totals_error__with_empty_offers(self): test_pricer = basket_pricer.BasketPricer() filepath_basket = "shopping_basket/data/basket_test_1.txt" filepath_catalogue = "shopping_basket/data/catalogue_full.txt" dict_basket = helpers.basket_textfile_to_dict(filepath_basket) dict_catalogue = helpers.cat_textfile_to_dict(filepath_catalogue) dict_offers = {} with self.assertRaises(NotImplementedError): test_pricer.calculate_total(dict_basket, dict_catalogue, dict_offers)
def test_get_discount_error_with_empty_catalogue(self): test_pricer = basket_pricer.BasketPricer() filepath_basket = "shopping_basket/data/basket_test_1.txt" filepath_offers = "shopping_basket/data/offers_test.txt" dict_basket = helpers.basket_textfile_to_dict(filepath_basket) dict_catalogue = {} dict_offers = helpers.offers_textfile_to_dict(filepath_offers) with self.assertRaises(NotImplementedError): test_pricer.calculate_discount(dict_basket, dict_catalogue, dict_offers)
def test_get_subtotal_with_basket_1(self): test_pricer = basket_pricer.BasketPricer() filepath_basket = "shopping_basket/data/basket_test_1.txt" filepath_catalogue = "shopping_basket/data/catalogue_test.txt" dict_basket = helpers.basket_textfile_to_dict(filepath_basket) dict_catalogue = helpers.cat_textfile_to_dict(filepath_catalogue) subtotal = 5.16 test_pricer.calculate_subtotal(dict_basket, dict_catalogue) self.assertEqual(test_pricer.subtotal, subtotal, "The subtotal is incorrect.")
def test_get_discount_with_basket_2(self): test_pricer = basket_pricer.BasketPricer() filepath_basket = "shopping_basket/data/basket_test_2.txt" filepath_catalogue = "shopping_basket/data/catalogue_test.txt" filepath_offers = "shopping_basket/data/offers_test.txt" dict_basket = helpers.basket_textfile_to_dict(filepath_basket) dict_catalogue = helpers.cat_textfile_to_dict(filepath_catalogue) dict_offers = helpers.offers_textfile_to_dict(filepath_offers) discount = 0.95 test_pricer.calculate_discount(dict_basket, dict_catalogue, dict_offers) self.assertEqual(test_pricer.discount, discount, "The discount is incorrect.")
def test_get_all_totals_basket_3(self): test_pricer = basket_pricer.BasketPricer() filepath_basket = "shopping_basket/data/basket_test_3.txt" filepath_catalogue = "shopping_basket/data/catalogue_full.txt" filepath_offers = "shopping_basket/data/offers_test.txt" dict_basket = helpers.basket_textfile_to_dict(filepath_basket) dict_catalogue = helpers.cat_textfile_to_dict(filepath_catalogue) dict_offers = helpers.offers_textfile_to_dict(filepath_offers) subtotal = 15.92 discount = 2.93 total = 12.99 test_pricer.calculate_total(dict_basket, dict_catalogue, dict_offers) self.assertEqual(test_pricer.subtotal, subtotal, "The subtotal is incorrect.") self.assertEqual(test_pricer.discount, discount, "The discount is incorrect.") self.assertEqual(test_pricer.total, total, "The total is incorrect.")
sys.exit(1) args = parser.parse_args() return args if __name__ == "__main__": args = parse_args() BASKET = args.basket CATALOGUE = args.catalogue OFFERS = args.offers if BASKET is None or CATALOGUE is None or OFFERS is None: print("Error: All file locations must be provided.") sys.exit(1) bp = bp.BasketPricer() print("\nLoading files...") DICT_BASKET = helpers.basket_textfile_to_dict(BASKET) DICT_CATALOGUE = helpers.cat_textfile_to_dict(CATALOGUE) DICT_OFFERS = helpers.offers_textfile_to_dict(OFFERS) print("\n***************************************") print("Calculating totals") bp.calculate_total(DICT_BASKET, DICT_CATALOGUE, DICT_OFFERS) print("***************************************\n") bp.print_totals() sys.exit(1)