def test_save_details(self): ''' Test case to check if we can save details to the details list. ''' self.new_detail.save_detail() instagram = Details("Deyalasoul", "Instagram", "Deyala", "Roseflower01") instagram.save_detail() self.assertEqual(len(Details.details_list), 2)
def test_find_my_website_name(self): ''' Test case to test if we can search credential by site_name and return the correct credential. ''' self.new_detail.save_detail() twitter = Details('Bill', 'Twitter', 'billy', 'billyboss') twitter.save_detail() detail_exist = Details.find_my_website_name('Twitter') self.assertEqual(detail_exist, twitter)
def test_credential_exists(self): ''' Test case to confirm if a detail exist in the detail_list. ''' self.new_detail.save_detail() test_detail = Details('Bill', 'Twitter', 'billy', 'billyboss') test_detail.save_detail() detail_exists = Details.detail_exist("Twitter") self.assertTrue(detail_exists)
def test_delete_detail(self): ''' Test to see if we can delete a saved detail ''' self.new_detail.save_detail() new_detail = Details('Bill', 'Twitter', 'billy', 'billyboss') new_detail.save_detail() self.new_detail.del_detail() self.assertEqual(len(Details.details_list), 1)
def test_display_details(self): ''' Test case to test if objects show. ''' self.new_detail.save_detail() instagram = Details("Deyalasoul", "Instagram", "Deyala", "Roseflower01") instagram.save_detail() twitter = Details('Bill', 'Twitter', 'billy', 'billyboss') twitter.save_detail() self.assertEqual(len(Details.display_detail(instagram.user_name)), 1)
def test_copy_details(self): ''' Test casse to test if the copy detail function copies the correct detail of the user. ''' self.new_detail.save_detail() facebook = Details('Dolphine', 'Facebook', 'dalphine', 'atieno1997') facebook.save_detail() find_detail = None for detail in Details.users_details_list: find_detail = Details.find_my_website_name(detail.website_name) pyperclip.copy(find_detail.password) Details.copy_detail(self.new_detail.website_name) self.assertEqual('atieno1997', pyperclip.paste())
def save_detail(detail): ''' Function to save a new created detail. ''' Details.save_detail(detail)
class TestDetails(unittest.TestCase): ''' Test class that defines test cases for the 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_detail = Details("Dolphine", "Facebook", "dalphine", "atieno1997") def test__init__(self): ''' Test case to check if details created is properly done. ''' self.assertEqual(self.new_detail.user_name, "Dolphine") self.assertEqual(self.new_detail.website_name, "Facebook") self.assertEqual(self.new_detail.account_name, "dalphine") self.assertEqual(self.new_detail.password, "atieno1997") def tearDown(self): ''' This method clears users details after every test. ''' Details.details_list = [] def test_save_details(self): ''' Test case to check if we can save details to the details list. ''' self.new_detail.save_detail() instagram = Details("Deyalasoul", "Instagram", "Deyala", "Roseflower01") instagram.save_detail() self.assertEqual(len(Details.details_list), 2) def test_display_details(self): ''' Test case to test if objects show. ''' self.new_detail.save_detail() instagram = Details("Deyalasoul", "Instagram", "Deyala", "Roseflower01") instagram.save_detail() twitter = Details('Bill', 'Twitter', 'billy', 'billyboss') twitter.save_detail() self.assertEqual(len(Details.display_detail(instagram.user_name)), 1) def test_find_my_website_name(self): ''' Test case to test if we can search credential by site_name and return the correct credential. ''' self.new_detail.save_detail() twitter = Details('Bill', 'Twitter', 'billy', 'billyboss') twitter.save_detail() detail_exist = Details.find_my_website_name('Twitter') self.assertEqual(detail_exist, twitter) def test_copy_details(self): ''' Test casse to test if the copy detail function copies the correct detail of the user. ''' self.new_detail.save_detail() facebook = Details('Dolphine', 'Facebook', 'dalphine', 'atieno1997') facebook.save_detail() find_detail = None for detail in Details.users_details_list: find_detail = Details.find_my_website_name(detail.website_name) pyperclip.copy(find_detail.password) Details.copy_detail(self.new_detail.website_name) self.assertEqual('atieno1997', pyperclip.paste()) def test_delete_detail(self): ''' Test to see if we can delete a saved detail ''' self.new_detail.save_detail() new_detail = Details('Bill', 'Twitter', 'billy', 'billyboss') new_detail.save_detail() self.new_detail.del_detail() self.assertEqual(len(Details.details_list), 1) def test_credential_exists(self): ''' Test case to confirm if a detail exist in the detail_list. ''' self.new_detail.save_detail() test_detail = Details('Bill', 'Twitter', 'billy', 'billyboss') test_detail.save_detail() detail_exists = Details.detail_exist("Twitter") self.assertTrue(detail_exists)