-
-
Notifications
You must be signed in to change notification settings - Fork 22
[Issue 125 Fix] : Added Serializer Field to Properly Resolve Choices in Resource.media_type Field #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[Issue 125 Fix] : Added Serializer Field to Properly Resolve Choices in Resource.media_type Field #140
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1f60b68
Added fix for missing media_type on save. Created new to_representat…
BethanyG 220c362
Uncommented and fixed create_one_resourcez_with_media_type test. Add…
BethanyG 9c85970
Added error check for when the media type is invalid.
BethanyG 5d99fa0
Added create_one_resource_with_invalid_media_type test case.
BethanyG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from unittest import skip | ||
from pytest import raises | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, didn't know about |
||
from random import randint | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
|
@@ -145,8 +146,7 @@ def test_view_one_resource(self): | |
self.assertEqual(response.data['title'], new_resource.title) | ||
self.assertEqual(response.data['description'], new_resource.description) | ||
|
||
@skip('https://github.com/codebuddies/backend/issues/125') | ||
def test_create_one_resource(self): | ||
def test_create_one_resource_with_media_type(self): | ||
url = '/api/v1/resources/' | ||
data = {"title": "The Modern JavaScript Tutorial", | ||
"author": "iliakan", | ||
|
@@ -165,4 +165,44 @@ def test_create_one_resource(self): | |
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(response.data['title'], "The Modern JavaScript Tutorial") | ||
self.assertEqual(response.data['other_referring_source'], "iliakan@javascript.info") | ||
self.assertEqual(response.data['media_type'], 'WEB') | ||
self.assertEqual(response.data['media_type'], 'Website') | ||
|
||
def test_create_one_resource_without_media_type(self): | ||
url = '/api/v1/resources/' | ||
data = {"title": "The Best Medium-Hard Data Analyst SQL Interview Questions", | ||
"author": "Zachary Thomas", | ||
"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.", | ||
"url": "https://quip.com/2gwZArKuWk7W", | ||
"referring_url": "https://quip.com", | ||
"other_referring_source": "twitter.com/lpnotes", | ||
"date_published": "2020-04-19T03:27:06Z", | ||
"created": "2020-05-02T03:27:06.485Z", | ||
"modified": "2020-05-02T03:27:06.485Z", | ||
"media_type": "", | ||
"tags": ["SQLt", "BackEnd", "Databases"] | ||
} | ||
|
||
response = self.client.post(url, data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(response.data['title'], "The Best Medium-Hard Data Analyst SQL Interview Questions") | ||
self.assertEqual(response.data['other_referring_source'], "twitter.com/lpnotes") | ||
self.assertEqual(response.data['media_type'], '') | ||
|
||
def test_create_one_resource_with_invalid_media_type(self): | ||
with raises(KeyError, match=r"The media type should be one of the following:"): | ||
url = '/api/v1/resources/' | ||
data = {"title": "The Best Medium-Hard Data Analyst SQL Interview Questions", | ||
"author": "Zachary Thomas", | ||
"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.", | ||
"url": "https://quip.com/2gwZArKuWk7W", | ||
"referring_url": "https://quip.com", | ||
"other_referring_source": "twitter.com/lpnotes", | ||
"date_published": "2020-04-19T03:27:06Z", | ||
"created": "2020-05-02T03:27:06.485Z", | ||
"modified": "2020-05-02T03:27:06.485Z", | ||
"media_type": "DOP", | ||
"tags": ["SQLt", "BackEnd", "Databases"] | ||
} | ||
|
||
response = self.client.post(url, data, format='json') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.