예제 #1
0
    def test_post_2(self):
        """ create a movie with actors"""
        payload = {
            'title': 'pirates of the caribbean',
            'genre': 'action',
            'actors': ['Johnny Depp', 'Orlando Bloom']
        }
        res = self.post_json('http://localhost:5555/movie/', payload)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.json.get('genre'), 'action')
        self.assertEqual(res.json.get('title'), 'pirates of the caribbean')
        movie_uuid = res.json.get('uuid')

        # fetch from db:
        m = Movie.get(Movie.uuid == movie_uuid)
        self.assertEqual(m.title, 'pirates of the caribbean')
        self.assertEqual(m.genre, 'action')

        # implicitly the actors should be created:
        actors = Actor.select()
        self.assertEqual(len(actors), 2)

        johnny = Actor.get(name='Johnny Depp')
        orlando = Actor.get(name='Orlando Bloom')

        # there should also be two records for MovieActor:

        all_movie_actors = MovieActor.select()
        self.assertEqual(len(all_movie_actors), 2)

        MovieActor.get((MovieActor.movie == m) & (MovieActor.actor == johnny))
        MovieActor.get((MovieActor.movie == m) & (MovieActor.actor == orlando))
예제 #2
0
    def test_post_1(self):
        """ create a movie with no actors"""
        payload = {'title': 'test_title', 'genre': 'test_genre'}
        res = self.post_json('http://localhost:5555/movie/', payload)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.json.get('genre'), 'test_genre')
        self.assertEqual(res.json.get('title'), 'test_title')
        movie_uuid = res.json.get('uuid')

        # fetch from db:
        m = Movie.get(Movie.uuid == movie_uuid)
        self.assertEqual(m.title, 'test_title')
        self.assertEqual(m.genre, 'test_genre')