def test_get_success(self, simple_film):
        # arrange
        expected_film = FilmDBRepo.decode_orm_film(simple_film)
        test_id = simple_film.id

        # act
        result_film = FilmDBRepo.get(film_id=test_id)

        # assert
        assert result_film.title == expected_film.title
    def test_get_all_success(self, films_20):
        # arrange
        test_params = {}
        expected_films = []
        for g in films_20:
            expected_films.append(FilmDBRepo.decode_orm_film(g))
        expected_len = 10

        # act
        result_films = FilmDBRepo.get_all(test_params)

        # assert
        for i in range(expected_len):
            assert result_films[i].title == expected_films[i].title
Exemple #3
0
    def test_all(self, x, films_3, simple_profile, client):
        # arrange
        test_films = [
            FilmDBRepo.decode_orm_film(films_3[i]) for i in range(len(films_3))
        ]
        test_films_genre_1 = test_films[0].genres[0]
        test_film_with_genre = test_films[0]

        test_profile = UserDBRepo.decode_orm_user_profile(simple_profile)
        test_user = userToDict(test_profile)

        comment_builder = CommentMother.one()
        test_comment = comment_builder.build()
        like_builder = LikeMother.one()
        test_like = like_builder.build()

        # act
        resp = client.post("/api/v1/sessions/", test_user)
        # print(resp.json())

        # assert
        assert resp.json()['username'] == test_user['username']

        session = resp.json()['token']

        # act
        resp = client.get("/api/v1/films/",
                          HTTP_AUTHORIZATION='Bearer ' + session)
        # print(resp.json())
        resp = resp.json()

        # assert
        for i in range(len(test_films)):
            assert test_films[i].id in [
                resp[i]['id'] for i in range(len(resp))
            ]

        # act
        resp = client.get("/api/v1/films/?genre=" + str(test_films_genre_1.id))
        print(resp.json())
        result_films = resp.json()

        # assert

        for i in range(len(result_films)):
            film_genres_ids = [
                result_films[i]['genres'][j]['id']
                for j in range(len(result_films[i]['genres']))
            ]
            assert test_films_genre_1.id in film_genres_ids

        # act
        resp = client.get("/api/v1/films/" + str(result_films[0]['id']) + '/')

        # assert
        assert test_film_with_genre.id == resp.json()['id']

        # act
        resp = client.get("/api/v1/films/" + str(result_films[0]['id']) +
                          '/comments/')

        # assert
        assert [] == resp.json()

        # act
        resp = client.post("/api/v1/films/" + str(result_films[0]['id']) +
                           '/comments/',
                           commentToDict(test_comment),
                           HTTP_AUTHORIZATION='Bearer ' + session)

        # assert
        assert resp.json()['text'] == test_comment.text

        # act

        resp = client.post("/api/v1/films/" + str(result_films[0]['id']) +
                           '/likes/',
                           likeToDict(test_like),
                           HTTP_AUTHORIZATION='Bearer ' + session)

        # assert
        assert resp.json()['value'] == test_like.value
Exemple #4
0
def films(films_3):
    test_films = [FilmDBRepo.decode_orm_film(films_3[i]) for i in range(len(films_3))]
    return test_films