本文整理汇总了Python中api_test.Helpers.getUser方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.getUser方法的具体用法?Python Helpers.getUser怎么用?Python Helpers.getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_test.Helpers
的用法示例。
在下文中一共展示了Helpers.getUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_works_for_multiple_authenticated_user_that_has_not_already_voted
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
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)
示例2: test_post_throws_forbidden_for_authenticated_user_not_himself
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_post_throws_forbidden_for_authenticated_user_not_himself(self):
user = Helpers.getUser(Helpers.USER1)
other_user = Helpers.getUser(Helpers.USER2)
composition = Helpers.createComposition(user)
bookmark_data = {'bookmarks': [composition.id]}
url = self.url.format(user.id)
self.client.login(
username=other_user.email, password=Helpers.USER2["password"])
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)
示例3: test_get_throws_forbidden_when_user_not_himself
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
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)
示例4: test_delete_returns_forbidden_for_user_not_interpretationer
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_delete_returns_forbidden_for_user_not_interpretationer(self):
user1 = Helpers.getUser(user_data=Helpers.USER1)
Helpers.getUser(user_data=Helpers.USER2)
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)
self.client.login(username="[email protected]", password="user2")
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
示例5: test_post_for_authenticated_user_empty_comment
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
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)
示例6: test_post_for_authenticated_user_empty_interpretation
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
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."]})
示例7: test_post_throws_forbidden_for_non_authenticated_user
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_post_throws_forbidden_for_non_authenticated_user(self):
Helpers.getUser(Helpers.USER1)
vote = self.createVote()
vote_data = {"id": vote.id, "vote": True}
url = self.url.format(vote.interpretation.composition.id, vote.interpretation.id)
response = self.client.post(url, vote_data)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
vote = self.refreshFromDB(vote)
self.assertEqual(vote.positive, 0)
self.assertEqual(vote.negative, 0)
self.assertEqual(vote.voters.all().count(), 0)
示例8: test_delete_for_autheticated_valid_interpretationer
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_delete_for_autheticated_valid_interpretationer(self):
user1 = Helpers.getUser(user_data=Helpers.USER1)
Helpers.getUser(user_data=Helpers.USER2)
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)
self.client.login(username="[email protected]", password="user1")
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(Interpretation.objects.all().count(), 0)
示例9: test_post_authenticated_user_valid_post_data
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_post_authenticated_user_valid_post_data(self):
user1 = Helpers.getUser(user_data=Helpers.USER1)
user2 = Helpers.getUser(user_data=Helpers.USER2)
composition = Helpers.getComposition(artist=user1)
interpretation_data = {'interpretation': 'interpretation1'}
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_201_CREATED)
self.assertEqual(response.data, self.createResponse(
1, 'interpretation1', user2.id, composition.id, datetime.now()))
self.assertEqual(Interpretation.objects.get(pk=1).interpretation, interpretation_data["interpretation"])
self.assertEqual(Interpretation.objects.all().count(), 1)
示例10: test_delete_returns_forbidden_for_user_not_commenter
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_delete_returns_forbidden_for_user_not_commenter(self):
user1 = Helpers.getUser(Helpers.USER1)
Helpers.getUser(Helpers.USER2)
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)
self.client.login(username='[email protected]', password='user2')
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
示例11: test_unread_returns_unread_notifications
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_unread_returns_unread_notifications(self):
notification1_data = self.createNotification("Action1")
self.createNotification("Action2")
notification3_data = self.createNotification("Action3")
notification = Notification.objects.get(pk=2)
notification.unread = False
notification.save()
user = Helpers.getUser(Helpers.USER2)
url = self.url + "/unread"
self.client.login(
username=user.email, password=Helpers.USER2["password"])
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
expected_response = [self.createResponse(3,
user.id,
notification3_data["verb"],
datetime.now(),
notification3_data["actor"],
notification3_data[
"action_object"],
notification3_data["target"])]
expected_response += [self.createResponse(1,
user.id,
notification1_data["verb"],
datetime.now(),
notification1_data["actor"],
notification1_data[
"action_object"],
notification1_data["target"])]
self.assertEqual(response.data, expected_response)
示例12: test_all_returns_all_notifications
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_all_returns_all_notifications(self):
notification1_data = self.createNotification()
notification2_data = self.createNotification()
user = Helpers.getUser(Helpers.USER2)
self.client.login(
username=user.email, password=Helpers.USER2["password"])
response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
expected_response = [self.createResponse(2,
user.id,
notification2_data["verb"],
datetime.now(),
notification2_data["actor"],
notification2_data[
"action_object"],
notification2_data["target"])]
expected_response += [self.createResponse(1,
user.id,
notification1_data["verb"],
datetime.now(),
notification1_data["actor"],
notification1_data[
"action_object"],
notification1_data["target"])]
self.assertEqual(response.data, expected_response)
示例13: test_get_throws_forbidden_when_user_not_authenticated
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
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)
示例14: test_update_for_autheticated_valid_interpretationer
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
def test_update_for_autheticated_valid_interpretationer(self):
user1 = Helpers.getUser(user_data=Helpers.USER1)
Helpers.getUser(user_data=Helpers.USER2)
composition = Helpers.getComposition(artist=user1)
interpretation = Interpretation.objects.create(
user=user1, composition=composition, interpretation="interpretation1"
)
interpretation_data = {"interpretation": "interpretation2"}
url = "/compositions/{0}/interpretations/{1}".format(composition.id, interpretation.id)
self.client.login(username="[email protected]", password="user1")
response = self.client.put(url, data=interpretation_data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.data, self.createResponse(1, "interpretation2", user1.id, composition.id, interpretation.created)
)
self.assertEqual(Interpretation.objects.all().count(), 1)
self.assertEqual(Interpretation.objects.get(pk=1).interpretation, interpretation_data["interpretation"])
示例15: test_post_returns_forbidden_for_not_authorized_user
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getUser [as 别名]
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."})