def test_update(self): filename = "test.pickle" generic_repository = GenericRepository(filename) medicine = Medicine(1, "para", "fares", 12.1, True, False) generic_repository.create(medicine) medicine_to_update = Medicine(1, "para", "fares", 12.12, True, False) generic_repository.update(medicine_to_update) new_medicine = generic_repository.read_by_id(1) self.assertEqual(new_medicine.get_medicine_price(), 12.12) generic_repository.delete(1)
def test_update_medicine(self): medicine_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test1.pickle") medicine_validator = MedicineValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) medicine_service.add_medicine(1, "para", "fares", 12.0, True, False) medicine_service.update_medicine(1, "alg", "fares", 12.34, False, False) medicine = medicine_service.get_drug(1) self.assertEqual(medicine.get_medicine_name(), "alg") self.assertEqual(medicine.get_recipe_need(), False) medicine_repository.delete(1)
def test_create(self): filename = "test.pickle" generic_repository = GenericRepository(filename) medicine = Medicine(1, "para", "fares", 12.1, True, False) generic_repository.create(medicine) storage = generic_repository.read_all() self.assertEqual(len(storage), 1) generic_repository.delete(1)
def main(): medicine_repository = GenericRepository("drugs.pickle") medicine_validator = MedicineValidator() customer_card_repository = GenericRepository("cards.pickle") customer_card_validator = CustomerCardValidator() transaction_repository = GenericRepository("transactions.pickle") transaction_validator = TransactionValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) customer_card_service = CustomerCardService(customer_card_repository, customer_card_validator, transaction_repository, medicine_repository) transaction_service = TransactionService(transaction_repository, transaction_validator, customer_card_repository, medicine_repository) ui = Console(medicine_service, customer_card_service, transaction_service) ui.run_console()
def test_update_transaction(self): medicine_repository = GenericRepository("test.pickle") customer_card_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test.pickle") transaction_validator = TransactionValidator() medicine_validator = MedicineValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) transaction_service = TransactionService(transaction_repository, transaction_validator, customer_card_repository, medicine_repository) medicine_service.add_medicine(2, "para", "fares", 12.12, True, False) transaction_service.add_transaction(1, 2, 3, 12, "12/11/2018", 12.23) transaction_service.update_transaction(1, 2, 4, 12, "12/11/2018", 12.23) medicine_repository.delete(2) transaction = transaction_repository.read_by_id(1) self.assertEqual(transaction.get_customer_card_transaction_id(), 4) transaction_repository.delete(1)
def test_add_transaction(self): medicine_repository = GenericRepository("test.pickle") customer_card_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test.pickle") transaction_validator = TransactionValidator() medicine_validator = MedicineValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) transaction_service = TransactionService(transaction_repository, transaction_validator, customer_card_repository, medicine_repository) medicine_service.add_medicine(2, "para", "fares", 12.12, True, False) transaction_service.add_transaction(1, 2, 3, 12, "12/11/2018", 12.23) medicine_repository.delete(2) self.assertEqual(len(transaction_service.get_all_transactions()), 1) transaction_repository.delete(1)
def test_populate(self): medicine_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test1.pickle") medicine_validator = MedicineValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) medicine_service.add_medicine(1, "para", "fares", 12.0, True, False) medicine_service.populate(2) self.assertEqual(len(medicine_service.get_all_drugs()), 3) medicine_repository.delete(1) medicine_repository.delete(2) medicine_repository.delete(3)
def test_get_all_drugs_that_match(self): medicine_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test1.pickle") medicine_validator = MedicineValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) medicine_service.add_medicine(1, "para", "fares", 12.0, True, False) medicine_service.add_medicine(2, "alg", "fares", 12.0, True, False) medicine_service.add_medicine(3, "alga", "fares", 12.0, True, False) list_of_drugs = medicine_service.get_list_of_drugs_that_match("alg") self.assertEqual(len(list_of_drugs), 2) medicine_repository.delete(1) medicine_repository.delete(2) medicine_repository.delete(3)
def test_add_customer_card(self): customer_card_validator = CustomerCardValidator() customer_card_repository = GenericRepository("test.pickle") medicine_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test.pickle") customer_card_service = CustomerCardService(customer_card_repository, customer_card_validator, transaction_repository, medicine_repository) customer_card_service.add_customer_card(1, "Adam", "Andrei", 5010306015562, "06/03/2001", "19/10/2018", False) self.assertEqual(len(customer_card_service.get_all_cards()), 1) customer_card_repository.delete(1)
def test_update_customer_card(self): customer_card_validator = CustomerCardValidator() customer_card_repository = GenericRepository("test.pickle") medicine_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test.pickle") customer_card_service = CustomerCardService(customer_card_repository, customer_card_validator, transaction_repository, medicine_repository) customer_card_service.add_customer_card(1, "Adam", "Andrei", 5020306015562, "06/03/2001", "19/10/2018", False) customer_card_service.update_customer_card(1, "Adams", "Andrei", 5010306015562, "06/03/2001", "19/10/2018", False) card = customer_card_repository.read_by_id(1) self.assertEqual(card.get_customer_name(), "Adams") customer_card_repository.delete(1)
def test_get_list_of_customer_cards_that_match(self): customer_card_validator = CustomerCardValidator() customer_card_repository = GenericRepository("test.pickle") medicine_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test.pickle") customer_card_service = CustomerCardService(customer_card_repository, customer_card_validator, transaction_repository, medicine_repository) customer_card_service.add_customer_card(1, "Adam", "Andrei", 5010306015562, "06/03/2001", "19/10/2018", False) customer_card_service.add_customer_card(2, "Adams", "Andrei", 5020306015562, "06/03/2001", "19/10/2018", False) customer_card_service.add_customer_card(3, "Adams", "Andrei", 5030306015562, "06/03/2001", "19/10/2018", False) list_of_cards = customer_card_service.get_list_of_customer_cards_that_match( "Adams") self.assertEqual(len(list_of_cards), 2) customer_card_repository.delete(1) customer_card_repository.delete(2) customer_card_repository.delete(3)
def test_get_transactions_between_two_dates(self): medicine_repository = GenericRepository("test.pickle") customer_card_repository = GenericRepository("test.pickle") transaction_repository = GenericRepository("test.pickle") transaction_validator = TransactionValidator() medicine_validator = MedicineValidator() medicine_service = MedicineService(medicine_repository, medicine_validator, transaction_repository) transaction_service = TransactionService(transaction_repository, transaction_validator, customer_card_repository, medicine_repository) medicine_service.add_medicine(2, "para", "fares", 12.12, True, False) medicine_service.add_medicine(5, "para", "fares", 12.12, True, False) medicine_service.add_medicine(6, "para", "fares", 12.12, True, False) transaction_service.add_transaction(1, 2, 3, 12, "12/11/2018", 12.23) transaction_service.add_transaction(3, 5, 3, 12, "13/11/2018", 12.23) transaction_service.add_transaction(4, 6, 3, 12, "15/11/2018", 12.23) medicine_repository.delete(2) medicine_repository.delete(5) medicine_repository.delete(6) list_of_transactions = transaction_service.get_transactions_between_two_dates( "11/11/2018", "14/11/2018") self.assertEqual(len(list_of_transactions), 2) transaction_repository.delete(1) transaction_repository.delete(3) transaction_repository.delete(4)
def main(): circle_validator = CircleValidator() circle_repository = GenericRepository("circle.pickle") circle_service = CircleService(circle_repository, circle_validator) ui = Console(circle_service) ui.run_console()