Beispiel #1
0
class TestUsers(unittest.TestCase):
    """
  This is a test class that defines the test cases for the users class behavior

  Args:
	    unittest.TestCase: helps in creating test cases
  """
    def setUp(self):
        '''
    Method that runs before each test case to ensure objects are being instantiated correctly
    '''
        self.new_user = User("BMuthoni", "pass@word")

    def tearDown(self):
        User.users_list = []

    def test_init(self):
        self.assertEqual(self.new_user.user_name, "BMuthoni")
        self.assertEqual(self.new_user.password, "pass@word")

    def test_save_user(self):
        '''
    Test case to confirm that user objects are being saved to the user list
    '''
        self.new_user.save_user()  #saving a new user
        self.assertEqual(len(User.users_list), 1)

    def test_delete_user(self):
        '''
    Test to check whether a user can remove their account
    
    '''
        self.new_user.save_user()
        test_user = User("BMuthoni", "4676jl")
        test_user.save_user()
        self.new_user.delete_user()
        self.assertEqual(len(User.users_list), 1)

    def test_find_user(self):
        '''
    Test case to check test whether a user can only login once they have created an account

		'''
        self.new_user.save_user()
        test_user = User("Muthoni", "pass@word")
        test_user.save_user()
        for user in User.users_list:
            if user.user_name == test_user.user_name and user.password == test_user.password:
                current_user = user.user_name
                return current_user
        self.assertEqual(
            current_user,
            User.find_user(test_user.password, test_user.user_name))
Beispiel #2
0
class TestUser(unittest.TestCase):
    '''
    Test class defining test cases for the users class behavior

    '''
    def setUp(self):
        '''
        method that runs before each Test
        '''
        self.new_user = User("Michael", "Mbogo", "Michaelmm17")  #create users

    def test_init(self):
        '''
        Test case to check proper initialization
        '''

        self.assertEqual(self.new_user.first_name, "Michael")
        self.assertEqual(self.new_user.last_name, "Mbogo")
        self.assertEqual(self.new_user.password, "Michaelmm17")

    def test_save_user(self):
        '''
        tests if the user is saved in the user list
        '''

        self.new_user.save_user()  #saves new users
        self.assertEqual(len(User.user_list), 1)

    def tearDown(self):
        '''
        cleans up after each TestCase is made
        '''
        User.user_list = []

    def test_save_multiple_user(self):
        '''
        check to see if multiple users can be saved
        '''

        self.new_user.save_user()
        test_user = User("Ann", "Bridgit", "brig13")

        test_user.save_user()
        self.assertEqual(len(User.user_list), 2)

    def test_delete_user(self):
        '''
        Deletes the user from the user_list
        '''

        self.new_user.save_user()
        test_user = User("Ann", "Bridgit", "brig13")

        test_user.save_user()

        self.new_user.delete_user()
        self.assertEqual(len(User.user_list), 1)

    def test_display_user(self):
        '''
        displays all user
        '''

        self.assertEqual(User.display_user(), User.user_list)
class TestUser(unittest.TestCase):

    """
    Test class that defines te test case for the User behavior
    Args:
        unittest.TestCase: Test class that helps create the test case
    """

    def setUp(self):

        """
        Set up method to run before each test case
        """

        self.new_user = User("Gabriel","Oduori","*****@*****.**", "gabriel@moringa")# create contact object

    def test_instance(self):
        """
        Test instance case to test if the object initialized properly
        """
        self.assertEqual(self.new_user.first_name, "Gabriel")
        self.assertEqual(self.new_user.last_name,"Oduori")
        self.assertEqual(self.new_user.user_email,"*****@*****.**")
        self.assertEqual(self.new_user.user_password,"password4me")
    
    def test_save_user(self):
        """
        test_save_user test case to test if the contact object is saved into
        the user list
        """
        self.new_user.save_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=[]
        
    def test_save_multiple_users(self):
        """
        test_save_multiple_users check if we can save multiple user
        objects to our user_list
        """
        self.new_user.save_user()
        test_user= User("FirstName","LastName","*****@*****.**", "AnotherPassword")
        test_user.save_user()
        self.assertEqual(len(User.users_list),2)
        
        
    def test_delete_user(self):
        """
        test_delete_user method tests if we can remove a user from the user_list
        """
        self.new_user.save_user()
        test_user= User("FirstName","LastName","*****@*****.**", "AnotherPassword")
        test_user.save_user()
        
        self.new_user.delete_user()
        self.assertEqual(len(User.users_list),1)
        
    def test_user_exists(self):
        """
        test_user_exists test case to test if the user exists in the
        list of users.
        """
        self.new_user = User("Gabriel","Oduori","*****@*****.**", "password4me")# create contact object
        self.new_user.save_user()
        user_exists = User.user_exists("*****@*****.**")
        self.assertTrue(user_exists)
        
    def test_authenticate_password(self):
        """
        test_authenticate_password checks if the password exists for login purposes
        """
        self.new_user = User("Gabriel","Oduori","*****@*****.**", "password4me")# create contact object
        self.new_user.save_user()
        true_password = User.authenticate_password("password4me")
        self.assertTrue(true_password)