class AddressBookTest(unittest.TestCase): def setUp(self): self.ab = AddressBook() with open('address_book.json', 'w'): pass def test_file_non_exist(self): os.remove('address_book.json') self.ab.add('test', 'test', 'test', 'test') assert os.path.isfile('address_book.json') @parameterized.expand([ ('test', 'test', 'test', 'test', "{'test': {'address': 'test', 'phone': 'test', 'email': 'test'}}"), ('', '', '', '', "{'': {'address': '', 'phone': '', 'email': ''}}"), ('тест', 'тест', 'тест', 'тест', "{'тест': {'address': 'тест', 'phone': 'тест', 'email': 'тест'}}") ]) def test_add_write(self, name, address, phone, email, expected_result): self.ab.add(name, address, phone, email) with open('address_book.json', 'r') as f: address_book_file = json.load(f) self.assertEqual(str(address_book_file), expected_result) def tearDown(self): os.remove('address_book.json')
def choose_option(self, user_input): ab = AddressBook() if user_input == 1: ab.show() elif user_input == 2: name = input('input name: ') address = input('input address: ') phone = input('input phone: ') email = input('input email: ') ab.add(name, address, phone, email) elif user_input == 3: ab.show() name = input('input name for change: ') field = input('input field for change: ') new_info = input('input new info: ') ab.change(name, field, new_info) ab.show() elif user_input == 4: name = input('input name for delete: ') ab.delete(name) elif user_input == 5: name = input('input name: ') ab.search(name) elif user_input == 0: print('good bye!') else: return