Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.43 KB | None | 0 0
  1. # File: test_clients_list.py
  2. # Description: Used in Week 08 tutorial 01 task 02 exercise, test fixture and associated test cases
  3. # Author: Chris Knowles
  4. # Date: 4-Dec-2017
  5.  
  6.  
  7. # Imports
  8. import unittest
  9. from data_model.clients_list import ClientsList
  10. from data_model.identified_entity import IdentifiedEntity
  11. from data_model.client import Client
  12.  
  13.  
  14. # Consts
  15. # Globals
  16.  
  17.  
  18. # Classes
  19. class TestClientsList(unittest.TestCase):
  20.     """
  21.    Test fixture to exercise the methods from the clients list class
  22.    """
  23.     def setUp(self):
  24.         """
  25.        Set up run before every test case
  26.  
  27.        :return:
  28.        """
  29.         # Create a new clients list before every test case and add some sample clients to it
  30.         self.clients_list = ClientsList()
  31.  
  32.         # Force the reset of the Client class next identifier counter to 1000, needs to be done through the
  33.         # IdentifiedEntity class since this counter is in the base class
  34.         IdentifiedEntity._IdentifiedEntity__next_id = 1000
  35.  
  36.         # Add 4 instances of clients (with ids of CL1000, CL1001, CL1002, CL1003), note - this is done using the data
  37.         # list accessed directly in clients list instance as we cannot be sure the add() method works yet
  38.         self.clients_list.data.append(Client("Ubisoft Entertainment"))
  39.         self.clients_list.data.append(Client("Electronic Arts Inc"))
  40.         self.clients_list.data.append(Client("Bethesda Softworks LLC"))
  41.         self.clients_list.data.append(Client("Blizzard Entertainment Inc"))
  42.  
  43.     def test_add_new_id(self):
  44.         """
  45.        Test case to check a new client can be added to the clients list using the add() method
  46.  
  47.        :return: None
  48.        """
  49.         # Arrange
  50.         in_client_name = "New Client"
  51.         ex_clients_count = 5
  52.  
  53.         # Act, note - use count of clients in the clients list to check new client has been added (is this the best
  54.         # approach? if not why? and what alternative approach to use?)
  55.         self.clients_list.add(Client(in_client_name))
  56.         ac_clients_count = len(self.clients_list.data)
  57.  
  58.         # Assert
  59.         self.assertEqual(ex_clients_count, ac_clients_count,
  60.                          "Test failed, expected client count: {0} got clients count: {1}".
  61.                          format(ex_clients_count, ac_clients_count))
  62.  
  63.     def test_add_existing_id(self):
  64.         """
  65.        Test case to check a new client can be added to the clients list using the add() method if this will cause a
  66.        clash with an existing client unique identifier
  67.  
  68.        :return: None
  69.        """
  70.         # Arrange, note - we have to artificially reset the next id counter in the Client class so when using add() it
  71.         # tries to use an existing identifier
  72.         IdentifiedEntity._IdentifiedEntity__next_id = 1000  # Force update of private __next_id class property
  73.         in_client_name = "New Client"
  74.         ex_clients_count = 4  # Should not add a new client with existing identifier
  75.  
  76.         # Act, note - use count of clients in the clients list to check new client has been added (is this the best
  77.         # approach? if not why? and what alternative approach to use?)
  78.         self.clients_list.add(Client(in_client_name))
  79.         ac_clients_count = len(self.clients_list.data)
  80.  
  81.         # Assert
  82.         self.assertEqual(ex_clients_count, ac_clients_count,
  83.                          "Test failed, expected client count: {0} got clients count: {1}".
  84.                          format(ex_clients_count, ac_clients_count))
  85.  
  86.     def test_has_client_CL1001(self):
  87.         """
  88.        Test case to check if the has() method returns True if an identifier for an existing client is passed to it
  89.  
  90.        :return: None
  91.        """
  92.         # Arrange
  93.         in_client_id = "CL1001"
  94.  
  95.         # Act
  96.         ac_result = self.clients_list.has(in_client_id)
  97.  
  98.         # Assert
  99.         self.assertTrue(ac_result,
  100.                         "Test failed, expected result of True")
  101.  
  102.     def test_has_client_CL9999(self):
  103.         """
  104.        Test case to check if the has() method returns False if an identifier for a non-existing client is passed to it
  105.  
  106.        :return: None
  107.        """
  108.         # Arrange
  109.         in_client_id = "CL9999"
  110.  
  111.         # Act
  112.         ac_result = self.clients_list.has(in_client_id)
  113.  
  114.         # Assert
  115.         self.assertFalse(ac_result,
  116.                         "Test failed, expected result of False")
  117.  
  118.  
  119. if __name__ == "__main__":
  120.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement