Ejemplo n.º 1
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):
        '''
    setUp method to run before each test cases
    '''

        self.new_user = User("User1", "TheFirst")

    def tearDown(self):
        '''
    tearDown method to clean up after each test case has run
    '''

        User.user_list = []

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

        self.assertEqual(self.new_user.user_name, "User1")
        self.assertEqual(self.new_user.password, "TheFirst")

    def test_save_user(self):
        '''
    test_save_user case to test if object is saved to user_list list
    '''

        self.test_user = User("User2", "The2")
        self.test_user.save_user()
        self.assertEqual(len(User.user_list), 1)

    def test_save_multiple_user(self):
        '''
    test_save_multiple_user case to test if multiple user objects can be saved to user_list
    '''

        self.test_user = User("User2", "The2")
        self.new_user.save_user()
        self.test_user.save_user()
        self.assertEqual(len(User.user_list), 2)

    def test_delete_user(self):
        '''
    test_delete_user case to test if user can be deleted from user_list
    '''

        self.new_user.save_user()
        self.test_user = User("User2", "The2")
        self.test_user.save_user()

        self.test_user.delete_user()
        self.assertEqual(len(User.user_list), 1)
Ejemplo n.º 2
0
class TestUser(unittest.TestCase):
    def setUp(self):
        '''
        Set up method to run before  each test
        '''
        self.new_user = User("Beryl", "Onyancha", "skittles")

    def tearDown(self):
        '''
        Tear down method performs clean up after each test method completes
        '''
        User.user_list = []

    def test_init(self):
        '''
        Test to check if initialization has been done
        '''
        self.assertEqual(self.new_user.first_name, "Beryl")
        self.assertEqual(self.new_user.last_name, "Onyancha")
        self.assertEqual(self.new_user.password, "skittles")

    def test_save_user(self):
        '''
        Test to check if users are added to the user list
        '''
        self.new_user.save_user()
        self.assertEqual(len(User.user_list), 1)

    def test_delete_user(self):
        '''
        Test to check if users can be deleted from the users list
        '''
        self.new_user.save_user()
        test_user = User("Test", "user", "1234")
        test_user.save_user()
        self.new_user.delete_user()
        self.assertEqual(len(User.user_list), 1)
Ejemplo n.º 3
0
class TestUser(unittest.TestCase):
    '''
    Test class that defines test cases for the user class behaviors.

    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("toni", "1234",
                             "*****@*****.**")  # create contact object

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

        self.assertEqual(self.new_user.user_name, "toni")
        self.assertEqual(self.new_user.password, "1234")
        self.assertEqual(self.new_user.email, "*****@*****.**")

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

    def test_save_user(self):
        '''
        test_save_user 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.user_list), 1)

    def test_save_multiple_user(self):
        '''
        test_save_multiple_user to check if we can save multiple user objects to our user_list
        '''
        self.new_user.save_user()
        test_user = User("Test", "0000", "*****@*****.**")  # new user
        test_user.save_user()
        self.assertEqual(len(User.user_list), 2)

    def test_delete_user(self):
        '''
        test_delete_user to test if we can remove a user from our user list
        '''
        self.new_user.save_user()
        test_user = User("Test", "0000", "*****@*****.**")  # new user
        test_user.save_user()

        self.new_user.delete_user()  # Deleting a user object
        self.assertEqual(len(User.user_list), 1)

    def test_display_user(self):
        '''
        method that returns a list of all users saved
        '''

        self.assertEqual(User.display_users(), User.user_list)