This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
EDUCATOR-464: Add POST method to course_summaries/ #173
Merged
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -9,3 +9,4 @@ Jason Bau <[email protected]> | |
John Jarvis <[email protected]> | ||
Dmitry Viskov <[email protected]> | ||
Eric Fischer <[email protected]> | ||
Kyle McCormick <[email protected]> | ||
This file contains 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 |
---|---|---|
|
@@ -100,15 +100,29 @@ class APIListViewTestMixin(object): | |
list_name = 'list' | ||
default_ids = [] | ||
always_exclude = ['created'] | ||
test_post_method = False | ||
|
||
def path(self, ids=None, fields=None, exclude=None, **kwargs): | ||
query_params = {} | ||
for query_arg, data in zip([self.ids_param, 'fields', 'exclude'], [ids, fields, exclude]) + kwargs.items(): | ||
if data: | ||
query_params[query_arg] = ','.join(data) | ||
query_string = '?{}'.format(urlencode(query_params)) | ||
def path(self, query_data=None): | ||
query_data = query_data or {} | ||
concat_query_data = {param: ','.join(arg) for param, arg in query_data.items() if arg} | ||
query_string = '?{}'.format(urlencode(concat_query_data)) if concat_query_data else '' | ||
return '/api/v0/{}/{}'.format(self.list_name, query_string) | ||
|
||
def validated_request(self, ids=None, fields=None, exclude=None, **extra_args): | ||
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. This is the function I'm most interested in feedback on. I'm making it so every request is done as both a GET and POST, and the results are compared before returning. Let me know what you think @efischer19. 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. I like it, very nice test addition |
||
params = [self.ids_param, 'fields', 'exclude'] | ||
args = [ids, fields, exclude] | ||
data = {param: arg for param, arg in zip(params, args) if arg} | ||
data.update(extra_args) | ||
|
||
get_response = self.authenticated_get(self.path(data)) | ||
if self.test_post_method: | ||
post_response = self.authenticated_post(self.path(), data=data) | ||
self.assertEquals(get_response.status_code, post_response.status_code) | ||
if 200 <= get_response.status_code < 300: | ||
self.assertEquals(get_response.data, post_response.data) | ||
|
||
return get_response | ||
|
||
def create_model(self, model_id, **kwargs): | ||
pass # implement in subclass | ||
|
||
|
@@ -134,19 +148,19 @@ def all_expected_results(self, ids=None, **kwargs): | |
|
||
def _test_all_items(self, ids): | ||
self.generate_data() | ||
response = self.authenticated_get(self.path(ids=ids, exclude=self.always_exclude)) | ||
response = self.validated_request(ids=ids, exclude=self.always_exclude) | ||
self.assertEquals(response.status_code, 200) | ||
self.assertItemsEqual(response.data, self.all_expected_results(ids=ids)) | ||
|
||
def _test_one_item(self, item_id): | ||
self.generate_data() | ||
response = self.authenticated_get(self.path(ids=[item_id], exclude=self.always_exclude)) | ||
response = self.validated_request(ids=[item_id], exclude=self.always_exclude) | ||
self.assertEquals(response.status_code, 200) | ||
self.assertItemsEqual(response.data, [self.expected_result(item_id)]) | ||
|
||
def _test_fields(self, fields): | ||
self.generate_data() | ||
response = self.authenticated_get(self.path(fields=fields)) | ||
response = self.validated_request(fields=fields) | ||
self.assertEquals(response.status_code, 200) | ||
|
||
# remove fields not requested from expected results | ||
|
@@ -158,10 +172,10 @@ def _test_fields(self, fields): | |
self.assertItemsEqual(response.data, expected_results) | ||
|
||
def test_no_items(self): | ||
response = self.authenticated_get(self.path()) | ||
response = self.validated_request() | ||
self.assertEquals(response.status_code, 404) | ||
|
||
def test_no_matching_items(self): | ||
self.generate_data() | ||
response = self.authenticated_get(self.path(ids=['no/items/found'])) | ||
response = self.validated_request(ids=['no/items/found']) | ||
self.assertEquals(response.status_code, 404) |
This file contains 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇