コード例 #1
0
ファイル: TestClient.py プロジェクト: ioanna14/Python-Project
 def test_search(self):
     from Service.ClientService import ClientService
     self._ClientService = ClientService()
     self.assertEqual(self._ClientService.search('1', '2'),
                      [Client('20', 'Mommy')])
     self.assertEqual(self._ClientService.search('2', 'M'),
                      [Client('17', 'Michael'),
                       Client('20', 'Mommy')])
コード例 #2
0
class TestClient(unittest.TestCase):
    def initialize(self):
        self.c = Client(1, "Marcel Pavel")
        self.c1 = Client(1, "Marcel Pavel")

    def testClient(self):
        self.assertTrue(self.c == Client(1, "Marcel Pavel"))
        self.assertTrue(self.c.__str__() == "ID: 1 Name = Marcel Pavel")
        self.assertTrue(self.c.id == 1)
        self.assertTrue(self.c.name == "Marcel Pavel")
        self.assertTrue(self.c.__eq__(self.c1))
コード例 #3
0
 def test_create_client(self):
     client_id = 22
     name = "Dan"
     client = Client(client_id, name)
     assert (client.get_clientid() == 22)
     assert (client.get_name() == "Dan")
     client.set_clientid(21)
     assert (client.get_clientid() == 21)
     client.set_name("Flavius")
     assert (client.get_name() == "Flavius")
     self.__client = client
コード例 #4
0
ファイル: Service.py プロジェクト: kms77/University
 def update_client_element(self,clientid,name):
     """
     this function update a client element
     a client element is created
     if it is a good one then it is updated
     otherwise an error is displayed
     """
     client=Client(clientid,name)
     self.__validClient.validate_client(client)
     client3=Client(clientid,None)
     client2=self.__repoClient.search(client3)
     self.__repoClient.update(client)
コード例 #5
0
ファイル: TestClient.py プロジェクト: ioanna14/Python-Project
 def test_Client_class(self):
     c = Client('1', 'George')
     with self.assertRaises(DomainError):
         Client(None, 'Hagi')
     with self.assertRaises(DomainError):
         Client('12', None)
     self.assertEqual(c.clientId, '1')
     self.assertEqual(c.name, 'George')
     self.assertEqual(str(c), 'ID = 1, name = George')
     c1 = Client('20', 'Geo')
     c2 = Client('1', 'George')
     self.assertEqual(c == c1, False)
     self.assertEqual(c == c2, True)
コード例 #6
0
ファイル: Service.py プロジェクト: kms77/University
 def add_rent(self, rentid, movieid, clientid, rented_date, due_date,
              returned_date):
     rent = Rent(rentid, movieid, clientid, rented_date, due_date,
                 returned_date)
     clientidd = Client(clientid, None)
     self.__repoClient.search(clientidd)
     movieid = Movie(movieid, None, None, None)
     self.__repoMovie.search(movieid)
     clients = []
     l = self.__repoRent.get_all()
     for i in range(len(l)):
         if l[i].get_clientid() == rent.get_clientid():
             clients.append(l[i])
     movies = []
     l = self.__repoRent.get_all()
     for i in range(len(l)):
         if l[i].get_movieid() == rent.get_movieid():
             movies.append(l[i])
     self.__validRent.validate_rent(rent, movies, clients)
     self.__repoRent.add(rent)
     rent = copy.deepcopy(rent)
     action = UndoAction(self.__repoRent.remove, self.__repoRent.add, rent,
                         None)
     self.__undoActions.push(action)
     self.__redoActions.clear()
コード例 #7
0
ファイル: Service.py プロジェクト: kms77/University
 def random_client(self, x):
     n = ["Vlad", "Georgiana", "Ana", "Calin", "Andrei", "Izabella"]
     for i in range(x):
         client_id = random.randint(1, 1000)
         name = n[random.randint(0, int(len(n)) - 1)]
         client = Client(client_id, name)
         self.__repoClient.add(client)
コード例 #8
0
ファイル: Service.py プロジェクト: kms77/University
 def remove_client_element(self,clientid):
     """
     this function create a client element
     then the client element is verificated
     if it is a good one then it is removed from the list
     otherwise an error is displayed
     """
     client=Client(clientid,None)
     client=self.__repoClient.remove(client)
コード例 #9
0
ファイル: Service.py プロジェクト: kms77/University
 def add_client_element(self,clientid,name):
     """
     this function create a client element
     then the cleint element is verificated
     if it is a good one then it is added to list
     otherwise an error is displayed
     """
     client=Client(clientid,name)
     self.__validClient.validate_client(client)
     self.__repoClient.add(client)
コード例 #10
0
 def test_repo_client(self):
     repo = Repo_movie()
     assert (repo.number_of_elements() == 0)
     self.__client = Client(22, "Dan")
     repo.add(self.__client)
     assert (repo.number_of_elements() == 1)
     keyClient = Client(self.__client.get_clientid(), None)
     foundClient = repo.search(keyClient)
     assert (foundClient.get_name() == self.__client.get_name())
     self.__clientSameid = Client(22, "Alex")
     try:
         repo.add(self.__clientSameid)
         assert (False)
     except RepoError as re:
         assert (str(re) == "Existing id!\n")
     self.__clientDifferentid = Client(10, "Alex")
     try:
         repo.search(self.__clientDifferentid)
         assert (False)
     except RepoError as re:
         assert (str(re) == "Inexisting id!\n")
コード例 #11
0
 def test_validator_client(self):
     validatorClient = Validator_client()
     validatorClient.validate_client(self.__client)
     self.__clientid = Client(-23, "Dan")
     self.__clientname = Client(23, "")
     self.__client = Client(-23, "")
     try:
         validatorClient.validate_client(self.__clientid)
         assert (False)
     except ValidError as val:
         assert (str(val) == "Invalid id!\n")
     try:
         validatorClient.validate_client(self.__clientname)
         assert (False)
     except ValidError as val:
         assert (str(val) == "Invalid name!\n")
     try:
         validatorClient.validate_client(self.__client)
         assert (False)
     except ValidError as val:
         assert (str(val) == "Invalid id!\nInvalid name!\n")
コード例 #12
0
ファイル: Service.py プロジェクト: kms77/University
 def remove_client_element(self, clientid):
     """
     this function create a client element
     then the client element is verificated
     if it is a good one then it is removed from the list
     otherwise an error is displayed
     """
     client = Client(clientid, None)
     client = self.__repoClient.remove(client)
     action = UndoAction(self.__repoClient.add, self.__repoClient.remove,
                         client, None)
     self.__undoActions.push(action)
     self.__redoActions.clear()
コード例 #13
0
ファイル: Service.py プロジェクト: kms77/University
 def add_client_element(self, clientid, name):
     """
     this function create a client element
     then the cleint element is verificated
     if it is a good one then it is added to list
     otherwise an error is displayed
     """
     client = Client(clientid, name)
     self.__validClient.validate_client(client)
     self.__repoClient.add(client)
     action = UndoAction(self.__repoClient.remove, self.__repoClient.add,
                         client, None)
     self.__undoActions.push(action)
     self.__redoActions.clear()
コード例 #14
0
ファイル: TestServie.py プロジェクト: ioanna14/Python-Project
 def test_functions_undo_redo(self):
     self.bookS = BookService()
     self.clientS = ClientService()
     self.rentalS = RentalService()
     self.undo_list = []
     self.redo_list = []
     self._service = Service(self.bookS, self.clientS, self.rentalS)
     book = Book('121', 'Nope', 'John')
     client = Client('223', 'Poppy')
     self._service.book_add(book)
     self.assertEqual(len(self.bookS.display()), 11)
     self._service.book_remove(book)
     self.assertEqual(len(self.bookS.display()), 10)
     self._service.client_add(client)
     self.assertEqual(len(self.clientS.display()), 11)
     self._service.client_remove(client)
     self.assertEqual(len(self.clientS.display()), 10)
     rental = Rental('212', '121', '223', ['14', '1', '2018'],
                     ['29', '5', '2019'])
     rentals = [
         Rental('212', '121', '223', ['14', '1', '2018'],
                ['29', '5', '2019']),
         Rental('002', '121', '223', ['18', '3', '2014'],
                ['29', '7', '2019'])
     ]
     self._service.rental_add(rental)
     self.assertEqual(len(self.rentalS.display()), 11)
     self._service.rental_remove(rental)
     self.assertEqual(len(self.rentalS.display()), 10)
     self._service.add_books_rentals(book, rentals)
     self.assertEqual(len(self.bookS.display()), 11)
     self.assertEqual(len(self.rentalS.display()), 12)
     self._service.remove_books_rentals(book, rentals)
     self.assertEqual(len(self.bookS.display()), 10)
     self.assertEqual(len(self.rentalS.display()), 10)
     self._service.add_client_rentals(client, rentals)
     self.assertEqual(len(self.clientS.display()), 11)
     self.assertEqual(len(self.rentalS.display()), 12)
     self._service.remove_client_rentals(client, rentals)
     self.assertEqual(len(self.clientS.display()), 10)
     self.assertEqual(len(self.rentalS.display()), 10)
     b1 = ['121', 'Nope', 'John']
     c1 = ['223', 'Poppy']
     b = ['121', 'Mommy', 'Lilly']
     c = ['223', 'Mark']
     self.assertEqual(self._service.book_update_undo(b1, b), b)
     self.assertEqual(self._service.book_update_redo(b1, b), b1)
     self.assertEqual(self._service.client_update_undo(c1, c), c)
     self.assertEqual(self._service.client_update_redo(c1, c), c1)
コード例 #15
0
 def testClient(self):
     self.assertTrue(self.c == Client(1, "Marcel Pavel"))
     self.assertTrue(self.c.__str__() == "ID: 1 Name = Marcel Pavel")
     self.assertTrue(self.c.id == 1)
     self.assertTrue(self.c.name == "Marcel Pavel")
     self.assertTrue(self.c.__eq__(self.c1))
コード例 #16
0
 def initialize(self):
     self.c = Client(1, "Marcel Pavel")
     self.c1 = Client(1, "Marcel Pavel")
コード例 #17
0
class Test(object):
    def __int__(self):
        pass

    def test_create_movie(self):
        movie = Movie(
            1, "The Lord of the Rings",
            "The story of the hobbit Frodo Baggins in a fictional word.",
            "epic fantasy adventure film")
        assert (movie.get_movieid() == 1)
        assert (movie.get_title() == "The Lord of the Rings")
        assert (movie.get_description() ==
                "The story of the hobbit Frodo Baggins in a fictional word.")
        assert (movie.get_genre() == "epic fantasy adventure film")
        movie.set_movieid(3)
        assert (movie.get_movieid() == 3)
        movie.set_title("Avengers")
        assert (movie.get_title() == "Avengers")
        movie.set_description(
            "The members of the Avengers attempt to reverse the damage caused by Thanos."
        )
        assert (
            movie.get_description() ==
            "The members of the Avengers attempt to reverse the damage caused by Thanos."
        )
        movie.set_genre("superhero film")
        assert (movie.get_genre() == "superhero film")
        self.__movie = movie

    def test_validator_movie(self):
        validMovie = Validator_movie()
        self.__movie = Movie(
            1, "The Lord of the Rings",
            "The story of the hobbit Frodo Baggins in a fictional word.",
            "epic fantasy adventure film")
        validMovie.validate_movie(self.__movie)
        self.__movie2 = Movie(
            -2, "Home Alone",
            "The eight year old Kevin McCaliister is mistakenly left behind by him family.",
            "comedy film")
        try:
            validMovie.validate_movie(self.__movie2)
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid id!\n")
        self.__movie3 = Movie(1, "The Lord of the Rings", "",
                              "epic fantasy adventure film")
        try:
            validMovie.validate_movie(self.__movie3)
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid description!\n")
        self.__movie4 = Movie(
            1, "The Lord of the Rings",
            "The story of the hobbit Frodo Baggins in a fictional word.", "")
        try:
            validMovie.validate_movie(self.__movie4)
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid genre!\n")
        self.__validMovie = validMovie

    def test_repo_movie(self):
        repo = Repo_movie()
        assert (repo.number_of_elements() == 0)
        repo.add(self.__movie)
        assert (repo.number_of_elements() == 1)
        keymovie = Movie(self.__movie.get_movieid(), None, None, None)
        findmovie = repo.search(keymovie)
        assert (findmovie.get_title() == self.__movie.get_title())
        self.__movie_dif_title_same_id = Movie(
            1, "Home Alone",
            "The eight year old Kevin McCaliister is mistakenly left behind by him family.",
            "comedy film")
        try:
            repo.add(self.__movie_dif_title_same_id)
            assert (False)
        except RepoError as re:
            assert (str(re) == "Existing id!\n")
        self.__inexisting_student = Movie(
            21, "Home Alone",
            "The eight year old Kevin McCaliister is mistakenly left behind by him family.",
            "comedy film")
        try:
            repo.search(self.__inexisting_student)
            assert (False)
        except RepoError as re:
            assert (str(re) == "Inexisting id!\n")
        movie = Movie(None, None, None, None)
        movies = repo.get_all()
        self.__repo = repo

    def test_service_movie(self):
        repoMovie = Repo_movie()
        validMovie = Validator_movie()
        self.__serv = Construct_Movie(validMovie, repoMovie)
        assert (self.__serv.all_movies() == 0)
        self.__serv.add_movie_element(
            1, "The Lord of the Rings",
            "The story of the hobbit Frodo Baggins in a fictional word.",
            "epic fantasy adventure film")
        assert (self.__serv.all_movies() == 1)
        movie = self.__serv.search_movie_by_id(1)
        assert (movie.get_title() == "The Lord of the Rings")
        assert (movie.get_description() ==
                "The story of the hobbit Frodo Baggins in a fictional word.")
        assert (movie.get_genre() == "epic fantasy adventure film")
        try:
            self.__serv.add_movie_element(-2, "", "Description", "action")
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid id!\nInvalid title!\n")
        try:
            self.__serv.add_movie_element(1, "Zlatan", "The story of Zlatan.",
                                          "action film")
            assert (False)
        except RepoError as re:
            assert (str(re) == "Existing id!\n")
        try:
            self.__serv.update_movie_element(2, "Zlatan",
                                             "The story of Zlatan.",
                                             "action film")
            assert (False)
        except RepoError as re:
            assert (str(re) == "Inexisting id!\n")
        self.__serv.update_movie_element(1, "Zlatan", "The story of Zlatan.",
                                         "action film")
        assert (self.__serv.all_movies() == 1)
        movie = self.__serv.search_movie_by_id(1)
        assert (movie.get_title() == "Zlatan")
        assert (movie.get_description() == "The story of Zlatan.")
        assert (movie.get_genre() == "action film")
        self.__serv.remove_movie_element(1)
        assert (self.__serv.all_movies() == 0)
        try:
            self.__serv.remove_movie_element(1)
            assert (False)
        except RepoError as re:
            assert (str(re) == "Inexisting id!\n")

    def test_create_client(self):
        client_id = 22
        name = "Dan"
        client = Client(client_id, name)
        assert (client.get_clientid() == 22)
        assert (client.get_name() == "Dan")
        client.set_clientid(21)
        assert (client.get_clientid() == 21)
        client.set_name("Flavius")
        assert (client.get_name() == "Flavius")
        self.__client = client

    def test_validator_client(self):
        validatorClient = Validator_client()
        validatorClient.validate_client(self.__client)
        self.__clientid = Client(-23, "Dan")
        self.__clientname = Client(23, "")
        self.__client = Client(-23, "")
        try:
            validatorClient.validate_client(self.__clientid)
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid id!\n")
        try:
            validatorClient.validate_client(self.__clientname)
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid name!\n")
        try:
            validatorClient.validate_client(self.__client)
            assert (False)
        except ValidError as val:
            assert (str(val) == "Invalid id!\nInvalid name!\n")

    def test_repo_client(self):
        repo = Repo_movie()
        assert (repo.number_of_elements() == 0)
        self.__client = Client(22, "Dan")
        repo.add(self.__client)
        assert (repo.number_of_elements() == 1)
        keyClient = Client(self.__client.get_clientid(), None)
        foundClient = repo.search(keyClient)
        assert (foundClient.get_name() == self.__client.get_name())
        self.__clientSameid = Client(22, "Alex")
        try:
            repo.add(self.__clientSameid)
            assert (False)
        except RepoError as re:
            assert (str(re) == "Existing id!\n")
        self.__clientDifferentid = Client(10, "Alex")
        try:
            repo.search(self.__clientDifferentid)
            assert (False)
        except RepoError as re:
            assert (str(re) == "Inexisting id!\n")

    def test_service_client(self):
        validatorClient = Validator_client()
        repoClient = Repo_movie()
        self.__service = Construct_Client(validatorClient, repoClient)
        assert (self.__service.no_of_clients() == 0)
        clientid = 24
        name = "Izabella"
        self.__service.add_client_element(clientid, name)
        assert (self.__service.no_of_clients() == 1)
        foundClient = self.__service.search_client_by_id(24)
        assert (foundClient.get_name() == "Izabella")
        try:
            self.__service.add_client_element(-33, "")
            assert (False)
        except ValidError as ve:
            assert (str(ve) == "Invalid id!\nInvalid name!\n")
        try:
            self.__service.add_client_element(24, "Alex")
            assert (False)
        except RepoError as re:
            assert (str(re) == "Existing id!\n")
        try:
            self.__service.update_client_element(2, "Claudiu")
            assert (False)
        except RepoError as re:
            assert (str(re) == "Inexisting id!\n")
        self.__service.update_client_element(24, "Dan")
        assert (self.__service.no_of_clients() == 1)
        client = self.__service.search_client_by_id(24)
        assert (client.get_name() == "Dan")
        try:
            self.__service.remove_client_element(2)
            assert (False)
        except RepoError as re:
            assert (str(re) == "Inexisting id!\n")
        self.__service.remove_client_element(24)
        assert (self.__service.no_of_clients() == 0)

    def run_all_tests(self):
        self.test_create_movie()
        self.test_validator_movie()
        self.test_repo_movie()
        self.test_service_movie()
        self.test_create_client()
        self.test_validator_client()
        self.test_repo_client()
        self.test_service_client()
コード例 #18
0
ファイル: Service.py プロジェクト: kms77/University
 def search_client_by_id(self, clientid):
     client = Client(clientid, None)
     return self.__repoClient.search(client)
コード例 #19
0
ファイル: TestClient.py プロジェクト: ioanna14/Python-Project
 def test_add(self):
     from Service.ClientService import ClientService
     self._ClientService = ClientService()
     self._ClientService.add('121', 'Johnny')
     self.assertEqual(self._ClientService.display()[-1],
                      Client('121', 'Johnny'))
コード例 #20
0
ファイル: TestClient.py プロジェクト: ioanna14/Python-Project
 def test_update(self):
     from Service.ClientService import ClientService
     self._ClientService = ClientService()
     self._ClientService.update('11', 'Lilly')
     self.assertEqual(self._ClientService.display()[0],
                      Client('11', 'Lilly'))