Exemple #1
0
def delete_credential(credentials):
    '''
    Function that deletes credentials that are no longer in use
    '''
    return Credential.delete_credentials(credentials)
Exemple #2
0
 def test_delete_credentials(self):
     self.new_credential.save_credentials()
     twitter = Credential('samuel', 'twitter', 'samuel-sam', '120819985')
     twitter.save_credentials()
     twitter.delete_credentials()
     self.assertEqual(len(Credential.credential_list), 1)
Exemple #3
0
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('shadrack', 'maestro', 's1234')
        self.new_user.save_users()
        addUser = User('', '', '')  # test if another user will be added
        addUser.save_users()

        for user in User.user_list:
            if user.username == addUser.username and user.password == addUser.password:
                current_user = user.username
        return current_user

        self.assertEqual(
            current_user,
            Credential.check_user(addUser.password, addUser.username))

    def tearDown(self):
        '''
		tearDown method that does clean up after each test case has run.
		'''
        Credential.cred_list = []

    def setUp(self):
        '''
		Set up method to run before each test cases.
		'''
        self.new_credential = Credential('shadrack', 'Facebook', 's1234')

    def test__init__(self):
        '''
		Test to  check if the initialization/creation of credential instances is properly done
		'''
        self.assertEqual(self.new_credential.user_name, 'shadrack')
        self.assertEqual(self.new_credential.site_name, 'Facebook')
        self.assertEqual(self.new_credential.password, 's1234')

    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('shadrack', 'Twitter', 's1234')
        twitter.save_credentials()
        self.assertEqual(len(Credential.cred_list), 2)

#testing testing

    def test_user_name_exists(self):
        '''
		test to check if we can return a Boolean  if we cannot find the sitename.
		'''

    @classmethod
    def user_name_exist(cls, user_name):
        '''
		Method that checks if a user name exists from the cred list.
		Args:
			user_namae: user name to  search if it exists
		Returns :
			Boolean: True or false depending if the site exists
		'''
        self.new_credential.save_credentials()
        test_user_name = Credential("user", "site", "pass")  # new cred
        test_user_name.save_credentials()

        user_name_exists = Credential.user_name_exist("user")

        self.assertTrue(user_name_exists)

        for cred in cls.cred_list:
            if cred.user_name == user_name:
                return True

        return False

    def test_copy_password(self):
        '''
		Test to confirm that we are copying the password 
		'''

    @classmethod
    def copy_password(cls, password):
        pass_found = Credential.find_by_sitename(site_name)
        pyperclip.copy(pass_found.password)

        self.new_contact.save_contact()
        Credential.copy_password("1234")

        self.assertEqual(self.new_user.password, pyperclip.paste())

    def test_delete_credential(self):
        """
		test method to test if we can remove an account credentials from our cred_list
		"""
        self.new_credential.save_credentials()
        test_credential = Credential("user", "site", "pass")
        test_credential.save_credentials()

        self.new_credential.delete_credentials()
        self.assertEqual(len(Credential.cred_list), 1)
        #testing

    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.new_credential.save_credentials()
        test_credential = Credential("user", "site", "pass")
        test_credential.save_credentials()

        credential = Credential.find_credential("user")

        self.assertEqual(credential.user_name, test_credential.user_name)

    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.new_credential.save_credentials()
        credential = Credential("user", "site", "pass")
        credential.save_credentials()
        credential_is_found = Credential.if_credential_exist("user")
        self.assertTrue(credential_is_found)
Exemple #4
0
class TestUser(unittest.TestCase):
    """
    Test class that defines test cases for the user class behaviours.

    Args:
         unittest.TestCase:TestCase that help in creating test cases
    """
    def setUp(self):
        """
        set up method to run before each test cases.
        """
        # self.new_user = User("owinolawrence", "2019")
        self.new_credential = Credential("owinolawrence", "twitter", "2018")

    def test_init(self):
        """
        test_init test case to test if the object is initialized properly
        """
        # self.assertEqual(self.new_user.login_username, "owinolawrence")
        # self.assertEqual(self.new_user.user_password, "2019")
        self.assertEqual(self.new_credential.account_name, "twitter")
        self.assertEqual(self.new_credential.account_password, "2018")

    def test_save_object(self):
        """
        test_save_object test case to test if the object will be save in user list and credential list
        """
        # self.new_user.save_detail()
        # self.new_credential.save_credential()

        # self.assertEqual(len(User.user_list), 1)
        # self.assertEqual(len(Credential.credential_list), 1)

    def tearDown(self):
        """
        tearDown method that does clean up after test case has run.
        """
        User.user_list = []
        Credential.credential_list = []

    def test_delete_user(self):
        """
        test_delete_user to test if we can remove a user from the user list
        """

    def test_delete_credentials(self):
        """
        test to check if the user can delete his or her credentials
        """
        self.new_credential.save_credential()
        test_credential = Credential("owinolawrence", "instragram", "2017")
        test_credential.save_credential()
        self.new_credential.delete_credentials(
        )  # Deleting a credential object
        # self.assertEqual(len(Credential.credential_list), 1)

    def test_find_user_by_name(self):
        """
        test to check if we can find a user by using  account name and display information
        """
        self.new_credential.save_credential()
        test_credential = Credential("owinolawrence", "twitter", "2018")
        test_credential.save_credential()
        found_credential = Credential.find_by_name("twitter")
        self.assertEqual(found_credential.account_password, "2018")

    def test_credential_exists(self):
        """
        test to check if we can return a Boolean if we cannot find the account name
        """
        self.new_credential.save_credential()
        test_credential = Credential("owinolawrence", "twitter", "2018")
        test_credential.save_credential()
        credential_exist = Credential.credential_exists("twitter")
        self.assertTrue(credential_exist)

    def test_display_all_credential(self):
        '''
        method that return all the credential saved
        '''

        self.assertEqual(Credential.display_credentials(),
                         Credential.credentials_list)