-
Couldn't load subscription status.
- Fork 79
Labman minimal changes #2633
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
Labman minimal changes #2633
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 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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| import qiita_db as qdb | ||
| from .oauth2 import OauthBaseHandler, authenticate_oauth | ||
| from .util import _get_instance | ||
|
|
||
|
|
||
| class SampleInfoDBHandler(OauthBaseHandler): | ||
| @authenticate_oauth | ||
| def get(self, study_id): | ||
| """Retrieves the sample information content | ||
|
|
||
| Parameters | ||
| ---------- | ||
| study_id: str | ||
| The id of the study whose sample information is being retrieved | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| The contents of the sample information keyed by sample id | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| ST = qdb.metadata_template.sample_template.SampleTemplate | ||
| st = _get_instance(ST, study_id, 'Error instantiating sample info') | ||
| response = {'data': st.to_dataframe().to_dict(orient='index')} | ||
|
|
||
| self.write(response) |
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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from unittest import main | ||
| from json import loads | ||
|
|
||
| from qiita_db.handlers.tests.oauthbase import OauthTestingBase | ||
|
|
||
|
|
||
| class SampleInfoDBHandlerTests(OauthTestingBase): | ||
| def test_get_does_not_exist(self): | ||
| obs = self.get('/qiita_db/sample_information/100/data/', | ||
| headers=self.header) | ||
| self.assertEqual(obs.code, 404) | ||
|
|
||
| def test_get_no_header(self): | ||
| obs = self.get('/qiita_db/sample_information/100/data/') | ||
| self.assertEqual(obs.code, 400) | ||
|
|
||
| def test_get(self): | ||
| obs = self.get('/qiita_db/sample_information/1/data/', | ||
| headers=self.header) | ||
| self.assertEqual(obs.code, 200) | ||
|
|
||
| obs = loads(obs.body) | ||
| self.assertEqual(obs.keys(), ['data']) | ||
|
|
||
| # for simplicity we will only test that the keys are the same | ||
| # and that one of the key's info is correct | ||
| obs = obs['data'] | ||
| exp = ['1.SKB2.640194', '1.SKM4.640180', '1.SKB3.640195', | ||
| '1.SKB6.640176', '1.SKD6.640190', '1.SKM6.640187', | ||
| '1.SKD9.640182', '1.SKM8.640201', '1.SKM2.640199', | ||
| '1.SKD2.640178', '1.SKB7.640196', '1.SKD4.640185', | ||
| '1.SKB8.640193', '1.SKM3.640197', '1.SKD5.640186', | ||
| '1.SKB1.640202', '1.SKM1.640183', '1.SKD1.640179', | ||
| '1.SKD3.640198', '1.SKB5.640181', '1.SKB4.640189', | ||
| '1.SKB9.640200', '1.SKM9.640192', '1.SKD8.640184', | ||
| '1.SKM5.640177', '1.SKM7.640188', '1.SKD7.640191'] | ||
| self.assertItemsEqual(obs.keys(), exp) | ||
|
|
||
| obs = obs['1.SKB1.640202'] | ||
| exp = {'qiita_study_id': '1', 'physical_specimen_location': 'ANL', | ||
| 'tot_org_carb': '5', 'common_name': 'soil metagenome', | ||
| 'water_content_soil': '0.164', | ||
| 'env_feature': 'ENVO:plant-associated habitat', | ||
| 'assigned_from_geo': 'n', 'altitude': '0', | ||
| 'env_biome': ('ENVO:Temperate grasslands, savannas, and ' | ||
| 'shrubland biome'), | ||
| 'texture': '64.6 sand, 17.6 silt, 17.8 clay', | ||
| 'scientific_name': '1118232', | ||
| 'description_duplicate': 'Burmese bulk', | ||
| 'latitude': '4.59216095574', 'ph': '6.94', 'host_taxid': '3483', | ||
| 'elevation': '114', 'description': 'Cannabis Soil Microbiome', | ||
| 'collection_timestamp': '2011-11-11 13:00:00', | ||
| 'physical_specimen_remaining': 'true', 'dna_extracted': 'true', | ||
| 'taxon_id': '410658', 'samp_salinity': '7.15', | ||
| 'host_subject_id': '1001:M2', 'sample_type': 'ENVO:soil', | ||
| 'season_environment': 'winter', 'temp': '15', | ||
| 'country': 'GAZ:United States of America', | ||
| 'longitude': '63.5115213108', 'tot_nitro': '1.41', | ||
| 'depth': '0.15', 'anonymized_name': 'SKB1'} | ||
| self.assertEqual(obs, exp) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from unittest import main | ||
| from json import loads | ||
|
|
||
| from qiita_db.handlers.tests.oauthbase import OauthTestingBase | ||
|
|
||
|
|
||
| class UserInfoDBHandlerTests(OauthTestingBase): | ||
| def test_get_does_not_exist(self): | ||
| obs = self.get('/qiita_db/user/no-exists@foo.bar/data/', | ||
| headers=self.header) | ||
| self.assertEqual(obs.code, 404) | ||
|
|
||
| def test_get_no_header(self): | ||
| obs = self.get('/qiita_db/user/no-exists@foo.bar/data/') | ||
| self.assertEqual(obs.code, 400) | ||
|
|
||
| def test_get(self): | ||
| obs = self.get('/qiita_db/user/shared@foo.bar/data/', | ||
| headers=self.header) | ||
| self.assertEqual(obs.code, 200) | ||
|
|
||
| obs = loads(obs.body) | ||
| self.assertEqual(obs.keys(), ['data']) | ||
|
|
||
| # for simplicity we will only test that the keys are the same | ||
| # and that one of the key's info is correct | ||
| obs = obs['data'] | ||
| exp = {"password": "$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJk" | ||
| "UM8nXG9Efe", "email": "shared@foo.bar", "level": "user"} | ||
| self.assertEqual(obs, exp) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from unittest import main | ||
|
|
||
| from tornado.web import HTTPError | ||
|
|
||
| from qiita_db.handlers.tests.oauthbase import OauthTestingBase | ||
| import qiita_db as qdb | ||
|
|
||
|
|
||
| class UtilTests(OauthTestingBase): | ||
| def test_get_sample_info(self): | ||
| ST = qdb.metadata_template.sample_template.SampleTemplate | ||
| exp = ST(1) | ||
| obs = qdb.handlers.util._get_instance(ST, 1, 'error') | ||
| self.assertEqual(obs, exp) | ||
|
|
||
| # It does not exist | ||
| with self.assertRaises(HTTPError): | ||
| qdb.handlers.util._get_instance(ST, 100, 'error') | ||
|
|
||
| def test_get_user_info(self): | ||
| US = qdb.user.User | ||
| obs = qdb.handlers.util._get_instance(US, 'shared@foo.bar', 'error') | ||
| exp = US('shared@foo.bar') | ||
| self.assertEqual(obs, exp) | ||
|
|
||
| # It does not exist | ||
| with self.assertRaises(HTTPError): | ||
| qdb.handlers.util._get_instance(US, 'no-exists@foo.bar', 'error') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| import qiita_db as qdb | ||
| from .oauth2 import OauthBaseHandler, authenticate_oauth | ||
| from .util import _get_instance | ||
|
|
||
|
|
||
| class UserInfoDBHandler(OauthBaseHandler): | ||
| @authenticate_oauth | ||
| def get(self, email): | ||
| """Retrieves the User information | ||
|
|
||
| Parameters | ||
| ---------- | ||
| email: str | ||
| The email of the user whose information is being retrieved | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| The user information as a dict | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| user = _get_instance(qdb.user.User, email, | ||
| 'Error instantiating user') | ||
| response = {'data': {'email': email, 'level': user.level, | ||
| 'password': user.password}} | ||
|
|
||
| self.write(response) |
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from tornado.web import HTTPError | ||
|
|
||
| import qiita_db as qdb | ||
|
|
||
|
|
||
| def _get_instance(klass, oid, reason): | ||
| """ | ||
| Returns the klass instance with the given `oid` | ||
|
|
||
| Parameters | ||
| ---------- | ||
| klass : class name | ||
| The class name to instanciate | ||
| oid : int/str | ||
| The object id | ||
| reason : str | ||
| The failure reason we want to be displayed | ||
|
|
||
| Returns | ||
| ------- | ||
| qiita_db.user.User | ||
| The requested user | ||
|
|
||
| Raises | ||
| ------ | ||
| HTTPError | ||
| If the user does not exist, with error code 404 | ||
| If there is a problem instantiating, with error code 500 | ||
| """ | ||
| try: | ||
| object = klass(oid) | ||
| except qdb.exceptions.QiitaDBUnknownIDError: | ||
| raise HTTPError(404) | ||
| except Exception as e: | ||
| raise HTTPError(500, reason=reason + ', id=%s: %s' % (oid, str(e))) | ||
|
|
||
| return object |
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
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
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.
I believe you should be able to add an argument to this method call
asjson=Trueso that the returned data inbodyis already parsed as a JSON object.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.
If this work, can you fix where appropriate in this PR?
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.
k
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.
tried, and didn't work, perhaps we are using an older version
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.
Thanks for giving that a shot. I'm surprised that's the case, maybe there are slightly different test classes in Qiita.