Ejemplo n.º 1
0
    def test_get_my_mock(self):
        # arrange
        expected_comments = [CommentMother.one().build(), CommentMother.two().build()]
        usecase = CommentUsecases(CommentDBRepoMock())
        film_id = 1

        # act
        result_comments = usecase.get_all_comments(film_id, 0, len(expected_comments))

        # assert
        for i in range(len(expected_comments)):
            assert result_comments[i].text == expected_comments[i].text
Ejemplo n.º 2
0
    def test_get_success(self, mocker):
        # arrange
        expected_comments = [CommentMother.one().build(), CommentMother.two().build()]
        mocker.patch('modules.DBRepo.CommentDBRepo.CommentDBRepo.get_all', return_value=expected_comments)
        usecase = CommentUsecases(CommentDBRepo())
        film_id = 1

        # act
        result_comments = usecase.get_all_comments(film_id, 0, len(expected_comments))

        # assert
        for i in range(len(expected_comments)):
            assert result_comments[i].text == expected_comments[i].text
Ejemplo n.º 3
0
    def test_all_mock(self, client, mocker):
        # arrange
        test_comments = [
            CommentMother.one().build(),
            CommentMother.two().build()
        ]
        mocker.patch('modules.DBRepo.CommentDBRepo.CommentDBRepo.get_all',
                     return_value=test_comments)
        expected_resp = [
            commentToDict(test_comments[i]) for i in range(len(test_comments))
        ]
        view = CommentsListView()

        # act
        resp = view.get(HttpRequest(), test_comments[0].film)

        # assert
        for i in range(len(expected_resp)):
            assert expected_resp[i]['text'] == resp.data[i]['text']
Ejemplo n.º 4
0
    def test_get_one_my_mock(self):
        # arrange
        usecase = CommentUsecases(CommentDBRepoMock())
        test_id = 1
        expected_comment = CommentMother.one().build()

        # act
        result_comments = usecase.get_comment(test_id)

        # assert
        assert result_comments.text == expected_comment.text
Ejemplo n.º 5
0
    def test_get_one_success_london(self, mocker):
        # arrange
        usecase = CommentUsecases(CommentDBRepo())
        test_id = 1
        expected_comment = CommentMother.one().build()
        mocker.patch('modules.DBRepo.CommentDBRepo.CommentDBRepo.get', return_value=expected_comment)

        # act
        result_comments = usecase.get_comment(test_id)

        # assert
        assert result_comments.text == expected_comment.text
Ejemplo n.º 6
0
    def test_get_mock(self, client, mocker):
        # arrange
        test_comment = CommentMother.one().build()
        test_id = 1
        mocker.patch('modules.DBRepo.CommentDBRepo.CommentDBRepo.get',
                     return_value=test_comment)
        view = CommentView()

        # act
        resp = view.get(HttpRequest(), 1, test_id)

        # assert
        assert commentToDict(test_comment)['text'] == resp.data['text']
Ejemplo n.º 7
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
Ejemplo n.º 8
0
 def get(comment_id) -> Comment:
     return CommentMother.one().build()
Ejemplo n.º 9
0
 def get_all(film_id, o, l) -> List[Comment]:
     return [CommentMother.one().build(), CommentMother.two().build()]