class TestUser(unittest.TestCase): ''' Test class that defines test cases for the user class behaviours. Args: unittest.TestCase: helps in creating test cases ''' def setUp(self): ''' Function to create a user account before each test ''' self.new_user = User('Ngigi', 'Kariuki', 'pswd100') def test__init__(self): ''' Test to if check the initialization/creation of user instances is properly done ''' self.assertEqual(self.new_user.first_name, 'Ngigi') self.assertEqual(self.new_user.last_name, 'Kariuki') self.assertEqual(self.new_user.password, 'pswd100') def test_save_user(self): ''' Test to check if the new users info is saved into the users list ''' self.new_user.save_user() self.assertEqual(len(User.users_list), 1)
class TestUser(unittest.TestCase): ''' Test class that defines test cases for the user class behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases ''' def setUp(self): ''' Method to run before each user test cases. ''' self.new_user = User("FeistyDory", "210sda38") def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.username, "FeistyDory") self.assertEqual(self.new_user.password, "210sda38") def test_save_user(self): ''' test case to test if a new user object has been saved into the User list ''' self.new_user.save_user() self.assertEqual(len(User.user_list), 1)
def test_save_multiple_user(self): self.new_user.save_user() test_user = User("Test_user","password")#new user test_user.save_user() self.assertEqual(len(User.user_List),2)
def test_save_multiple_user(self): ''' test_save_multiple_user to check if we can save multiple users object to our lists ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() self.assertEqual(len(User.user_list), 2)
def test_save_multiple_user(self): ''' test_save_multiple_contact to check if we can save multiple contact objects to our contact_list ''' self.new_user.save_user() test_user = User("fname", "abc123") # new user test_user.save_user() self.assertEqual(len(User.user_list), 2)
def test_delete_user(self): self.new_user.save_user() test_user = User("Test_user","password") test_user.save_user() self.new_user.delete_user() #del user self.assertEqual(len(User.user_List),1)
def test_save_multiple_user(self): ''' test_save_multiple_user to check if we can save multiple user objects to our user_list ''' self.new_user.save_user() test_user = User("Test", "user", "0712345678", "*****@*****.**") # the new user test_user.save_user() self.assertEqual(len(User.user_list), 2)
def test_delete_user(self): ''' test_delete_contact to test if we can remove a contact from our contact list ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list), 1)
def test_find_user_by_account_name(self): ''' test to check if we can find user by account name and display information ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() found_user = User.find_by_account_name("Facebook") self.assertEqual(found_user.password, test_user.password)
def test_user_exists(self): ''' test to check if we can return a boolean if cannot find the contact. ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() user_exists = User.user_exist("Facebook") self.assertTrue(user_exists)
def test_delete_user(self): """ test_delete_user to test if we can remove a user from our users list """ self.created_user.save_user() test_user = User("Kevin", "1050") test_user.save_user() self.created_user.delete_user() self.assertEqual(len(User.user_list), 1)
def test_delete_user(self): ''' test_delete_user to test if we can remove a user from our user_list ''' self.new_user.save_user() test_user = User("feven", "a1b1c1") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1)
def test_user_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_user.save_user() test_user = User("Test", "user", "0711223344", "test@user") #new user test_user.save_user() user_exists = User.user_exist("0711223344") self.assertTrue(user_exists)
def test_users_exists(self): ''' returns boolean if users not found test ''' self.new_user.save_user() test_user = User("test_user","password",) test_user.save_user() user_exists = User.user_exist("test") self.assertTrue(user_exists)
def test_user_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_user.save_user() test_user = User("feven", "a1b1c1") # new user test_user.save_user() user_exists = User.user_exist("feven") self.assertTrue(user_exists)
def test_delete_user(self): ''' test_delete_user to test if we can remove a user from our user list ''' self.new_user.save_user() test_user = User("Test", "user", "0712345678", "*****@*****.**") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1)
def test_find_user_by_number(self): ''' test to check if we can find a user by phone number and display information ''' self.new_user.save_user() test_user = User("Test", "user", "0711223344", "*****@*****.**") # new user test_user.save_user() found_user = User.find_by_number("0711223344") self.assertEqual(found_user.email, test_user.email)
class TestClass(unittest.TestCase): """ A Test class that defines test cases for the User class. """ def setUp(self): """ Method that runs before each individual test methods run. """ self.user = User('WangechiKimani', '123Pass') self.credentials = Credentials('instagram', 'WangechiKimani', '123Pass') def test_init(self): """ test case to check if the object has been initialized correctly """ self.assertEqual(self.user.username, 'WangechiKimani') self.assertEqual(self.user.password, '123Pass') def test_save_user(self): """ test case to test if a new user instance has been saved into the User list """ self.user.save_user() self.assertGreater(len(User.user_list), 0) def test_get_user(self): self.user.save_user() self.assertIsNot(User.get_user(User('WangechiKimani', '123Pass')), False) def test_save_credentials(self): self.credentials.save_credential() self.assertGreater(len(Credentials.credentials_list), 0) def test_generate_random_password_with_predefined_length(self): credentials = Credentials('twitter', 'WangechiKimani') password = credentials.generate_random_password(2) self.assertEqual(len(password), 2) def test_generate_random_password_with_standard_length(self): credentials = Credentials('twitter', 'WangechiKimani') password = credentials.generate_random_password() self.assertEqual(len(password), 10) def test_find_credentials(self): self.credentials.save_credential() self.assertEqual(len(self.user.find_credentials()), 0)
def test_check_user(self): ''' Function to test whether the login in function check_user works as expected ''' self.new_user = User('Ngigi', 'Kariuki', 'pswd100') self.new_user.save_user() user2 = User('Ngigi', 'Kariuki', 'pswd100') user2.save_user() for user in User.users_list: if user.first_name == user2.first_name and user.password == user2.password: current_user = user.first_name return current_user self.assertEqual( current_user, Credential.check_user(user2.password, user2.first_name))
class User_Test(unittest.TestCase): # to test user class def setUp(self): #function that runs before self.user = User('ingabire','ingabire') def test_init(self): #is user created correctly self.assertEqual(self.user.username,'ingabire') self.assertEqual(self.user.password,'ingabire') def test_save_user(self): # is the user saved self.user.save_user() self.assertEqual(len(User.users),1)
class TestUser(unittest.TestCase): """ Test class that defines test cases for the user class behaviours. """ def setUp(self): self.created_user = User("Kiptoo", "1997") def tearDown(self): User.user_list = [] def test_init(self): self.assertEqual(self.created_user.name, "Kiptoo") self.assertEqual(self.created_user.user_password, "1997") def test_save_user(self): """ test_save_user test case to test if the user object is saved into the user list """ self.created_user.save_user() # saving the new user self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): self.created_user.save_user() test_user = User("Kevin", "1050") test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_delete_user(self): """ test_delete_user to test if we can remove a user from our users list """ self.created_user.save_user() test_user = User("Kevin", "1050") test_user.save_user() self.created_user.delete_user() self.assertEqual(len(User.user_list), 1)
def test_save_multiple_user(self): self.created_user.save_user() test_user = User("Kevin", "1050") test_user.save_user() self.assertEqual(len(User.user_list), 2)
class TestClass(unittest.TestCase): """ A Test class that defines test cases for the User class. """ def setUp(self): """ Method that runs before each individual test methods run. """ self.user = User('WangechiKimani', '123Pass') self.credentials = Credentials('Twitter', 'WangechiKimani', '123Pass') def test_init(self): """ test case to chek if the object has been initialized correctly """ self.assertEqual(self.user.username, 'WangechiKimani') self.assertEqual(self.user.password, '123Pass') def test_save_user(self): """ test case to test if a new user instance has been saved into the User list """ self.user.save_user() self.assertGreater(len(User.user_list), 0) def test_get_user(self): self.user.save_user() self.assertIsNot(User.get_user(User('WangechiKimani', '123Pass')), False) def test_save_credentials(self): self.credentials.save_credential() self.assertGreater(len(Credentials.credentials_list), 0) def test_generate_random_password_with_predefined_length(self): credentials = Credentials('twitter', 'WangechiKimani') password = credentials.generate_random_password(2) self.assertEqual(len(password), 2) def test_generate_random_password_with_standard_length(self): credentials = Credentials('twitter', 'WangechiKimani') password = credentials.generate_random_password() self.assertEqual(len(password), 10) def test_find_credentials(self): self.credentials.save_credential() self.assertEqual(len(self.user.find_credentials()), 1) def tearDown(self): """ method that does clean up after each test case has run. """ Credentials.credentials_list = [] def test_save_many_accounts(self): """ test to check if we can save multiple credentials objects to our credentials list """ self.credentials.save_credential() test_credential = Credentials("Twitter", "WangechiKimani", "123Pass") test_credential.save_credential() self.assertGreater(len(Credentials.credentials_list), 1) def test_delete_credential(self): """ test method to test if we can remove an account credentials from our credentials_list """ self.credentials.save_credential() self.credentials.delete_credentials() self.assertEqual(len(Credentials.credentials_list), 0) def test_find_credential(self): """ test to check if we can find a credential entry by account name and display the details of the credential """ self.credentials.save_credential() credential = self.credentials.find_credential("Twitter") self.assertEqual(self.credentials.credential, credential.credential) # def test_credential_exist(self): # """ # test to check if we can return a true or false based on whether we find or can't find the credential. # """ # self.credentials.save_credential() # the_credential = Credentials("Twitter", "WangechiKimani", "123Pass") # the_credential.save_credential() # credential_is_found = Credentials.if_credential_exist("Twitter") # self.assertTrue(credential_is_found) def test_display_all_saved_credentials(self): """ method that displays all the credentials that has been saved by the user """ self.assertEqual(Credentials.display_credentials(), Credentials.credentials_list)
class TestUser(unittest.TestCase, User, Credentials): ''' This is test class that defines test cases for the user and credentials class behaviours Args: unittest.TestCase: TestCase class that helps in creating test cases ''' def setUp(self): ''' Set Up method to run before each test cases. ''' self.new_user = User("Derrick", "Kariuki", "0718016066", "*****@*****.**") # creates user object self.new_account = Credentials( "Instagram", "dero1234") # creates credentials object def tearDown(self): ''' tearDown method that cleans up after each test case has run ''' User.user_list = [] Credentials.account_list = [] def test_init(self): ''' test init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.first_name, "Derrick") self.assertEqual(self.new_user.last_name, "Kariuki") self.assertEqual(self.new_user.phone_number, "0718016066") self.assertEqual(self.new_user.email, "*****@*****.**") self.assertEqual(self.new_account.account_name, "Instagram") self.assertEqual(self.new_account.account_password, "dero1234") def test_save_user(self): ''' test_save_user test case tests whether the user object is saved in the user list ''' self.new_user.save_user() # saving the new user self.assertEqual(len(User.user_list), 1) def test_save_account(self): ''' test_save_account test case tests whether the account object is saved in the account list ''' self.new_account.save_account() # saving the new account self.assertEqual(len(Credentials.account_list), 1) def test_save_multiple_user(self): ''' test_save_multiple_user to check if we can save multiple user objects to our user_list ''' self.new_user.save_user() test_user = User("Test", "user", "0712345678", "*****@*****.**") # the new user test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_save_multiple_account(self): ''' test_save_multiple_account to check if we can save multiple account objects to our account_list ''' self.new_account.save_account() test_account = Credentials("Test", "account12") # the new account test_account.save_account() self.assertEqual(len(Credentials.account_list), 2) def test_delete_user(self): ''' test_delete_user to test if we can remove a user from our user list ''' self.new_user.save_user() test_user = User("Test", "user", "0712345678", "*****@*****.**") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1) def test_delete_account(self): ''' test_delete_account to test if we can remove an account from our account list ''' self.new_account.save_account() test_account = Credentials("Test", "account12") # new account test_account.save_account() self.new_account.delete_account() # Deleting a account object self.assertEqual(len(Credentials.account_list), 1) def test_find_user_by_number(self): ''' test to check if we can find a user by phone number and display information ''' self.new_user.save_user() test_user = User("Test", "user", "0711223344", "*****@*****.**") # new user test_user.save_user() found_user = User.find_by_number("0711223344") self.assertEqual(found_user.email, test_user.email) def test_user_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_user.save_user() test_user = User("Test", "user", "0711223344", "test@user") #new user test_user.save_user() user_exists = User.user_exist("0711223344") self.assertTrue(user_exists) def test_display_all_users(self): ''' test to check that a list of all users saved is returned. ''' self.assertEqual(User.display_users(), User.user_list) def test_display_all_accounts(self): ''' test to check that a list of all accounts saved is returned. ''' self.assertEqual(Credentials.display_accounts(), Credentials.account_list)
class TestUser(unittest.TestCase): ''' test class that defines test cases for the User class behaviours Args: unittest.TestCase: TestCase class that helps in creating test cases ''' def tearDown(self): ''' tear down method that cleans up after each test case is run ''' User.user_List = [] def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("tu276","nathan") #create user object def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.login_username,"tu276") self.assertEqual(self.new_user.user_password,"nathan") def test_save_user(self): ''' test case to see if user ogject is saved into ''' self.new_user.save_user() #save user self.assertEqual(len(User.user_List),1) def test_save_multiple_user(self): self.new_user.save_user() test_user = User("Test_user","password")#new user test_user.save_user() self.assertEqual(len(User.user_List),2) def test_delete_user(self): self.new_user.save_user() test_user = User("Test_user","password") test_user.save_user() self.new_user.delete_user() #del user self.assertEqual(len(User.user_List),1) def test_users_exists(self): ''' returns boolean if users not found test ''' self.new_user.save_user() test_user = User("test_user","password",) test_user.save_user() user_exists = User.user_exist("test") self.assertTrue(user_exists)
class TestCredentials(unittest.TestCase): ''' Test class that defines test cases for the credentials class behaviours. Args: unittest.TestCase: helps in creating test cases ''' def test_check_user(self): ''' Function to test whether the login in function check_user works as expected ''' self.new_user = User('Ngigi', 'Kariuki', 'pswd100') self.new_user.save_user() user2 = User('Ngigi', 'Kariuki', 'pswd100') user2.save_user() for user in User.users_list: if user.first_name == user2.first_name and user.password == user2.password: current_user = user.first_name return current_user self.assertEqual( current_user, Credential.check_user(user2.password, user2.first_name)) def setUp(self): ''' Function to create an account's credentials before each test ''' self.new_credential = Credential('Ngigi', 'Facebook', 'test', 'pswd100') def test__init__(self): ''' Test to if check the initialization/creation of credential instances is properly done ''' self.assertEqual(self.new_credential.user_name, 'Ngigi') self.assertEqual(self.new_credential.site_name, 'Facebook') self.assertEqual(self.new_credential.account_name, 'test') self.assertEqual(self.new_credential.password, 'pswd100') def test_save_credentials(self): ''' Test to check if the new credential info is saved into the credentials list ''' self.new_credential.save_credentials() twitter = Credential('Ngigi', 'Twitter', 'works', 'pswd100') twitter.save_credentials() self.assertEqual(len(Credential.credentials_list), 2) def tearDown(self): ''' Function to clear the credentials list after every test ''' Credential.credentials_list = [] User.users_list = [] def test_display_credentials(self): ''' Test to check if the display_credentials method, displays the correct credentials. ''' self.new_credential.save_credentials() twitter = Credential('Ngigi', 'Twitter', 'works', 'pswd100') twitter.save_credentials() gmail = Credential('Ngigi', 'Gmail', 'send', 'pswd200') gmail.save_credentials() self.assertEqual( len(Credential.display_credentials(twitter.user_name)), 3) def test_find_by_site_name(self): ''' Test to check if the find_by_site_name method returns the correct credential ''' self.new_credential.save_credentials() twitter = Credential('Ngigi', 'Twitter', 'works', 'pswd100') twitter.save_credentials() credential_exists = Credential.find_by_site_name('Twitter') self.assertEqual(credential_exists, twitter) def test_copy_credential(self): ''' Test to check if the copy a credential method copies the correct credential ''' self.new_credential.save_credentials() twitter = Credential('Ngigi', 'Twitter', 'works', 'pswd100') twitter.save_credentials() find_credential = None for credential in Credential.user_credentials_list: find_credential = Credential.find_by_site_name( credential.site_name) return pyperclip.copy(find_credential.password) Credential.copy_credential(self.new_credential.site_name) self.assertEqual('pswd100', pyperclip.paste()) print(pyperclip.paste())
class TestUser(unittest.TestCase): def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("feven", "abc123") # create User object def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' User.user_list = [] def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.first_name, "feven") self.assertEqual(self.new_user.password, "abc123") def test_save_user(self): ''' test_save_user test case to test if the user object is saved into the user list ''' self.new_user.save_user() self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): ''' test_save_multiple_contact to check if we can save multiple contact objects to our contact_list ''' self.new_user.save_user() test_user = User("fname", "abc123") # new user test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_delete_user(self): ''' test_delete_user to test if we can remove a user from our user_list ''' self.new_user.save_user() test_user = User("feven", "a1b1c1") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1) def test_display_all_users(self): ''' method that returns a list of all users saved ''' self.assertEqual(User.display_users(), User.user_list) def test_user_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_user.save_user() test_user = User("feven", "a1b1c1") # new user test_user.save_user() user_exists = User.user_exist("feven") self.assertTrue(user_exists)
def save_user(user): ''' Function to save a new user account ''' User.save_user(user)
class TestUser(unittest.TestCase): ''' Test class that defines test cases for user class behaviours Args: unittest.TestCase: class that helps in creating test cases ''' def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("Joe", "Instagram", "@joe.com", "killshot18") def tearDown(self): ''' tearDown method that does clean up after each test case has run ''' User.user_list = [] def test_init(self): ''' test_init test case to case to test if the object is initialized properly ''' self.assertEqual(self.new_user.user_name, "Joe") self.assertEqual(self.new_user.account_name, "Instagram") self.assertEqual(self.new_user.email, "@joe.com") self.assertEqual(self.new_user.password, "killshot18") def test_save_user(self): ''' test_save_user test case to test if the user object is saved into user list ''' self.new_user.save_user() self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): ''' test_save_multiple_user to check if we can save multiple users object to our lists ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_delete_user(self): ''' test_delete_contact to test if we can remove a contact from our contact list ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list), 1) def test_find_user_by_account_name(self): ''' test to check if we can find user by account name and display information ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() found_user = User.find_by_account_name("Facebook") self.assertEqual(found_user.password, test_user.password) def test_user_exists(self): ''' test to check if we can return a boolean if cannot find the contact. ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() user_exists = User.user_exist("Facebook") self.assertTrue(user_exists) def test_display_all_users(self): ''' method that returns a list of all contacts saved ''' self.assertEqual(Credential.display_users(), Credential.user_list) def test_copy_email(self): ''' test to confirm that we are copying email from found user ''' self.new_user.save_user() User.copy_email("Instagram") self.assertEqual(self.new_user.email, pyperclip.paste())