示例#1
0
    def test_expired_movies(self):
        today = date.today()
        db.session.add(dummy_movie(title="A"))
        db.session.add(
            dummy_movie(title="B", expiry_date=today - timedelta(days=2)))
        start, end = today - timedelta(days=1), today + timedelta(days=1)

        result = self.get_expired_movies(start, end)
        self.assert200(result)
        expiredMovies = byte_to_json(result.data)['movies']
        allMovies = byte_to_json(self.get_all_movies().data)['movies']
        self.assertNotEqual(len(expiredMovies), len(allMovies))
示例#2
0
    def test_insert_multiple(self):
        movies = [dummy_movie(), dummy_movie(title="test2")]
        for movie in movies:
            result = self.insert_movie(movie)
            self.assert200(result)

        movies_found = byte_to_json(self.get_all_movies().data)['movies']
        for i, movie in enumerate(movies):
            self.assertEquals(json.dumps(movies_found[i], sort_keys=True), json.dumps(MovieSchema().dump(movie), sort_keys=True))
示例#3
0
 def test_get_all_movies_multiple_entry(self):
     movieA = dummy_movie()
     movieB = dummy_movie(title="test2")
     db.session.add(movieA)
     db.session.add(movieB)
     db.session.commit()
     movies = byte_to_json(self.get_all_movies().data)['movies']
     self.assertEqual(movies[0], MovieSchema().dump(movieA))
     self.assertEqual(movies[1], MovieSchema().dump(movieB))
示例#4
0
    def test_delete_movie(self):
        targetTitle = 'deletethismovie'
        movieEntries = 5
        moviesToNotDelete = [ dummy_movie("title{}".format(i)) for i in range(5) ]
        
        for movie in moviesToNotDelete + [dummy_movie(targetTitle)]:
            db.session.add(movie)
        db.session.commit()

        allMovies = byte_to_json(self.get_all_movies().data)['movies']
        assert(len(allMovies) == movieEntries + 1)

        result = self.delete_movie(targetTitle)
        allMovies = byte_to_json(self.get_all_movies().data)['movies']
        self.assert200(result)
        
        assert(len(allMovies) == movieEntries)
        for movie in allMovies:
            self.assertNotEqual(movie['title'], targetTitle)
示例#5
0
 def test_insert_bad_movie(self):
     movie ={"blahblahblah":"bleh"}
     jwt = byte_to_json(self.get_auth_point())['access_token']
     result = self.client.post("/api/", 
         headers={   "Content-Type": "application/json", 
                     "Authorization": "Bearer {}".format(jwt)
         },
         data=json.dumps(movie)
     )
     self.assert400(result)
示例#6
0
    def test_search_title(self):
        movie = dummy_movie()
        movie_to_not_find = dummy_movie(title="somethingElse")
        db.session.add(movie)
        db.session.add(movie_to_not_find)
        db.session.commit()
        
        result = self.search_movie({'title': movie.title})
        self.assert200(result)

        movies = byte_to_json(result.data)['movies']
        
        self.assertEquals(json.dumps(movies[0], sort_keys=True), json.dumps(MovieSchema().dump(movie), sort_keys=True))
示例#7
0
 def test_search_multi_fields(self):
     title_to_search = "find me"
     genre_to_search = "find me too"
     movie_to_search = dummy_movie(title=title_to_search, genre=genre_to_search)
     movie_to_not_find = dummy_movie(title="somethingElse")
     db.session.add(movie_to_search)
     db.session.add(movie_to_not_find)
     db.session.commit()
     
     result = self.search_movie({'title': title_to_search, 'genre': genre_to_search})
     self.assert200(result)
     
     movies = byte_to_json(result.data)['movies']
     self.assertEquals(json.dumps(movies[0], sort_keys=True), json.dumps(MovieSchema().dump(movie_to_search), sort_keys=True))
示例#8
0
    def test_search_datetime(self):
        today = date.today()
        not_today = date.today() - timedelta(days=3)
        today_movie = dummy_movie(expiry_date=today)
        today_movie2 = dummy_movie(title="today2", expiry_date=today)
        not_today_movie = dummy_movie(title="not today", expiry_date=not_today)
        db.session.add(today_movie)
        db.session.add(today_movie2)
        db.session.add(not_today_movie)
        db.session.commit()
        
        result = self.search_movie({'expiry_date': today.isoformat()})
        self.assert200(result)

        movies = byte_to_json(result.data)['movies']
        self.assertEquals(len(movies), 2)
示例#9
0
 def test_get_all_movies(self):
     jwt = byte_to_json(self.get_auth_point())['access_token']
     result = self.get_all_movies()
     self.assert200(result)
示例#10
0
 def test_get_all_movies_with_entry(self):
     movie = dummy_movie()
     db.session.add(movie)
     db.session.commit()
     movies = byte_to_json(self.get_all_movies().data)['movies']
     self.assertEquals(movies[0], MovieSchema().dump(movie))