|
1 | 1 | from unittest import skip
|
| 2 | +from pytest import raises |
2 | 3 | from random import randint
|
3 | 4 | from rest_framework import status
|
4 | 5 | from rest_framework.test import APITestCase
|
@@ -186,3 +187,22 @@ def test_create_one_resource_without_media_type(self):
|
186 | 187 | self.assertEqual(response.data['title'], "The Best Medium-Hard Data Analyst SQL Interview Questions")
|
187 | 188 | self.assertEqual(response.data['other_referring_source'], "twitter.com/lpnotes")
|
188 | 189 | 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