當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。