Skip to content

Commit 30a387c

Browse files
committed
Added create_one_resource_with_invalid_media_type test case.
1 parent ddf3bec commit 30a387c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

project/resources/tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import skip
2+
from pytest import raises
23
from random import randint
34
from rest_framework import status
45
from rest_framework.test import APITestCase
@@ -186,3 +187,22 @@ def test_create_one_resource_without_media_type(self):
186187
self.assertEqual(response.data['title'], "The Best Medium-Hard Data Analyst SQL Interview Questions")
187188
self.assertEqual(response.data['other_referring_source'], "twitter.com/lpnotes")
188189
self.assertEqual(response.data['media_type'], '')
190+
191+
def test_create_one_resource_with_invalid_media_type(self):
192+
with raises(KeyError, match=r"The media type should be one of the following:"):
193+
url = '/api/v1/resources/'
194+
data = {"title": "The Best Medium-Hard Data Analyst SQL Interview Questions",
195+
"author": "Zachary Thomas",
196+
"description": "The first 70% of SQL is pretty straightforward but the remaining 30% can be pretty tricky. These are good practice problems for that tricky 30% part.",
197+
"url": "https://quip.com/2gwZArKuWk7W",
198+
"referring_url": "https://quip.com",
199+
"other_referring_source": "twitter.com/lpnotes",
200+
"date_published": "2020-04-19T03:27:06Z",
201+
"created": "2020-05-02T03:27:06.485Z",
202+
"modified": "2020-05-02T03:27:06.485Z",
203+
"media_type": "DOP",
204+
"tags": ["SQLt", "BackEnd", "Databases"]
205+
}
206+
207+
response = self.client.post(url, data, format='json')
208+

0 commit comments

Comments
 (0)