Пример #1
0
class TestsFourthFunctionality(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

    def initialize(self):
        undoStack = Stack()
        redoStack = Stack()
        self.__valid_movie = ValidMovie()
        self.__valid_client = ValidClient()
        self.__valid_rental = ValidRental()
        self.__movies_repository = Repository()
        self.__clients_repository = Repository()
        self.__rentals_repository = Repository()
        self.__service_movies = ServiceMovies(self.__movies_repository,
                                              self.__valid_movie, undoStack,
                                              redoStack,
                                              self.__rentals_repository)
        self.__service_clients = ServiceClients(self.__clients_repository,
                                                self.__valid_client, undoStack,
                                                redoStack,
                                                self.__rentals_repository)
        self.__service_rentals = ServiceRentals(self.__movies_repository,
                                                self.__clients_repository,
                                                self.__rentals_repository,
                                                self.__valid_rental, undoStack,
                                                redoStack)
        self.__service_movies.generate_movies()
        self.__service_clients.generate_client()

        self.__service_rentals.rent_movie(1, 1, 1, '1/1/1', '2/1/1')
        self.__service_rentals.return_movie(1, '3/1/1')
        self.__service_rentals.rent_movie(3, 1, 1, '5/1/1', '10/1/1')
        self.__service_rentals.return_movie(3, '15/1/1')
        self.__service_rentals.rent_movie(2, 2, 2, '2/2/2', '3/3/3')
        self.__service_rentals.return_movie(2, '7/2/2')
        self.__service_rentals.rent_movie(4, 3, 4, '1/1/1', '2/1/1')
        self.__service_rentals.return_movie(4, '2/1/1')

    def test_most_rented(self):
        self.initialize()
        result = self.__service_rentals.most_rented()
        self.assertEqual(result[0].movie.get_id(), 1)
        self.assertEqual(result[1].movie.get_id(), 2)
        self.assertEqual(result[2].movie.get_id(), 3)

    def test_most_active(self):
        self.initialize()
        result = self.__service_rentals.most_active()
        self.assertEqual(result[0].client.get_id(), 1)
        self.assertEqual(result[1].client.get_id(), 2)
        self.assertEqual(result[2].client.get_id(), 4)

    def test_late_rentals(self):
        self.initialize()
        self.__service_rentals.rent_movie(11, 1, 1, '4/4/4', '5/5/5')
        self.__service_rentals.rent_movie(12, 2, 2, '4/4/4', '5/5/5')
        result = self.__service_rentals.late_rentals()
        print(result)
        self.assertEqual(result[0].movie_id, 1)
        self.assertEqual(result[1].movie_id, 2)
Пример #2
0
        repository_movie = Repository()
        repository_client = Repository()
        repository_rental = Repository()
        ''' Services '''
        service_movie = ServiceMovies(repository_movie, valid_movie,
                                      undo_stack, redo_stack,
                                      repository_rental)
        service_client = ServiceClients(repository_client, valid_client,
                                        undo_stack, redo_stack,
                                        repository_rental)
        service_rental = ServiceRentals(repository_movie, repository_client,
                                        repository_rental, valid_rental,
                                        undo_stack, redo_stack)
        service_undo = ServiceUndo(undo_stack, redo_stack)
        ''' Initializing '''
        service_movie.generate_movies()
        service_client.generate_client()

    elif line[2] == "text":
        from text_files import FileRepo

        line = file.readline().strip()
        line = line.split(" ")
        repository_movie = FileRepo(line[2], Movie.read_movie,
                                    Movie.write_movie)

        line = file.readline().strip()
        line = line.split(" ")
        repository_client = FileRepo(line[2], Client.read_client,
                                     Client.write_client)