-
Notifications
You must be signed in to change notification settings - Fork 9
test: add integration tests #40
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
Open
akash2237778
wants to merge
3
commits into
dev
Choose a base branch
from
integration_tests
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import json | ||
| import requests | ||
|
|
||
| from mock_data import ( | ||
| MOCK_OBJECT, | ||
| MOCK_SERVICE_INFO | ||
| ) | ||
|
|
||
|
|
||
| access_id = "" | ||
| base_url = "http://localhost:8080/ga4gh/drs/v1" | ||
| headers = { | ||
| 'Accept': 'application/json', | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| object_id = "" | ||
| payload_objects = json.dumps(MOCK_OBJECT) | ||
| payload_service_info = json.dumps(MOCK_SERVICE_INFO) | ||
|
|
||
|
|
||
| def test_error_404(): | ||
| """Test `GET /` for response 404 (Page not found)""" | ||
| endpoint = "/test_endpoint" | ||
| response = requests.request("GET", base_url + endpoint, headers=headers, | ||
| data={}) | ||
| assert response.status_code == 404 | ||
|
|
||
|
|
||
| def test_post_service_info(): | ||
| """Test `POST /service-info` for successfully creating or updating a new | ||
| service-info. | ||
| """ | ||
| endpoint = "/service-info" | ||
| response = requests.request("POST", base_url + endpoint, headers=headers, | ||
| data=payload_service_info) | ||
| assert response.status_code == 201 | ||
|
|
||
|
|
||
| def test_get_service_info(): | ||
| """Test `GET /service-info` for fetching service info.""" | ||
| endpoint = "/service-info" | ||
| response = requests.request("GET", base_url + endpoint, headers=headers) | ||
| assert response.status_code == 200 | ||
| assert json.loads(response.content) == json.loads(payload_service_info) | ||
|
|
||
|
|
||
| def test_error_400_service_info(): | ||
| """Test `POST /service-info` for response 400 (Bad request)""" | ||
| endpoint = "/service-info" | ||
| response = requests.request("POST", base_url + endpoint, headers=headers, | ||
| data={}) | ||
| assert response.status_code == 400 | ||
|
|
||
|
|
||
| def test_post_objects(): | ||
| """Test `POST /objects` for successfully registering an DrsObject.""" | ||
| global object_id | ||
| endpoint = "/objects" | ||
| response = requests.request("POST", base_url + endpoint, headers=headers, | ||
| data=payload_objects) | ||
| object_id = response.text.replace("\"", "").replace("\n", "") | ||
| assert response.status_code == 200 | ||
|
|
||
|
|
||
| def test_get_objects(): | ||
| """Test `GET /objects/{object_id}` for fetching info about DrsObject.""" | ||
| global access_id | ||
| is_expand = "True" | ||
| endpoint = "/objects/" + object_id + "?expand=" + is_expand | ||
| response = requests.request("GET", base_url + endpoint, headers=headers) | ||
| response_content = json.loads(response.text) | ||
| access_id = response_content['access_methods'][0]['access_id'] | ||
| assert response.status_code == 200 | ||
| assert response_content['name'] == json.loads(payload_objects)['name'] | ||
|
|
||
|
|
||
| def test_error_404_get_objects(): | ||
| """Test `GET /objects/{object_id}` for response 404 (Page not | ||
| found) | ||
| """ | ||
| endpoint = "/objects" + "/test_id" | ||
| response = requests.request("GET", base_url + endpoint, headers=headers, | ||
| data={}) | ||
| assert response.status_code == 404 | ||
|
|
||
|
|
||
| def test_error_400_objects(): | ||
| """Test `POST /objects` for response 400 (Bad request)""" | ||
| endpoint = "/objects" | ||
| response = requests.request("POST", base_url + endpoint, headers=headers, | ||
| data={}) | ||
| assert response.status_code == 400 | ||
|
|
||
|
|
||
| def test_get_objects_access(): | ||
| """Test `GET /objects/{object_id}/access/{access_id}` for fetching URL to | ||
| fetch the bytes of a DrsObject | ||
| """ | ||
| endpoint = "/objects/" + object_id + "/access/" + access_id | ||
| response = requests.request("GET", base_url + endpoint, headers=headers) | ||
| response_content = json.loads(response.text) | ||
| assert response.status_code == 200 | ||
| assert response_content['url'] == \ | ||
| json.loads(payload_objects)['access_methods'][0]['access_url']['url'] | ||
|
|
||
|
|
||
| def test_error_404_get_objects_access(): | ||
| """Test 'GET /objects/{object_id}/access/{access_id}' for handling | ||
| ERROR 404 (Page not found) | ||
| """ | ||
| endpoint = "/objects/" + object_id + "/access/" + "test_access_id" | ||
| response = requests.request("GET", base_url + endpoint, headers=headers) | ||
| assert response.status_code == 404 | ||
|
|
||
|
|
||
| def test_put_objects(): | ||
| """Test `PUT /objects/{object_id}` to modify or update a DrsObject""" | ||
| global access_id | ||
| endpoint = "/objects/" + object_id | ||
| object_put_payload = json.loads(payload_objects) | ||
| object_put_payload['name'] = "gerp_constrained_elements.tetraodon_" + \ | ||
| "nigroviridis.bed.gz" | ||
| response = requests.request("PUT", base_url + endpoint, headers=headers, | ||
| data=json.dumps(object_put_payload)) | ||
| assert response.status_code == 200 | ||
| is_expand = "True" | ||
| endpoint = "/objects/" + object_id + "?expand=" + is_expand | ||
| response = requests.request("GET", base_url + endpoint, headers=headers) | ||
| response_content = json.loads(response.text) | ||
| access_id = response_content['access_methods'][0]['access_id'] | ||
| assert response.status_code == 200 | ||
| assert response_content['name'] == \ | ||
| "gerp_constrained_elements.tetraodon_nigroviridis.bed.gz" | ||
|
|
||
|
|
||
| def test_delete_objects_access(): | ||
| """Test `DELETE /objects/{object_id}/access/{access_id}` to delete | ||
| DrsObject's access method. | ||
| """ | ||
| endpoint = "/objects/" + object_id + "/access/" + access_id | ||
| response = requests.request("DELETE", base_url + endpoint, headers=headers) | ||
| assert response.status_code == 200 | ||
| assert response.text.replace("\"", "").replace("\n", "") == access_id | ||
|
|
||
|
|
||
| def test_delete_objects(): | ||
| """Test `DELETE /objects/{object_id}` to delete existing DrsObject""" | ||
| endpoint = "/objects/" + object_id | ||
| response = requests.request("DELETE", base_url + endpoint, headers=headers) | ||
| assert response.status_code == 200 | ||
| assert response.text.replace("\"", "").replace("\n", "") == object_id | ||
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,76 @@ | ||
| """Mock data for testing.""" | ||
|
|
||
| MOCK_OBJECT = { | ||
| "name": "Homo_sapiens.GRCh38.dna.chromosome.19.fa.gz", | ||
| "size": 16700000, | ||
| "created_time": "2021-05-04T11:59:56.400Z", | ||
| "updated_time": "2021-05-04T11:59:56.400Z", | ||
| "version": "38", | ||
| "mime_type": "application/json", | ||
| "checksums": [ | ||
| { | ||
| "checksum": "18c2f5517e4ddc02cd57f6c7554b8e88", | ||
| "type": "md5" | ||
| } | ||
| ], | ||
| "access_methods": [ | ||
| { | ||
| "type": "ftp", | ||
| "access_url": { | ||
| "url": "ftp://ftp.ensembl.org/pub/release-96/fasta/homo_sapien" | ||
| "s/dna//Homo_sapiens.GRCh38.dna.chromosome.19.fa.gz", | ||
| "headers": [ | ||
| "None" | ||
| ] | ||
| }, | ||
| "region": "us-east-1" | ||
| }, | ||
| { | ||
| "type": "ftp", | ||
| "access_url": { | ||
| "url": "ftp://ftp.ensembl.org/pub/release-96/fasta/homo_sapien" | ||
| "s/dna//Homo_sapiens.GRCh38.dna.chromosome.19.fa.gz", | ||
| "headers": [ | ||
| "None" | ||
| ] | ||
| }, | ||
| "region": "us-east-1" | ||
| }, | ||
| ], | ||
| "contents": [ | ||
| { | ||
| "name": "Homo_sapiens", | ||
| "id": "b001", | ||
| "drs_uri": [ | ||
| "drs://drs.example.org/314159", | ||
| "drs://drs.example.org/213512" | ||
| ], | ||
| "contents": [] | ||
| } | ||
| ], | ||
| "description": "description", | ||
| "aliases": [ | ||
| "alias1" | ||
| ] | ||
| } | ||
|
|
||
| MOCK_SERVICE_INFO = { | ||
| "contactUrl": "mailto:support@example.com", | ||
| "createdAt": "2019-06-04T12:58:19Z", | ||
| "description": "This service provides...", | ||
| "documentationUrl": "https://docs.myservice.example.com", | ||
| "environment": "test", | ||
| "id": "org.ga4gh.myservice", | ||
| "name": "My project", | ||
| "organization": { | ||
| "name": "My organization", | ||
| "url": "https://example.com" | ||
| }, | ||
| "type": { | ||
| "artifact": "beacon", | ||
| "group": "org.ga4gh", | ||
| "version": "1.0.0" | ||
| }, | ||
| "updatedAt": "2019-06-04T12:58:19Z", | ||
| "version": "1.0.0" | ||
| } |
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.
Would be good to add test cases for some errors as well, especially 404 and 400. Eventually we should cover 401 and 403 as well, but we can do that once we have a better idea of how controlled access management will look like