Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    def test_get_fail_not_found(self):
        # arrange
        test_id = 1

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

        # assert
        assert result_film is None
Beispiel #4
0
    def test_get_fail_not_normal(self):
        # arrange
        test_id = -100

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

        # assert
        assert result_film is None
Beispiel #5
0
    def test_get_all_no_results(self):
        # arrange
        test_params = {}
        expected_films = []

        # act
        result_films = FilmDBRepo.get_all(test_params)

        # assert
        assert result_films == expected_films
    def test_get_one_success(self, simple_like):
        # arrange
        usecase = LikeUsecases(LikeDBRepo(), FilmDBRepo())
        test_id = simple_like.id
        expected_like = simple_like

        # act
        result_likes = usecase.get_like(test_id)

        # assert
        assert result_likes.value == expected_like.value
Beispiel #7
0
    def test_get_success(self, simple_film):
        # arrange
        usecase = FilmUsecases(FilmDBRepo())
        test_id = simple_film.id
        expected_film = simple_film

        # act
        result_films = usecase.get_film(test_id)

        # assert
        assert result_films.title == expected_film.title
Beispiel #8
0
    def test_get_all_sort(self, films_3, films_3_core):
        # arrange
        test_params = {'sort': 'title'}
        expected_films = films_3_core
        expected_len = 3

        # act
        result_films = FilmDBRepo.get_all(test_params)

        # assert
        for i in range(expected_len):
            assert result_films[i].title == expected_films[i].title
Beispiel #9
0
    def test_get_one_success_london(self, mocker):
        # arrange
        usecase = LikeUsecases(LikeDBRepo(), FilmDBRepo())
        test_id = 1
        expected_like = LikeMother.one().build()
        mocker.patch('modules.DBRepo.LikeDBRepo.LikeDBRepo.get',
                     return_value=expected_like)

        # act
        result_likes = usecase.get_like(test_id)

        # assert
        assert result_likes.value == expected_like.value
Beispiel #10
0
    def test_get_success_london(self, mocker):
        # arrange
        test_id = 1
        expected_film = FilmMother.one().build()
        mocker.patch('modules.DBRepo.FilmDBRepo.FilmDBRepo.get',
                     return_value=expected_film)
        usecase = FilmUsecases(FilmDBRepo())

        # act
        result_films = usecase.get_film(test_id)

        # assert
        assert result_films.title == expected_film.title
Beispiel #11
0
    def test_get_all_success(self, mocker):
        # arrange
        expected_films = [FilmMother.one().build(), FilmMother.two().build()]
        mocker.patch('modules.DBRepo.FilmDBRepo.FilmDBRepo.get_all',
                     return_value=expected_films)
        usecase = FilmUsecases(FilmDBRepo())
        test_params = {}

        # act
        result_genres = usecase.get_all_films(test_params)

        # assert
        for i in range(len(expected_films)):
            assert result_genres[i].title == expected_films[i].title
Beispiel #12
0
    def test_get_all_genres_sort(self, films_3):
        # arrange
        expected_genre = films_3[0].genres.all()[0].id
        test_params = {'genre': [expected_genre]}
        expected_len = 3

        # act
        result_films = FilmDBRepo.get_all(test_params)

        # assert
        for i in range(len(result_films)):
            assert expected_genre in [
                result_films[i].genres[j].id
                for j in range(len(result_films[i].genres))
            ]
Beispiel #13
0
    def test_create_like_mock(self, mocker):
        # arrange
        expected_like = LikeMother.one().build()
        user_id = expected_like.author
        film_id = expected_like.film
        value = expected_like.value
        usecase = LikeUsecases(LikeDBRepo(), FilmDBRepo())
        mocker.patch('modules.DBRepo.LikeDBRepo.LikeDBRepo.create',
                     return_value=(expected_like, None))
        mocker.patch('modules.DBRepo.FilmDBRepo.FilmDBRepo.count_rating',
                     return_value=None)

        # act
        (like, error) = usecase.create_like(user_id=user_id,
                                            film_id=film_id,
                                            value=value)

        # assert
        assert like.value == expected_like.value
    def test_get_one_no_result(self):
        usecase = LikeUsecases(LikeDBRepo(), FilmDBRepo())

        result_likes = usecase.get_like(1)
        assert result_likes is None
Beispiel #15
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
Beispiel #16
0
 def get_film_usecase() -> FilmUsecases:
     return FilmUsecases(FilmDBRepo())
Beispiel #17
0
 def get_like_usecase() -> LikeUsecases:
     return LikeUsecases(LikeDBRepo(), FilmDBRepo())
Beispiel #18
0
    def test_get_one_no_result(self):
        usecase = FilmUsecases(FilmDBRepo())

        result_films = usecase.get_film(1)
        assert result_films is None
Beispiel #19
0
    def test_get_one_wrong_params(self):
        usecase = FilmUsecases(FilmDBRepo())

        result_films = usecase.get_film(-100)
        assert result_films is None
    def test_get_one_wrong_params(self):
        usecase = LikeUsecases(LikeDBRepo(), FilmDBRepo())

        result_likes = usecase.get_like(-100)
        assert result_likes is None
Beispiel #21
0
def films(films_3):
    test_films = [FilmDBRepo.decode_orm_film(films_3[i]) for i in range(len(films_3))]
    return test_films