-
Notifications
You must be signed in to change notification settings - Fork 14
[BUG] Fix results_iter when API returns an object CAT-213 #35
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
rhiannon-eldridge-lrn
merged 8 commits into
master
from
CAT-213/bug/fix-results-iter-for-object-responses
Aug 7, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0143e30
[BUG] Fix issue with results_iter when API returns an object CAT-213
rhiannon-eldridge-lrn 3222221
[BUG] Fix issue with results_iter when API returns an object CAT-213
rhiannon-eldridge-lrn 8d559a3
fixup! [BUG] Fix issue with results_iter when API returns an object C…
rhiannon-eldridge-lrn 51a0a4f
fixup! fixup! [BUG] Fix issue with results_iter when API returns an o…
rhiannon-eldridge-lrn 4c2b8c9
fixup! fixup! fixup! [BUG] Fix issue with results_iter when API retur…
rhiannon-eldridge-lrn 390b8fd
fixup! fixup! fixup! fixup! [BUG] Fix issue with results_iter when AP…
rhiannon-eldridge-lrn e1ceb30
fixup! fixup! fixup! fixup! fixup! [BUG] Fix issue with results_iter …
rhiannon-eldridge-lrn 7c6ef52
Update learnosity_sdk/request/dataapi.py
rhiannon-eldridge-lrn 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .idea | ||
| *.egg-info | ||
| *.pyc | ||
| .tox | ||
|
|
||
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
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,5 +1,5 @@ | ||
| from .lrnuuid import Uuid | ||
|
|
||
| __all__ = [ | ||
| "Uuid", | ||
| "Uuid" | ||
| ] |
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 |
|---|---|---|
|
|
@@ -2,43 +2,38 @@ | |
| import os | ||
| from learnosity_sdk.request import DataApi | ||
|
|
||
|
|
||
| # This test uses the consumer key and secret for the demos consumer | ||
| # this is the only consumer with publicly available keys | ||
| security = { | ||
| 'consumer_key': 'yis0TYCu7U9V4o7M', | ||
| 'domain': 'demos.learnosity.com' | ||
| } | ||
|
|
||
| # WARNING: Normally the consumer secret should not be committed to a public | ||
| # repository like this one. Only this specific key is publically available. | ||
| consumer_secret = '74c5fd430cf1242a527f6223aebd42d30464be22' | ||
| request = { | ||
| action = 'get' | ||
|
|
||
| items_request = { | ||
| # These items should already exist for the demos consumer | ||
| 'references': ['item_2', 'item_3'], | ||
| 'limit': 1 | ||
| } | ||
| action = 'get' | ||
| endpoint = '/itembank/items' | ||
| dummy_responses = [{ | ||
| 'meta': { | ||
| 'status': True, | ||
| 'timestamp': 1514874527, | ||
| 'records': 2, | ||
| 'next': '1' | ||
| }, | ||
| 'data': [{'id': 'a'}] | ||
| }, { | ||
| 'meta': { | ||
| 'status': True, | ||
| 'timestamp': 1514874527, | ||
| 'records': 2 | ||
| }, | ||
| 'data': [{'id': 'b'}] | ||
| }] | ||
| items_endpoint = '/itembank/items' | ||
|
|
||
| questions_request = { | ||
| # These items should already exist for the demos consumer | ||
| 'item_references': ['py-sdk-test-2019-1', 'py-sdk-test-2019-2'], | ||
| 'limit': 1 | ||
| } | ||
| questions_endpoint = '/itembank/questions' | ||
|
|
||
|
|
||
| class IntegrationTestDataApiClient(unittest.TestCase): | ||
|
|
||
| def _build_base_url(self): | ||
| @staticmethod | ||
| def __build_base_url(): | ||
|
Contributor
Author
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 changed this to a static method as it's only used internally by the integration tests and does not access any class variables. |
||
| env = os.environ | ||
| env_domain = '' | ||
| region_domain = '.learnosity.com' | ||
|
|
@@ -55,34 +50,67 @@ def _build_base_url(self): | |
|
|
||
| base_url = "https://data%s%s/%s" % (env_domain, region_domain, version_path) | ||
|
|
||
| print('Using base URL: ' + base_url) | ||
|
|
||
| return base_url | ||
|
|
||
|
|
||
| def test_real_request(self): | ||
| """Make a request against Data Api to ensure the SDK works""" | ||
| client = DataApi() | ||
| res = client.request(self._build_base_url() + endpoint, security, consumer_secret, request, | ||
| res = client.request(self.__build_base_url() + items_endpoint, security, consumer_secret, items_request, | ||
| action) | ||
| print(res.request.url) | ||
| print(res.request.body) | ||
| print(res.content) | ||
| returned_json = res.json() | ||
|
|
||
| assert len(returned_json['data']) > 0 | ||
|
|
||
| returned_ref = returned_json['data'][0]['reference'] | ||
| assert returned_ref in request['references'] | ||
| assert returned_ref in items_request['references'] | ||
|
|
||
| def test_paging(self): | ||
| """Verify that paging works""" | ||
| client = DataApi() | ||
| pages = client.request_iter(self._build_base_url() + endpoint, security, consumer_secret, | ||
| request, action) | ||
| pages = client.request_iter(self.__build_base_url() + items_endpoint, security, consumer_secret, | ||
| items_request, action) | ||
| results = set() | ||
|
|
||
| for page in pages: | ||
| if page['data']: | ||
| results.add(page['data'][0]['reference']) | ||
|
|
||
| assert len(results) == 2 | ||
| assert results == {'item_2', 'item_3'} | ||
|
|
||
| def test_real_question_request(self): | ||
| """Make a request against Data Api to ensure the SDK works""" | ||
| client = DataApi() | ||
|
|
||
| questions_request['limit'] = 3 | ||
| res = client.request(self.__build_base_url() + questions_endpoint, security, consumer_secret, questions_request, | ||
| action) | ||
|
|
||
| returned_json = res.json() | ||
| assert len(returned_json['data']) > 0 | ||
|
|
||
| keys = set() | ||
| for key in returned_json['data']: | ||
| keys.add(key) | ||
|
|
||
| assert keys == {'py-sdk-test-2019-1', 'py-sdk-test-2019-2'} | ||
|
|
||
| def test_question_paging(self): | ||
| """Verify that paging works""" | ||
| client = DataApi() | ||
|
|
||
| pages = client.request_iter(self.__build_base_url() + questions_endpoint, security, consumer_secret, | ||
| questions_request, action) | ||
|
|
||
| results = [] | ||
| for page in pages: | ||
| if page['data']: | ||
| results.append(page['data']) | ||
|
|
||
| keys = set() | ||
| for row in results: | ||
| for key in row.keys(): | ||
| keys.add(key) | ||
|
|
||
| assert len(results) == 3 | ||
flakeparadigm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert keys == {'py-sdk-test-2019-1', 'py-sdk-test-2019-2'} | ||
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.