예제 #1
0
    def testSave(self):
        #We need an empty repo for this test
        self.__clientRepository = Repository(ClientValidator)
        
        self.assertTrue(self.__clientRepository.save(self.__client1), "Could not create student")
        self.assertTrue(self.__clientRepository.save(self.__client2), "Could not create student")
        
#         self.assertRaises(RepositoryException, self.__clientRepository.save(self.__client1))

        try:
            self.__clientRepository.save(self.__client1)
            self.fail("Duplicate ID at saving")
        except RepositoryException:
            pass
        
        try:
            self.__clientRepository.save(self.__client2)
            self.fail("Duplicate ID at saving")
        except RepositoryException:
            pass
        
        try:
            self.__clientRepository.save(Client("ab", "Ada"))
            self.fail("ID must be an integer")
        except RepositoryException:
            pass
        
        self.assertEqual(len(self.__clientRepository.get_all()), 2, "There must be 2 clients already saved")
        self.assertEqual(self.__clientRepository.find_by_id(1), self.__client1, "Client 1 was not save properly")
        self.assertEqual(self.__clientRepository.find_by_id(2), self.__client2, "Client 2 was not save properly")
예제 #2
0
    def setUp(self):
        TestCase.setUp(self)
        self.__clientRepository = Repository(ClientValidator)
        self.__clientRepository.save(Client(1, "Aurica"))
        self.__clientRepository.save(Client(2, "Daniel"))

        self.__clientControler = ClientControler(self.__clientRepository)
예제 #3
0
 def setUp(self):
     self.__clientRepository = Repository(ClientValidator)
     
     self.__client1 = Client(1, "Aurel")
     self.__client2 = Client(2, "Viorel")
     self.__clientRepository.save(self.__client1)
     self.__clientRepository.save(self.__client2)
예제 #4
0
class ClientControllerTest(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.__clientRepository = Repository(ClientValidator)
        self.__clientRepository.save(Client(1, "Aurica"))
        self.__clientRepository.save(Client(2, "Daniel"))

        self.__clientControler = ClientControler(self.__clientRepository)

    def testAdd(self):
        self.__clientControler.add(3, "Dana")
        self.assertEqual(len(self.__clientControler.get_all()), 3)

        #It is not the responsabilty of controller to check if entity is duplicated
#         try:
#             self.__clientControler.add(1,"Aurica")

    def testRemove(self):
        self.__clientControler.remove(1)
        self.assertEqual(len(self.__clientControler.get_all()), 1)
예제 #5
0
    def setUp(self):
        TestCase.setUp(self)
        self.__rentalRepository = Repository(RentalValidator)
        self.__movieRepository = Repository(MovieValidator)
        self.__clientRepository = Repository(ClientValidator)

        self.__movieRepository.save(Movie(1, "Ana", "Bun", "Comedie"))
        self.__clientRepository.save(Client(1, "Aurica"))
        self.__rentalRepository.save(
            Rental(1, 1, 1, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), None))

        self.__movieRepository.save(Movie(2, "Dana Film", "Nebun", "Drama"))
        self.__clientRepository.save(Client(2, "Daniel"))
        self.__rentalRepository.save(
            Rental(2, 2, 2, datetime.date(2016, 12, 15),
                   datetime.date(2017, 1, 5), None))

        self.__movieRepository.save(Movie(3, "Bolt", "D-amar", "Actiune"))
        self.__clientRepository.save(Client(3, "Liviu"))
        self.__rentalRepository.save(
            Rental(3, 3, 3, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), datetime.date(1997, 11, 13)))

        self.__movieRepository.save(Movie(4, "Flash", "Great", "Actiune"))
        self.__clientRepository.save(Client(4, "Radu"))
        self.__rentalRepository.save(
            Rental(4, 4, 4, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), datetime.date(1997, 11, 5)))

        self.__rentalRepository.save(
            Rental(5, 4, 4, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), datetime.date(1997, 11, 5)))

        self.__statisticsController = StatisticsControler(
            self.__rentalRepository, self.__movieRepository,
            self.__clientRepository)
예제 #6
0
class RepositoryTest(TestCase):

    def setUp(self):
        self.__clientRepository = Repository(ClientValidator)
        
        self.__client1 = Client(1, "Aurel")
        self.__client2 = Client(2, "Viorel")
        self.__clientRepository.save(self.__client1)
        self.__clientRepository.save(self.__client2)
        
    def testSave(self):
        #We need an empty repo for this test
        self.__clientRepository = Repository(ClientValidator)
        
        self.assertTrue(self.__clientRepository.save(self.__client1), "Could not create student")
        self.assertTrue(self.__clientRepository.save(self.__client2), "Could not create student")
        
#         self.assertRaises(RepositoryException, self.__clientRepository.save(self.__client1))

        try:
            self.__clientRepository.save(self.__client1)
            self.fail("Duplicate ID at saving")
        except RepositoryException:
            pass
        
        try:
            self.__clientRepository.save(self.__client2)
            self.fail("Duplicate ID at saving")
        except RepositoryException:
            pass
        
        try:
            self.__clientRepository.save(Client("ab", "Ada"))
            self.fail("ID must be an integer")
        except RepositoryException:
            pass
        
        self.assertEqual(len(self.__clientRepository.get_all()), 2, "There must be 2 clients already saved")
        self.assertEqual(self.__clientRepository.find_by_id(1), self.__client1, "Client 1 was not save properly")
        self.assertEqual(self.__clientRepository.find_by_id(2), self.__client2, "Client 2 was not save properly")
        
    def testRemove(self):
        #These 2 lines are almost same thing
        self.assertEqual(self.__clientRepository.remove(1), self.__client1, "Client 1 was not deleted")
        self.assertEqual(self.__clientRepository.find_by_id(1), None, "Client 1 was not deleted properly")
        
        try:
            self.__clientRepository.remove(3)
            self.fail("There is no element 3 in repository")
        except RepositoryException:
            pass
        
        try:
            self.__clientRepository.remove(1)
            self.fail("There is no element 3 in repository")
        except RepositoryException:
            pass
         
        self.assertEqual(self.__clientRepository.remove(2), self.__client2, "Client 2 was not deleted")
         
        try:
            self.__clientRepository.remove(1)
            self.fail("Repository is empty")
        except RepositoryException:
            pass
         
    def testFindById(self):
        
        self.assertEqual(self.__clientRepository.find_by_id(1), self.__client1, "It does not return client 1")
        self.assertEqual(self.__clientRepository.find_by_id(2), self.__client2, "It does not return client 2")
        self.assertEqual(self.__clientRepository.find_by_id(3), None, "There is no client 3")
        
        
        clients = list(self.__clientRepository.get_all())
        
        self.assertEqual(len(clients), 2, "There must be 2 clients")
        self.assertEqual(clients[0],self.__client1,"This must be client 1")
        self.assertEqual(clients[1],self.__client2,"This must be client 2")
    
    
    def testUpdate(self):
        try:
            self.__clientRepository.update(3, Client(3,"Aurel"))
            self.fail("Client with id 3 does not exist")
        except RepositoryException:
            pass
        
        try:
            self.__clientRepository.update(1,Client(2,"Anakin"))
            self.fail("Id's mismatch. You are not allowed to change the Id.")
        except RepositoryException:
            pass
        
        self.__clientRepository.update(1,Client(1,"Antoniu"))
        self.assertEqual(self.__clientRepository.find_by_id(1).entityName, "Antoniu", "His name must be Antoniu")
        self.__clientRepository.update(1,Client(1,"Aurel"))
        self.assertEqual(self.__clientRepository.find_by_id(1).entityName, "Aurel", "His name must be Aurel")
예제 #7
0
from movie.domain.validators.RentalValidator import RentalValidator
from movie.repo.Repository import Repository, FileRepository
from movie.ui.Console import Console
from movie.ctrl.MovieControllerUndo import MovieControllerUndo
from util.Utils import PropertiesHandler
from movie.repo.Repository import BinaryRepository

if __name__ == '__main__':

    fileName = "settings.properties"
    propertiesHandler = PropertiesHandler(fileName)

    repositoryChose = propertiesHandler.getRepository()

    if repositoryChose == PropertiesHandler.MEMORYREPOSITORY:
        clientRepository = Repository(ClientValidator)
        movieRepository = Repository(MovieValidator)
        rentalRepository = Repository(RentalValidator)
    else:
        clientsFile = propertiesHandler.getClientFile()
        moviesFile = propertiesHandler.getMovieFile()
        rentalsFile = propertiesHandler.getRentalsFile()

        if repositoryChose == PropertiesHandler.FILEREPO:
            clientRepository = FileRepository(ClientValidator, clientsFile)
            movieRepository = FileRepository(MovieValidator, moviesFile)
            rentalRepository = FileRepository(RentalValidator, rentalsFile)

        if repositoryChose == PropertiesHandler.BINARYREPOSITORY:
            clientRepository = BinaryRepository(ClientValidator, clientsFile)
            movieRepository = BinaryRepository(MovieValidator, moviesFile)
예제 #8
0
class StatisticsControllerTest(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.__rentalRepository = Repository(RentalValidator)
        self.__movieRepository = Repository(MovieValidator)
        self.__clientRepository = Repository(ClientValidator)

        self.__movieRepository.save(Movie(1, "Ana", "Bun", "Comedie"))
        self.__clientRepository.save(Client(1, "Aurica"))
        self.__rentalRepository.save(
            Rental(1, 1, 1, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), None))

        self.__movieRepository.save(Movie(2, "Dana Film", "Nebun", "Drama"))
        self.__clientRepository.save(Client(2, "Daniel"))
        self.__rentalRepository.save(
            Rental(2, 2, 2, datetime.date(2016, 12, 15),
                   datetime.date(2017, 1, 5), None))

        self.__movieRepository.save(Movie(3, "Bolt", "D-amar", "Actiune"))
        self.__clientRepository.save(Client(3, "Liviu"))
        self.__rentalRepository.save(
            Rental(3, 3, 3, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), datetime.date(1997, 11, 13)))

        self.__movieRepository.save(Movie(4, "Flash", "Great", "Actiune"))
        self.__clientRepository.save(Client(4, "Radu"))
        self.__rentalRepository.save(
            Rental(4, 4, 4, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), datetime.date(1997, 11, 5)))

        self.__rentalRepository.save(
            Rental(5, 4, 4, datetime.date(1997, 10, 20),
                   datetime.date(1997, 11, 10), datetime.date(1997, 11, 5)))

        self.__statisticsController = StatisticsControler(
            self.__rentalRepository, self.__movieRepository,
            self.__clientRepository)

    def tearDown(self):
        TestCase.tearDown(self)
        Rental.rentalCounter -= 5

    def testAllRentedMovies(self):
        rentedMovies = self.__statisticsController.allRentedMovies()

        self.assertEqual(len(rentedMovies), 2,
                         "There are no other rented movies")
        self.assertEqual(rentedMovies[0].clientId, 1,
                         "It is rented by client 1")
        self.assertEqual(rentedMovies[0].movieId, 1, "Movie Id is 1")

    def testLateRentedMovies(self):
        lateRented = self.__statisticsController.lateRentedMovies()

        #Take care. After 5.01.2017, the len will be 2
        #         self.assertEqual(len(lateRented), 2)

        self.assertEqual(len(lateRented), 1)
        self.assertEqual(lateRented[0].clientId, 1)

        #After 5.01.2017 also


#         self.assertEqual(lateRented[1].movieId, 2)
#         self.assertGreaterEqual(lateRented[0].numberOfDaysDelayed, lateRented[1].numberOfDaysDelayed)

    def testMostActiveClients(self):
        mostActive = self.__statisticsController.mostActiveClients()

        self.assertEqual(len(mostActive), 4, "There should be 4 clients")

        self.assertEqual(mostActive[0].clientId, 1)
        self.assertEqual(mostActive[1].clientId, 4)
        self.assertEqual(mostActive[2].clientId, 3)
        self.assertEqual(mostActive[3].clientId, 2)

        self.assertEqual(mostActive[0].rentalDays,
                         (datetime.date.today() -
                          datetime.date(1997, 10, 20)).days)

    def testMostRentedMovies(self):
        mostRented = self.__statisticsController.mostRentedMovies()

        self.assertEqual(len(mostRented), 4)

        self.assertEqual(mostRented[0].movieId, 4)

    def testSearchClient(self):
        string = "l"
        clientMatches = self.__statisticsController.searchClient(string)

        self.assertEqual(len(clientMatches), 2)

        for match in clientMatches:
            if not string in match.entityName.lower():
                self.fail("Not good matching")

    def testSearchMovies(self):
        string = "ana"
        movieMatches = self.__statisticsController.searchMovies(string)

        self.assertEqual(len(movieMatches), 2)

        for match in movieMatches:
            if not ((string in match.entityName.lower()) or (string in match.entityDescription.lower()) or \
                (string in match.entityGenre.lower())):
                self.fail("Not good matching")