def test_get_all_totals_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_total(dict_basket, dict_catalogue, dict_offers)
def test_get_offers_from_textfile(self): filepath = "shopping_basket/data/offers_test.txt" offers = { "Baked Beans": ["buy", "2", "get", "1", "free"], "Sardines": ["25", "discount"] } dict_offers = helpers.offers_textfile_to_dict(filepath) self.assertEqual( dict_offers, offers, "The offers are not correct.", )
def test_get_discount_zero_with_empty_basket(self): test_pricer = basket_pricer.BasketPricer() filepath_catalogue = "shopping_basket/data/catalogue_test.txt" filepath_offers = "shopping_basket/data/offers_test.txt" dict_basket = {} dict_catalogue = helpers.cat_textfile_to_dict(filepath_catalogue) dict_offers = helpers.offers_textfile_to_dict(filepath_offers) test_pricer.calculate_discount(dict_basket, dict_catalogue, dict_offers) self.assertEqual(test_pricer.discount, 0.0, "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)