当前位置: 首页>>代码示例>>Python>>正文


Python api_test.Helpers类代码示例

本文整理汇总了Python中api_test.Helpers的典型用法代码示例。如果您正苦于以下问题:Python Helpers类的具体用法?Python Helpers怎么用?Python Helpers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Helpers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_post_works_for_multiple_authenticated_user_that_has_not_already_voted

    def test_post_works_for_multiple_authenticated_user_that_has_not_already_voted(self):
        user1 = Helpers.getUser(Helpers.USER1)
        user2 = Helpers.getUser(Helpers.USER2)
        user3 = Helpers.getUser(Helpers.USER3)
        vote = self.createVote()
        vote_data1 = {"id": vote.id, "vote": True}
        vote_data2 = {"id": vote.id, "vote": False}
        vote_data3 = {"id": vote.id, "vote": True}
        url = self.url.format(vote.composition.id)

        self.client.login(
            username=user1.email, password=Helpers.USER1["password"])
        response = self.client.post(url, vote_data1)
        self.client.logout()

        self.client.login(
            username=user2.email, password=Helpers.USER2["password"])
        response = self.client.post(url, vote_data2)
        self.client.logout()

        self.client.login(
            username=user3.email, password=Helpers.USER3["password"])
        response = self.client.post(url, vote_data3)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, self.createResponse(vote.composition.id, 2, 1))
        vote = self.refreshFromDB(vote)
        self.assertEqual(vote.positive, 2)
        self.assertEqual(vote.negative, 1)
        self.assertEqual(vote.voters.all().count(), 3)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:31,代码来源:testVotes.py

示例2: test_get_for_non_existing_interpretation

    def test_get_for_non_existing_interpretation(self):
        Helpers.createComposition()
        url = '/compositions/1/interpretations/1/comments'

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, [])
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:8,代码来源:testListComments.py

示例3: test_post_returns_forbidden_for_not_authorized_user

    def test_post_returns_forbidden_for_not_authorized_user(self):
        user1 = Helpers.getUser(user_data=Helpers.USER1)
        composition = Helpers.getComposition(artist=user1)
        url = '/compositions/{0}/interpretations'.format(composition.id)

        response = self.client.post(url, data={})

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(
            response.data, {"detail": "Authentication credentials were not provided."})
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:10,代码来源:testListInterpretations.py

示例4: test_get_throws_forbidden_when_user_not_authenticated

    def test_get_throws_forbidden_when_user_not_authenticated(self):
        user = Helpers.getUser(Helpers.USER1)
        composition1 = Helpers.createComposition(user)
        composition2 = Helpers.createComposition(user)
        user.bookmarks.add(composition1, composition2)
        url = self.url.format(user.id)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:10,代码来源:testBookmarks.py

示例5: test_post_throws_forbidden_for_not_authenticated_user

    def test_post_throws_forbidden_for_not_authenticated_user(self):
        user = Helpers.getUser(Helpers.USER1)
        composition = Helpers.createComposition(user)
        bookmark_data = {'bookmarks': [composition.id]}
        url = self.url.format(user.id)

        response = self.client.post(url, bookmark_data, format="json")

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(user.bookmarks.all().count(), 0)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:10,代码来源:testBookmarks.py

示例6: test_delete_return_forbidden_for_non_authenticated_user

    def test_delete_return_forbidden_for_non_authenticated_user(self):
        user1 = Helpers.getUser(user_data=Helpers.USER1)
        composition = Helpers.getComposition(artist=user1)
        interpretation = Interpretation.objects.create(
            user=user1, composition=composition, interpretation="interpretation1"
        )
        url = "/compositions/{0}/interpretations/{1}".format(composition.id, interpretation.id)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:11,代码来源:testSingleInterpretation.py

示例7: test_post_adds_bookmark_for_valid_authenticated_user

    def test_post_adds_bookmark_for_valid_authenticated_user(self):
        user = Helpers.getUser(Helpers.USER1)
        composition = Helpers.createComposition(user)
        bookmark_data = {'bookmarks': [composition.id]}
        url = self.url.format(user.id)

        self.client.login(
            username=user.email, password=Helpers.USER1["password"])
        response = self.client.post(url, bookmark_data, format="json")

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(user.bookmarks.all().count(), 1)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:12,代码来源:testBookmarks.py

示例8: test_post_throws_400_for_invalid_post_data

    def test_post_throws_400_for_invalid_post_data(self):
        user = Helpers.getUser(Helpers.USER1)
        composition = Helpers.createComposition(user)
        url = self.url.format(user.id)

        self.client.login(
            username=user.email, password=Helpers.USER1["password"])
        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data, {"bookmarks": "This field is required"})
        self.assertEqual(user.bookmarks.all().count(), 0)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testBookmarks.py

示例9: test_post_authenticated_user_valid_post_data

    def test_post_authenticated_user_valid_post_data(self):
        user2 = Helpers.getUser(Helpers.USER2)
        interpretation = Helpers.createInterpretation()
        comment_data = {'comment': 'comment1'}
        url = '/compositions/{0}/interpretations/{1}/comments'.format(interpretation.composition.id, interpretation.id)

        self.client.login(username='[email protected]', password='user2')
        response = self.client.post(url, data=comment_data)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data, self.createResponse(
            1, 'comment1', user2.id, interpretation.id, datetime.now()))
        self.assertEqual(Comment.objects.all().count(), 1)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testListComments.py

示例10: test_delete_return_forbidden_for_non_authenticated_user

    def test_delete_return_forbidden_for_non_authenticated_user(self):
        user1 = Helpers.getUser(Helpers.USER1)
        interpretation = Helpers.createInterpretation()
        comment = Comment.objects.create(
            commenter=user1, interpretation=interpretation, comment='comment1')
        url = '/compositions/{0}/interpretations/{1}/comments/{2}'.format(
            interpretation.composition.id,
            interpretation.id,
            comment.id)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testSingleComment.py

示例11: test_get_throws_forbidden_when_user_not_himself

    def test_get_throws_forbidden_when_user_not_himself(self):
        user = Helpers.getUser(Helpers.USER1)
        other_user = Helpers.getUser(Helpers.USER2)
        composition1 = Helpers.createComposition(user)
        composition2 = Helpers.createComposition(user)
        user.bookmarks.add(composition1, composition2)
        url = self.url.format(user.id)

        self.client.login(
            username=other_user.email, password=Helpers.USER2["password"])
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testBookmarks.py

示例12: test_delete_for_non_existing_bookmark_does_not_crash

    def test_delete_for_non_existing_bookmark_does_not_crash(self):
        user = Helpers.getUser(Helpers.USER1)
        composition1 = Helpers.createComposition(user)
        user.bookmarks.add(composition1)
        bookmark_data = {'bookmarks': [56, 89]}
        url = self.url.format(user.id)

        self.client.login(
            username=user.email, password=Helpers.USER1["password"])
        response = self.client.delete(url, data=bookmark_data, format="json")

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(user.bookmarks.all().count(), 1)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testBookmarks.py

示例13: test_post_for_already_added_bookmark_acts_same_as_adding_new

    def test_post_for_already_added_bookmark_acts_same_as_adding_new(self):
        user = Helpers.getUser(Helpers.USER1)
        composition = Helpers.createComposition(user)
        user.bookmarks.add(composition)
        bookmark_data = {'bookmarks': [composition.id]}
        url = self.url.format(user.id)

        self.client.login(
            username=user.email, password=Helpers.USER1["password"])
        response = self.client.post(url, bookmark_data, format="json")

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(user.bookmarks.all().count(), 1)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testBookmarks.py

示例14: test_post_for_authenticated_user_empty_interpretation

    def test_post_for_authenticated_user_empty_interpretation(self):
        user1 = Helpers.getUser(user_data=Helpers.USER1)
        Helpers.getUser(user_data=Helpers.USER2)
        composition = Helpers.getComposition(artist=user1)
        interpretation_data = {'interpretation': ''}
        url = '/compositions/{0}/interpretations'.format(composition.id)

        self.client.login(username='[email protected]', password='user2')
        response = self.client.post(url, data=interpretation_data)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data, {"interpretation": ["This field is required."]})
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testListInterpretations.py

示例15: test_post_for_authenticated_user_empty_comment

    def test_post_for_authenticated_user_empty_comment(self):
        Helpers.getUser(Helpers.USER2)
        interpretation = Helpers.createInterpretation()
        comment_data = {'comment': ''}
        url = '/compositions/{0}/interpretations/{1}/comments'.format(interpretation.composition.id, interpretation.id)

        self.client.login(username='[email protected]', password='user2')
        response = self.client.post(url, data=comment_data)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data, {"comment": ["This field is required."]})
        self.assertEqual(Comment.objects.all().count(), 0)
开发者ID:RohitRepo,项目名称:ShowCase,代码行数:13,代码来源:testListComments.py


注:本文中的api_test.Helpers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。