test_create_movie.py 1.47 KB
Newer Older
Brady James Garvin's avatar
Brady James Garvin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from unittest import TestCase

from movies import MovieDatabase, Movie
from main import MoviesApp


class TestCreateMovie(TestCase):
    def test_create_movie_inserts_movies(self):
        url = MovieDatabase.construct_in_memory_url()
        movie_database = MovieDatabase(url)
        movie_database.ensure_tables_exist()
        session = movie_database.create_session()
        MoviesApp._create_movie(session, 'Example', 4000000, 290000000)
        actual = session.query(Movie).filter(Movie.title == 'Example').first()
        self.assertIsNotNone(actual)

    def test_create_movie_inserts_one_movie(self):
        url = MovieDatabase.construct_in_memory_url()
        movie_database = MovieDatabase(url)
        movie_database.ensure_tables_exist()
        session = movie_database.create_session()
        MoviesApp._create_movie(session, 'Example', 4000000, 290000000)
        actual = session.query(Movie).filter(Movie.title == 'Example').count()
        self.assertEqual(actual, 1)

    def test_create_movie_inserts_correct_dollar_figures(self):
        url = MovieDatabase.construct_in_memory_url()
        movie_database = MovieDatabase(url)
        movie_database.ensure_tables_exist()
        session = movie_database.create_session()
        MoviesApp._create_movie(session, 'Example', 4000000, 290000000)
        actual = session.query(Movie).filter(Movie.title == 'Example').first()
        self.assertEqual(actual.budget, 4000000)
        self.assertEqual(actual.gross_revenue, 290000000)