def test_delete_account(self): ''' Test case checks whether an account is account is deleted when delete_account is called. ''' new_account = User ("Kivian","kivian12","instagram") new_account.add_account() User.delete_account(new_account) self.assertEqual(len(User.accounts_list),1)
def test_find_account(self): ''' This test case checks whether to check the find_account function. ''' new_account = User ("Kivian","kivian12","instagram") new_account.add_account() found_acc = User.find_account("kivian12") self.assertEqual(found_acc.password,new_account.password)
def json_to_user(dictionary): """Converts a json dictionary to a User class object""" user_object = User(dictionary['id'], dictionary['username']) accounts_list = dictionary['accounts'] #list of account dictionaries for account in accounts_list: account_object = Account(account['account_name'], account['type'], account['username']) account_object.deposit(float(account['balance'])) user_object.add_account(account_object) transactions_list = dictionary['transactions'] for transaction in transactions_list: transaction_object = Transaction(transaction['time_stamp'], transaction['account_1'], transaction['account_2'], transaction['amount'], transaction['type']) user_object.add_transaction(transaction_object) return user_object
class TestUser(unittest.TestCase): def setUp(self): """ Test class that defines test cases for the profile behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases """ self.new_user = User("kamran", "sumar", "*****@*****.**", "God786", []) self.new_accounts = UserAccounts("facebook", "*****@*****.**", "God786") self.new_accounts2 = UserAccounts("insta", "*****@*****.**", "Holy786") def test_init(self): """ test_init test case to test if the object is initialized properly """ self.assertEqual(self.new_user.first_name, "kamran") self.assertEqual(self.new_user.last_name, "sumar") self.assertEqual(self.new_user.email, "*****@*****.**") self.assertEqual(self.new_user.password, "God786") self.assertEqual(self.new_user.platforms, []) def test_save_user(self): """ test_init test case to test if the object is initialized properly """ print(len(self.new_user.save_user())) self.assertEqual(len(self.new_user.save_user()), 5) def test_add_account(self): account = self.new_accounts.save_user_accounts() account2 = self.new_accounts2.gen_details(8) self.new_user.add_account(account) self.new_user.add_account(account2) print(self.new_user.platforms)
class TestUser(unittest.TestCase): """ TestUser class defines test that check the behaviours of users clas. """ def tearDown(self): ''' tearDown clears everything after every test has been run ''' User.users_list = [] Credentials.cred_list = [] def setUp(self): ''' setUp runs before the test cases. ''' self.new_account = User ("Victor","ndungi12","twitter") self.new_cred = Credentials ("*****@*****.**","0723456789") def user_init(self): ''' user_init checks if the object has been initialized properly. ''' self.assertEqual(self.new_account.user_name,"Victor") self.assertEqual(self.new_account.password,"ndungi12") self.assertEqual(self.new_account.site,"twitter") self.assertEqual(self.new_cred.gmail,"*****@*****.**") self.assertEqual(self.new_cred.number,"0723456789") def test_save_cred(self): ''' This test cases checks whether save_cred functions saves credentials. ''' self.new_cred.save_cred() self.assertEqual(len(Credentials.cred_list),1) def test_add_user(self): ''' Test case checks whether if an account is added everytime add_account function is called. ''' self.new_account.add_account() self.assertEqual(len(User.accounts_list),1) def test_delete_account(self): ''' Test case checks whether an account is account is deleted when delete_account is called. ''' new_account = User ("Kivian","kivian12","instagram") new_account.add_account() User.delete_account(new_account) self.assertEqual(len(User.accounts_list),1) def test_display_account(self): ''' This test case checks whether the listed items are the items in the accounts_list. ''' self.assertEqual(User.display_account(),User.accounts_list) def test_find_account(self): ''' This test case checks whether to check the find_account function. ''' new_account = User ("Kivian","kivian12","instagram") new_account.add_account() found_acc = User.find_account("kivian12") self.assertEqual(found_acc.password,new_account.password)