コード例 #1
0
class TestUser(unittest.TestCase):
    def setUp(self):
        self.new_user = User('Raphael', 'Katana', '0720132613')  #new user

        self.new_credentials = Credentials('1123', 'hjk')  #new credentials

    def test_init(self):
        self.assertEqual(self.new_user.f_name, 'Raphael')
        self.assertEqual(self.new_user.l_name, 'Katana')
        self.assertEqual(self.new_user.p_number, '0720132613')

        #assert test for  credentials

        self.assertEqual(self.new_credentials.acc_name, '1123')
        self.assertEqual(self.new_credentials.password, 'hjk')

    def tearDown(self):
        user_details = []
        user_info = []

    #test to check if user detailsare saved
    def test_save_user(self):
        self.new_user.save_user()
        self.assertEqual(len(User.user_info), 2)

        #test to check if credentials are saved
        self.new_credentials.save_info()
        self.assertEqual(len(Credentials.user_details), 4)

    #Test to check if multiple accounts can be saved
    def test_multi_save(self):
        self.new_user.save_user()
        self.new_user = User('Kk', 'pk', '1432')
        self.assertEqual(len(User.user_info), 1)

        #test for credentials
        self.new_credentials.save_info()
        self.new_credentials = Credentials('23', 'kde')
        self.assertEqual(len(Credentials.user_details), 3)

    #test to check for profile and details
    def check_profile_name(self):
        self.new_credentials.save_info()
        unique_user = Credentials('kbc', '5360')
        unique_user.save_info()
        search_user = Credentials.search_acc_name('kbc')
        self.assertEqual(search_user.password, unique_user.password)

    def test_acc_exists(self):
        self.new_credentials.save_info()
        new_acc = Credentials('kcb', '1020')
        new_acc.save_info()

        new_acc = Credentials.acc_exist('1123')
        self.assertTrue(new_acc)

    def test_show_details(self):
        self.assertEqual(Credentials.show_details(), Credentials.user_details)
コード例 #2
0
    def test_delete_user(self):

	    '''
		delete user's account
		'''

	    self.new_user.save_user()

	    test_user=User("mwalo254","mwalo254")
	    test_user.save_user()
	    self.new_user.delete_user()
	    self.assertEqual(len(User.user_list),1)
コード例 #3
0
    def test_check_user(self):
    
        '''
		Function to test whether the login in function check_user works as expected
		'''
        self.new_user = User("mwalo254","mwalo254")
        self.new_user.save_user()
        user2 = User('nick','nick9214')
        user2.save_user()

        for user in User.user_list:
            if user.lockname == user2.lockname and user.password == user2.password:
	            current_user = user.lockname
        return current_user

        self.assertEqual(current_user,Account.check_user(user2.password,user2.lockname))
コード例 #4
0
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("mwalo","mwalo9214") # create contact object


    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_user.lockname,"mwalo")
        self.assertEqual(self.new_user.password,"mwalo9214")

    def test_save_user(self):
        '''
        test_save_user test case to test if the user's object is saved into the user's list
        '''
        self.new_user.save_user()
        self.assertEqual(len(User.user_list),2)

    def test_delete_user(self):

	    '''
		delete user's account
		'''

	    self.new_user.save_user()

	    test_user=User("mwalo254","mwalo254")
	    test_user.save_user()
	    self.new_user.delete_user()
	    self.assertEqual(len(User.user_list),1)
コード例 #5
0
class testAccounts(unittest.TestCase):
    '''
    Test class that defines test cases for the account class behaviours.
    Args:
        unittest.TestCase: TestCase class that 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("mwalo254","mwalo254")
        self.new_user.save_user()
        user2 = User('nick','nick9214')
        user2.save_user()

        for user in User.user_list:
            if user.lockname == user2.lockname and user.password == user2.password:
	            current_user = user.lockname
        return current_user

        self.assertEqual(current_user,Account.check_user(user2.password,user2.lockname))


    def setUp(self):
        '''      
        Set up method to run before each test cases.
        '''
        self.new_account = Account("Github","mwalo254","mwalo9214")



    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_account.somedia,"Github")
        self.assertEqual(self.new_account.username,"mwalo254")
        self.assertEqual(self.new_account.accpassword,"mwalo9214")

    # def test_save_account(self):
    #     '''
    #     test_save_account test case to test if the account object is saved into
    #      the account list
    #     '''
    #     self.new_account.save_account()
    #     self.assertEqual(len(Account.account_list),1)

    def test_save_account(self):
            '''
            test_save_multiple_account to check if we can save multiple account
            objects to our account_list
            '''
            self.new_account.save_account()
            codewars= Account("Codewars","mwalo254","user11") 
            codewars.save_account()
            self.assertEqual(len(Account.account_list),2)


    def tearDown(self):
            '''
            tearDown method that does clean up after each test case has run.
            '''
            Account.account_list = []
            User.user_list=[]

    def test_display_accounts(self):
        '''
        method that returns a list of all accounts saved
        '''
        self.new_account.save_account()
        codewars = Account('Codewars', 'mwalz','user')
        codewars.save_account()
        gmail= Account('Gmail','mwalznick','mwalz9214')
        gmail.save_account()
        self.assertEqual(len(Account.display_accounts(codewars.somedia)),3)

    def test_find_by_somedia(self):
        '''
		Test to check if the find_by_somedia method returns the correct account
		'''
        self.new_account.save_account()
        codewars = Account('Codewars','mwalz','user')
        codewars.save_account()
        account_exists = Account.find_by_somedia('Codewars')
        self.assertEqual(account_exists,codewars)



    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 = Account("Codewars","mwalz","user")
            test_account.save_account()

            self.new_account.delete_account()
            self.assertEqual(len(Account.account_list),1)


    def test_copy_account(self):
        '''
		test to check if the copy an account method copies the correct account
		'''
        self.new_account.save_account()
        codewars= Account('Codewars','mwalz','user')
        codewars.save_account()
        find_account = None

        for account in Account.user_account_list:
            find_account=Account.find_by_somedia(account.somedia)
            return pyperclip.copy(find_account.accpassword)

        Account.copy_account(self.new_account.somedia)
        self.assertEqual('mwalo9214',pyperclip.paste())
        print(pyperclip.paste())