def __loadRepo(self):
     self.__loadFileReadMode()
     for line in self.__file:
         splitLine = line.split()
         movieToAdd = MovieDAO(splitLine[1], splitLine[2], splitLine[3])
         movieToAdd.setMovieId(int(splitLine[0]))
         super().addMovieWithId(movieToAdd)
     self.__closeFile()
 def test_updateMovie(self):
     self.movieRepo.addMovie(MovieDAO("dani", "great", "nice"))
     self.movieRepo.addMovie(MovieDAO("titanic", "description", "genre"))
     self.movieRepo.updateMovieWithId(0, MovieDAO("ancu", "nice", "great"))
     testMovie1 = MovieDAO("ancu", "nice", "great")
     testMovie1.setMovieId(0)
     testMovie2 = MovieDAO("titanic", "description", "genre")
     testMovie2.setMovieId(1)
     self.assertEqual(self.movieRepo.getList(), [testMovie1, testMovie2])
Beispiel #3
0
    def test_undoUpdateMovie(self):
        updatedMovie = MovieDAO("a", "a", "a")
        updatedMovie.setMovieId(0)
        self.undoRunner.addCommandToUndo(["update", "0", "a", "a", "a"], self.movieController, self.stack, "movie", self.commandsStack)

        self.movieController.updateMovieWithId(0, updatedMovie)
        self.assertEqual(self.movieController.getMovieWithId(0).getTitle(), "a")
        self.undoRunner.undo(self.clientController, self.movieController, self.rentalController, self.stack)
        self.assertEqual(self.movieController.getMovieWithId(0).getTitle(), "Titanic")
 def test_removeMovie(self):
     self.movieRepo.addMovie(MovieDAO("dani", "great", "nice"))
     self.movieRepo.addMovie(MovieDAO("titanic", "description", "genre"))
     self.movieRepo.removeMovieWithId(1)
     self.assertEqual(len(self.movieRepo.getList()), 1)
     testMovie = MovieDAO("dani", "great", "nice")
     testMovie.setMovieId(0)
     self.assertEqual(self.movieRepo.getList(), [testMovie])
     with self.assertRaises(ObjectNotInCollectionException):
         self.movieRepo.removeMovieWithId(5)
 def test_hasClientWithId(self):
     movie1 = MovieDAO("aaa", "aaa", "aaa")
     movie1.setMovieId(1)
     movie2 = MovieDAO("bb", "bb", "bb")
     movie2.setMovieId(2)
     movie3 = MovieDAO("958", "958", "958")
     movie3.setMovieId(3)
     self.movieFileRepository.addMovieWithId(movie1)
     self.movieFileRepository.addMovieWithId(movie2)
     self.movieFileRepository.addMovieWithId(movie3)
     self.assertEqual(self.movieFileRepository.hasMovieWithId(1), True)
     self.assertEqual(self.movieFileRepository.hasMovieWithId(4), False)
 def test_getList(self):
     movie1 = MovieDAO("aaa", "aaa", "aaa")
     movie1.setMovieId(1)
     movie2 = MovieDAO("bb", "bb", "bb")
     movie2.setMovieId(2)
     movie3 = MovieDAO("958", "958", "958")
     movie3.setMovieId(4)
     self.movieFileRepository.addMovieWithId(movie1)
     self.movieFileRepository.addMovieWithId(movie2)
     self.movieFileRepository.addMovieWithId(movie3)
     self.assertEqual(self.movieFileRepository.getList(),
                      [movie1, movie2, movie3])
class TestMovie(TestCase):

    def setUp(self):
        self.movie = MovieDAO("Titanic", "lovely", "romance")

    def tearDown(self):
        self.movie = None

    def test_init(self):
        with self.assertRaises(ValueError):
            testMovie = MovieDAO(1, "dfa", "fasd")
        with self.assertRaises(ValueError):
            testMovie = MovieDAO("asd", [], "fasd")
        with self.assertRaises(ValueError):
            testMovie = MovieDAO("sdf", "fsda", 6.5)
        with self.assertRaises(ValueError):
            testMovie = MovieDAO(1, "dfa", [])
        with self.assertRaises(ValueError):
            testMovie = MovieDAO(1, [], {"6": 5})
        self.assertEqual(self.movie.getTitle(), "Titanic", 'movie title got wrong')
        self.assertEqual(self.movie.getDescription(), "lovely", 'movie description got wrong')
        self.assertEqual(self.movie.getGenre(), "romance", 'movie genre got wrong')
        self.assertRaises(TypeError, lambda: self.movie.getId(), 'default movie id not None')

    def test_setMovieId(self):
        self.movie.setMovieId(5)
        self.assertEqual(self.movie.getId(), 5, "movie id set wrong")

    def test_setWrongId(self):
        self.assertRaises(ValueError, lambda: self.movie.setMovieId(-3))
        self.assertRaises(ValueError, lambda: self.movie.setMovieId(5.5))
        self.assertRaises(ValueError, lambda: self.movie.setMovieId("dasas"))
        self.assertRaises(ValueError, lambda: self.movie.setMovieId([]))
        self.assertRaises(ValueError, lambda: self.movie.setMovieId({}))
        self.assertRaises(ValueError, lambda: self.movie.setMovieId((5, 3)))

    def test_setMovieIdSecondTime(self):
        self.movie.setMovieId(5)
        with self.assertRaises(AlreadySetException):
            self.movie.setMovieId(9)
Beispiel #8
0
 def updateMovie(self, command, movieController):
     # return "movie" "update" "movie id" "old title" "old description" "old genre"
     updatedMovie = MovieDAO(command[3], command[4], command[5])
     updatedMovie.setMovieId(int(command[2]))
     movieController.updateMovieWithId(int(command[2]), updatedMovie)
Beispiel #9
0
 def addMovie(self, command, movieController):
     # return "movie" "add" "movie id" "title" "description" "genre"
     movie = MovieDAO(command[3], command[4], command[5])
     movie.setMovieId(int(command[2]))
     movieController.addMovieWithId(movie)