def test_get_catalog_from_textfile(self): filepath = "shopping_basket/data/catalogue_test.txt" catalog = {"Baked Beans": 0.99, "Biscuits": 1.20, "Sardines": 1.89} dict_cat = helpers.cat_textfile_to_dict(filepath) self.assertEqual( dict_cat, catalog, "The catalog is not correct.", )
def test_get_subtotal_zero_with_empty_basket(self): test_pricer = basket_pricer.BasketPricer() filepath_catalogue = "shopping_basket/data/catalogue_test.txt" dict_basket = {} dict_catalogue = helpers.cat_textfile_to_dict(filepath_catalogue) test_pricer.calculate_subtotal(dict_basket, dict_catalogue) self.assertEqual(test_pricer.subtotal, 0.0, "The subtotal is not zero.")
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_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_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.")
def test_get_incorrect_filename_catalog_from_textfile(self): filepath = "catalogue.txt" with self.assertRaises(FileNotFoundError): helpers.cat_textfile_to_dict(filepath)
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)