Beispiel #1
0
 def remove_client(self, client_name, client_id):
     client_to_remove = Client(client_name)
     client_to_remove.id = client_id
     try:
         self._repository.remove_element(client_to_remove)
     except RepositoryException as e:
         print(e)
Beispiel #2
0
 def test_str__valid_input__correct_creation_of_object(self):
     client = Client("Andrei Popa")
     self.assertTrue(client.name, "Andrei Popa")
     client.creation_date = Date(15, 4, 2020)
     self.assertTrue(str(client.creation_date), "15-04-2020")
     self.assertTrue(str(client.expiration_date), "15-07-2020")
     client.id = "1234"
     self.assertTrue(str(client.id), "1234")
Beispiel #3
0
 def test_remove_element__invalid_input__throw_exception(self):
     client = Client()
     repository = FileRepository("test.txt", Client.read_from_file, Client.write_to_file)
     with self.assertRaises(RepositoryException):
         repository.remove_element(client)
     f = open('test.txt', 'w')
     f.close()
Beispiel #4
0
 def add_client(self, client_name):
     Valid.validate_name(client_name)
     client = Client(client_name)
     try:
         self._repository.add_element(client)
     except RepositoryException as e:
         print(e)
Beispiel #5
0
 def test_add_element__valid_input__correct_addition_of_element_to_the_list(self):
     client_to_add = Client("Andrei Popa")
     repository = FileRepository("test.txt", Client.read_from_file, Client.write_to_file)
     repository.add_element(client_to_add)
     list_of_clients = repository.get_all()
     self.assertEqual(list_of_clients[0].name, "Andrei Popa")
     f = open('test.txt', 'w')
     f.close()
Beispiel #6
0
 def test_remove_element__valid_input__correct_removal_of_object(self):
     client = Client("Andrei Popa")
     repository = FileRepository("test.txt", Client.read_from_file, Client.write_to_file)
     repository.add_element(client)
     repository.remove_element(client)
     list_of_client = repository.get_all()
     self.assertEqual(list_of_client, [])
     f = open('test.txt', 'w')
     f.close()
Beispiel #7
0
 def test_add_element__invalid_input__throw_exception(self):
     client1 = Client("Andrei Popa")
     client2 = Client("Andrei Popa")
     repository = FileRepository("test.txt", Client.read_from_file, Client.write_to_file)
     client1.id = "1234"
     client2.id = "1234"
     repository.add_element(client1)
     with self.assertRaises(RepositoryException):
         repository.add_element(client2)
     f = open('test.txt', 'w')
     f.close()