def test_user_add_card_invalid_card_type_string(self, mocked_input): """ Tests user_add_card when invalid card type(String) given. """ mocked_input.side_effect = ['my choice', 'done'] Controller.card_manager = CardManager() self.assertRaises(InvalidCardTypeError, Controller.user_add_card)
def run_test(): cm = CardManager(card_filename='res/CubeLegacyClassic.csv') mm = MetatribeManager( type_to_tribe_filename='res/types.txt', special_tribes_filename='res/special_tribes.txt', ) culler = Culler(cull_filename='res/culls_v2.txt') creatures = cm.filter(lambda x: 'Creature' in x.supertypes) culled = creatures.filter(lambda x: not culler(x)) jcc = culled.filter(lambda x: mm.is_jcc(x)) non_jcc = culled.filter(lambda x: not mm.is_jcc(x)) print('creatures: {}'.format(len(creatures.cards))) print('non-jcc : {}'.format(len(non_jcc.cards))) print('jcc : {}'.format(len(jcc.cards))) print('culls : {}'.format(len(culler.card_names))) print('-----') tribes = mm.split_by_tribe(non_jcc.cards) del tribes['jcc'] for t, cs in tribes.items(): print('{:6}: {}'.format(t, len(cs))) remaining = non_jcc.filter(lambda x: not mm.is_myth(x)) remaining = remaining.filter(lambda x: not mm.is_animal(x)) remaining = remaining.filter(lambda x: not mm.is_human(x))
def test_user_search_card_no_found(self, mocked_input): """ Tests user_search_card when no card result matches. """ mocked_input.side_effect = ['BCIT student card', 'done'] Controller.card_manager = CardManager() self.assertRaises(NameNotFoundError, Controller.user_search_card)
def test_user_add_card_reward_card(self, mocked_input): """ Tests user_add_card when a reward card is successfully added. """ mocked_input.side_effect = [ '1', 'Starbucks reward card', 'eric', 'Starbucks', 'points', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_add_card_balance_card(self, mocked_input): """ Tests user_add_card when a balance card is successfully added. """ mocked_input.side_effect = [ '2', 'Compass Card', 'eric', 'TransLink', '150', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_add_card_invalid_height_input(self, mocked_input): """ Tests user_add_card when invalid height input given. """ mocked_input.side_effect = [ '6', 'Driver licence', 'eric', 'government of Canada', '2000-12-12', '2020-12-12', 'A010xxx', '26', 'very tall', 'done' ] Controller.card_manager = CardManager() self.assertRaises(InvalidHeightError, Controller.user_add_card)
def test_user_add_card_invalid_date_input(self, mocked_input): """ Tests user_add_card when invalid date format given. """ mocked_input.side_effect = [ '4', 'card a', 'eric', 'somewhere', 'Oct.6th.1919' 'done' ] Controller.card_manager = CardManager() self.assertRaises(InvalidDateFormatError, Controller.user_add_card)
def test_user_add_card_invalid_balance_input(self, mocked_input): """ Tests user_add_card when invalid card balance given. """ mocked_input.side_effect = [ '2', 'card a', 'eric', 'somewhere', '-100' 'done' ] Controller.card_manager = CardManager() self.assertRaises(InvalidCardBalanceError, Controller.user_add_card)
def test_user_add_card_other_card(self, mocked_input): """ Tests user_add_card when an other type card is successfully added. """ mocked_input.side_effect = [ '7', 'Moive ticket', 'eric', 'Scotia Bank theatre', 'Redeems one movie', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_add_card_govID_card(self, mocked_input): """ Tests user_add_card when a government id card is successfully added. """ mocked_input.side_effect = [ '6', 'Drivers licence', 'eric', 'ICBC', '2012-12-12', '2013-12-12', '123123123', '26', '179', 'Male', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_add_card_id_card(self, mocked_input): """ Tests user_add_card when a id card is successfully added. """ mocked_input.side_effect = [ '5', 'BCIT student card', 'eric', 'BCIT', '2012-12-12', '2013-12-12', 'A01037479', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_add_card_bank_card(self, mocked_input): """ Tests user_add_card when a bank card is successfully added. """ mocked_input.side_effect = [ '4', 'BMO credit card', 'eric', 'BMO', '2012-12-12', '2013-12-12', 'downtown branch', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_add_card_Membership_card(self, mocked_input): """ Tests user_add_card when a membership card is successfully added. """ mocked_input.side_effect = [ '3', 'YMCA card', 'eric', 'YMCA', '2012-12-12', '2013-12-12', 'regular', 'done' ] Controller.card_manager = CardManager() self.assertTrue(Controller.user_add_card)
def test_user_back_up_data_success(self, mocked_input): """ Tests user_back_up_card when successfully backed up. """ mocked_input.side_effect = [ '1', 'Starbucks reward card', 'eric', 'Starbucks', 'points', 'done' ] Controller.card_manager = CardManager() Controller.user_add_card() file_path = Controller.user_backup_data() self.assertTrue(os.path.exists(file_path))
def start_app(cls): """ Starts the application by prompting user menu. Catches all kinds of exceptions if raised. """ cls.card_manager = CardManager() menu_dict = {1: Controller.user_add_card, 2: Controller.user_remove_card, 3: Controller.user_view_all_card, 4: Controller.user_view_card, 5: Controller.user_search_card, 6: Controller.user_backup_data, 7: Controller.end_app} while True: try: user_input = int(input(f'1. Add a card\n' f'2. Remove a card\n' f'3. View all cards\n' f'4. View cards by type\n' f'5. Search for a card\n' f'6. Back up data\n' f'7. Exit app\n' f' : ')) menu_dict[user_input]() except KeyError: print(f'Invalid option\nPlease enter integer 1 to 7!\n') except ValueError: print(f'Invalid option\nPlease enter integers only!\n') except InvalidCardBalanceError as e: print(f'InvalidCardBalanceError caught! {e}') except InvalidCardTypeError as e: print(f'InvalidCardTypeError caught! {e}') except InvalidDateFormatError as e: print(f'InvalidDateFormatError caught! {e}') except DuplicatedNameError as e: print(f'DuplicatedNameError caught! {e}') except NameNotFoundError as e: print(f'NameNotFoundError caught! {e}') except EmptyCardManagerError as e: print(f'EmptyCardManagerError caught! {e}') except InvalidAgeError as e: print(f'InvalidAgeError caught! {e}') except InvalidHeightError as e: print(f'InvalidHeightError caught! {e}') except InvalidSexError as e: print(f'InvalidSexError caught! {e}') except TypeError as e: print(f'InvalidFileTypeError caught! {e}')
def test_user_back_up_data(self): """ Tests user_back_up_card when card manager is empty. """ Controller.card_manager = CardManager() self.assertRaises(EmptyCardManagerError, Controller.user_backup_data)