本文整理汇总了Python中api_test.Helpers.getComposition方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.getComposition方法的具体用法?Python Helpers.getComposition怎么用?Python Helpers.getComposition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_test.Helpers
的用法示例。
在下文中一共展示了Helpers.getComposition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_returns_forbidden_for_not_authorized_user
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [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."})
示例2: test_delete_return_forbidden_for_non_authenticated_user
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [as 别名]
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)
示例3: test_delete_returns_forbidden_for_user_not_interpretationer
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [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)
示例4: test_post_for_authenticated_user_empty_interpretation
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [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."]})
示例5: test_delete_for_autheticated_valid_interpretationer
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [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)
示例6: test_post_authenticated_user_valid_post_data
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [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)
示例7: test_update_for_autheticated_valid_interpretationer
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [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"])
示例8: test_get_returns_all_interpretations_for_composition
# 需要导入模块: from api_test import Helpers [as 别名]
# 或者: from api_test.Helpers import getComposition [as 别名]
def test_get_returns_all_interpretations_for_composition(self):
user1 = Helpers.getUser(user_data=Helpers.USER1)
user2 = Helpers.getUser(user_data=Helpers.USER2)
composition = Helpers.getComposition(artist=user1)
interpretation1 = Interpretation.objects.create(
user=user1, composition=composition, interpretation='interpretation1')
interpretation2 = Interpretation.objects.create(
user=user1, composition=composition, interpretation='interpretation2')
interpretation3 = Interpretation.objects.create(
user=user2, composition=composition, interpretation='interpretation3')
url = '/compositions/{0}/interpretations'.format(composition.id)
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
expected_response = [
self.createResponse(1, 'interpretation1', user1.id, composition.id, interpretation1.created)]
expected_response.append(
self.createResponse(2, 'interpretation2', user1.id, composition.id, interpretation2.created))
expected_response.append(
self.createResponse(3, 'interpretation3', user2.id, composition.id, interpretation3.created))
self.assertEqual(response.data, expected_response)