-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Aratz/dev-2090_create_project_endpoint
Get either token or token path through API
- Loading branch information
Showing
5 changed files
with
78 additions
and
31 deletions.
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
from delivery.handlers import * | ||
from delivery.handlers.utility_handlers import ArteriaDeliveryBaseHandler | ||
|
||
import os | ||
import tempfile | ||
import logging | ||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -25,7 +27,8 @@ async def post(self, project_name): | |
Create a new project in DDS. The project description as well as the | ||
email of its pi must be specified in the request body. Project owners, | ||
researchers, and whether the data is sensitive or not (default is yes), | ||
can also be specified there. E.g.: | ||
can also be specified there. "auth_token" can be either the path to | ||
the authentication token or the token itself. E.g.: | ||
import requests | ||
|
@@ -37,16 +40,30 @@ async def post(self, project_name): | |
"researchers": ["[email protected]", "[email protected]"], | ||
"owners": ["[email protected]"], | ||
"non-sensitive": False, | ||
"token_path": "/foo/bar" | ||
"auth_token": "1234" | ||
} | ||
response = requests.request("POST", url, json=payload) | ||
""" | ||
|
||
required_members = ["token_path"] | ||
project_metadata = self.body_as_object(required_members=required_members) | ||
required_members = ["auth_token"] | ||
project_metadata = self.body_as_object( | ||
required_members=required_members) | ||
|
||
dds_project_id = await self.dds_service.create_dds_project(project_name, project_metadata) | ||
with tempfile.NamedTemporaryFile(mode='w', delete=True) as token_file: | ||
if os.path.exists(project_metadata["auth_token"]): | ||
token_path = project_metadata["auth_token"] | ||
else: | ||
token_file.write(project_metadata["auth_token"]) | ||
token_file.flush() | ||
|
||
token_path = token_file.name | ||
|
||
dds_project_id = await self.dds_service.create_dds_project( | ||
project_name, | ||
project_metadata, | ||
token_path, | ||
) | ||
|
||
self.set_status(ACCEPTED) | ||
self.write_json({'dds_project_id': dds_project_id}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ def test_can_stage_and_delivery_runfolder(self): | |
delivery_body = { | ||
'delivery_project_id': 'fakedeliveryid2016', | ||
'dds': True, | ||
'token_path': 'token_path', | ||
'auth_token': '1234', | ||
'skip_mover': True, | ||
} | ||
delivery_resp = yield self.http_client.fetch(self.get_url(delivery_url), method='POST', body=json.dumps(delivery_body)) | ||
|
@@ -102,7 +102,7 @@ def test_can_stage_and_delivery_project_dir(self): | |
'delivery_project_id': 'fakedeliveryid2016', | ||
'skip_mover': True, | ||
'dds': True, | ||
'token_path': 'token_path', | ||
'auth_token': '1234', | ||
} | ||
delivery_resp = yield self.http_client.fetch(self.get_url(delivery_url), method='POST', body=json.dumps(delivery_body)) | ||
delivery_resp_as_json = json.loads(delivery_resp.body) | ||
|
@@ -214,7 +214,7 @@ def test_can_create_project(self): | |
"researchers": ["[email protected]", "[email protected]"], | ||
"owners": ["[email protected]"], | ||
"non-sensitive": False, | ||
"token_path": '/foo/bar/auth', | ||
"auth_token": '1234', | ||
} | ||
|
||
response = yield self.http_client.fetch( | ||
|
@@ -234,7 +234,7 @@ def test_can_create_two_projects(self): | |
"researchers": ["[email protected]", "[email protected]"], | ||
"owners": ["[email protected]"], | ||
"non-sensitive": False, | ||
"token_path": '/foo/bar/auth', | ||
"auth_token": '1234', | ||
} | ||
|
||
response = yield self.http_client.fetch( | ||
|
@@ -294,7 +294,7 @@ def test_can_deliver_and_respond(self): | |
delivery_body = { | ||
'delivery_project_id': 'fakedeliveryid2016', | ||
'dds': True, | ||
'token_path': 'token_path', | ||
'auth_token': '1234', | ||
'skip_mover': False, | ||
} | ||
delivery_response = self.http_client.fetch(self.get_url(delivery_url), method='POST', body=json.dumps(delivery_body)) | ||
|
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 |
---|---|---|
|
@@ -186,30 +186,37 @@ def test_parse_dds_project_id(self): | |
self.assertEqual(DDSService._parse_dds_project_id(dds_output), "snpseq00003") | ||
|
||
@gen_test | ||
def test_create_project(self): | ||
def test_create_project_token_file(self): | ||
project_name = "AA-1221" | ||
project_metadata = { | ||
"description": "Dummy project", | ||
"pi": "[email protected]", | ||
"researchers": ["[email protected]", "[email protected]"], | ||
"owners": ["[email protected]"], | ||
"non-sensitive": False, | ||
"token_path": "/foo/bar/auth", | ||
} | ||
|
||
token_path = "/foo/bar/auth" | ||
|
||
with patch( | ||
'delivery.services.external_program_service' | ||
'.ExternalProgramService.run_and_wait', | ||
new_callable=AsyncMock) as mock_run,\ | ||
patch('delivery.services.dds_service.DDSService._parse_dds_project_id') as mock_parse_dds_project_id: | ||
patch( | ||
'delivery.services.dds_service' | ||
'.DDSService._parse_dds_project_id' | ||
) as mock_parse_dds_project_id: | ||
mock_run.return_value.status_code = 0 | ||
mock_parse_dds_project_id.return_value = "snpseq00001" | ||
|
||
yield self.dds_service.create_dds_project(project_name, project_metadata) | ||
yield self.dds_service.create_dds_project( | ||
project_name, | ||
project_metadata, | ||
token_path) | ||
|
||
mock_run.assert_called_once_with([ | ||
'dds', | ||
'--token-path', '/foo/bar/auth', | ||
'--token-path', token_path, | ||
'--log-file', '/foo/bar/log', | ||
'project', 'create', | ||
'--title', project_name, | ||
|
@@ -220,6 +227,6 @@ def test_create_project(self): | |
'--researcher', project_metadata['researchers'][1], | ||
]) | ||
self.mock_dds_project_repo.add_dds_project\ | ||
.assert_called_once_with( | ||
project_name=project_name, | ||
dds_project_id=mock_parse_dds_project_id.return_value) | ||
.assert_called_once_with( | ||
project_name=project_name, | ||
dds_project_id=mock_parse_dds_project_id.return_value) |