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): ''' Set up method to run before each test cases. ''' self.new_account = User("qwerty12345") def test_init(self): ''' Test case to test if the object is initialized properly. ''' self.assertEqual(self.new_account.master_password, "qwerty12345") def tearDown(self): ''' Clear after each test case runs ''' User.user_accounts = [] def test_save_account(self): ''' Test case to test if the account object is saved into the user_accounts list. ''' self.new_account.save_account() self.assertEqual(len(User.user_accounts), 1)
def test_save_multiple_user(self): ''' save_multiple_user to test the ability to save multiple users ''' self.new_user.save_user() test_user = User ("test", "0726", "*****@*****.**") test_user.save_user() self.assertEqual(len(User.user_list), 2)
def test_user_change_password(self): """ test_user_change_password to test if a user can alter their password """ test_alter = User("username", "password1") test_alter.save_user() change_passwrd = test_alter.change_userpass("username", "password03") self.assertEqual(change_passwrd.password, "password03")
def test_user_delete_account(self): """ test_user_delete_account to test if a user can delete their account """ self.test_user = User("username", "password1") self.test_user.save_user() self.test_user.user_delete_account() self.assertEqual(len(User.user_list), 0)
def test_username_match_password(self): """ test_username_match_password to test if a password matches a username """ self.test_user = User("username", "password1") self.test_user.save_user() confirm_user_exist = User.confirm_user("username", "password1") self.assertTrue(confirm_user_exist)
def test_save_multiple_user(self): ''' checks if it can save multiple user profiles ''' self.new_user.save_user() test_user = User("Her", "Him", "0798765432", "*****@*****.**", "01234") test_user.save_user() self.assertEqual(len(User.details_list), 2)
def test_check_user_exists(self): """ test_check_user_exists to test if a user exists or not """ self.new_user.save_user() test_user = User("username", "password1") test_user.save_user() user_exists = User.user_exists("username") self.assertTrue(user_exists)
def test_save_user(self): ''' test_save_user to check if we can save user objects to our User_list ''' self.new_user.save_user() test_user = User("Gabriel", "Nwachukwu", "moringa123") # new contact test_user.save_user() self.assertEqual(len(User.users_list), 2)
def test_delete_user(self): ''' delete_user method that uses the remove method from the user_list ''' self.new_user.save_user() test_user = User ("test", "0726", "*****@*****.**") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list), 1)
def test_delete_user(self): ''' tests if it can remove a user profile from user_details ''' self.new_user.save_user() test_user = User("Her", "Him", "0798765432", "*****@*****.**", "01234") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.details_list), 1)
def test_find_user_by_number(self): ''' checks if it can find user by phone phone_number ''' self.new_user.save_user() test_user = User("Her", "Him", "0798765432", "*****@*****.**", "01234") test_user.save_user() found_user = User.find_by_number("0798765432") self.assertEqual(found_user.email, test_user.email)
def test_find_user_by_username(self): ''' test to check if it is possible to find users by usernames and display the usernames ''' self.new_user.save_user() test_user = User("test", "0726", "*****@*****.**") test_user.save_user() found_user = User.find_by_username("test") self.assertEqual(found_user.username, test_user.username)
def test_user_exists(self): ''' checks if user exists ''' self.new_user.save_user() test_user = User("Her", "Him", "0798765432", "*****@*****.**", "01234") test_user.save_user() user_exists = User.user_exist("0798765432") self.assertTrue(user_exists)
def test_user_exists(self): ''' method that tests if a user exists in the user_list ''' self.new_user.save_user() test_user = User("test", "0726", "*****@*****.**") test_user.save_user() user_exists = User.user_exist("test") self.assertTrue(user_exists)
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): ''' Set up method to run before each test cases. ''' self.new_user = User("Gabriel", "Nwachukwu", "moringa123") # create contact object def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.first_name, "Gabriel") self.assertEqual(self.new_user.last_name, "Nwachukwu") self.assertEqual(self.new_user.password, "moringa123") def test_save_user(self): ''' test_user_contact test case to test if the user object is saved into the user list ''' self.new_user.save_user() # saving the new user self.assertEqual(len(User.users_list), 1) def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' User.users_list = [] # other test cases here def test_save_user(self): ''' test_save_user to check if we can save user objects to our User_list ''' self.new_user.save_user() test_user = User("Gabriel", "Nwachukwu", "moringa123") # new contact test_user.save_user() self.assertEqual(len(User.users_list), 2)
def new_account(master_password): ''' Function to create new account ''' new_user = User(master_password) return new_user
def validate_user(master_password): ''' Function to validate an existing user ''' existing_user = User.existing_user(master_password) return existing_user
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('Gabriel', 'Nwachukwu', 'moringa123') self.new_user.save_user() user2 = User('peter', 'okoye', 'nigeria123') 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 test_check_user(self): ''' Function to test whether the login in function check_user works as expected ''' self.new_user = User('Gabriel', 'Nwachukwu', 'moringa123') self.new_user.save_user() user2 = User('Roland', 'Nwachukwu', 'yola123') 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 create_user(fname,lname,password): ''' Function to create a new user account ''' new_user = User(fname,lname,password) return new_user
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_account = User("qwerty12345")
def create_user(username, phone, email): new_user = User(username, phone, email) return new_user
def display_user(): return User.display_user()
def user_exists(username): return User.user_exist(username)
def find_by_username(username): return User.find_by_username(username)
def user_change_password(userName, new_pass): return User.change_userpass(userName, new_pass)
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("Gabriel", "Nwachukwu", "moringa123") # create contact object
from user_data import User from user_data import Facility import pandas as pd from bs4 import BeautifulSoup import time # Excelファイルを文字列として読み込む excel = excel_access.ExcelAccess("database.xlsx", 0) # ログイン情報を格納する user_list = [] for item in excel.ReadAll(): user_id = item[2] password = item[3] user_list.append(User(user_id, password)) WEB_SITE_PATH = 'https://yoyaku.harp.lg.jp/resident/Menu.aspx?lgCode=011002' driver = chrome_driver.SeleniumChromeAccess() driver.change_url(WEB_SITE_PATH) # 施設予約ログインボタンクリック driver.click_button_using_XPath( "/html/body/form/div[5]/div/div[1]/div/table/tbody/tr[4]/td[1]/div/ul/li[1]/input" ) input_user_id_xml = "/html/body/form/div[5]/div/div[1]/div/table[1]/tbody/tr[2]/td/input" input_password_xml = "/html/body/form/div[5]/div/div[1]/div/table[1]/tbody/tr[3]/td/input" push_button_login = "******"
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('Gabriel', 'Nwachukwu', 'moringa123') self.new_user.save_user() user2 = User('Roland', 'Nwachukwu', 'yola123') 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('Mary', 'Facebook', 'maryjoe', 'nairobi123') def test__init__(self): ''' Test to if check the initialization/creation of credential instances is properly done ''' self.assertEqual(self.new_credential.user_name, 'Mary') self.assertEqual(self.new_credential.site_name, 'Facebook') self.assertEqual(self.new_credential.account_name, 'maryjoe') self.assertEqual(self.new_credential.password, 'nairobi123') 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('Jane', 'Twitter', 'maryjoe', 'nairobi123') 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('paul', 'Twitter', 'okoye', 'nairobi123') twitter.save_credentials() gmail = Credential('paul', 'Gmail', 'okoye', 'nairobi123') gmail.save_credentials() self.assertEqual( len(Credential.display_credentials(twitter.user_name)), 2) 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('Jane', 'Twitter', 'maryjoe', 'nairobi123') 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('Jane', 'Twitter', 'maryjoe', 'nairobi123') twitter.save_credentials() find_credential = None for credential in Credential.user_credentials_list: find_credential = Credential.find_by_site_name( credential.site_name) print(find_credential.site_name) return pyperclip.copy(find_credential.password) Credential.copy_credential(self.new_credential.site_name) self.assertEqual('nairobi123', pyperclip.paste()) print(pyperclip.paste())
def save_user(user): ''' Function to save a new user account ''' User.save_user(user)