Skip to content
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

Implement new organise handlers #47

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Aratz
Copy link
Contributor

@Aratz Aratz commented Aug 7, 2023

What problems does this PR solve?
This PR adds handlers to connect the webservice's endpoints to the organise service. This might be need to be adapted in the future depending on the rest of the code so this is only a draft for now.

How has the changes been tested?
Unit tests have been added, not sure if integration tests should be added already or if we should wait until we have all the pieces.

Reasons for careful code review
If any of the boxes below are checked, extra careful code review should be inititated.

  • This PR contains code that could remove data

@Aratz Aratz requested review from b97pla and monikaBrandt August 7, 2023 07:24
@Aratz Aratz self-assigned this Aug 7, 2023
@Aratz Aratz force-pushed the BIO-2361_implement_handler branch from 942999a to 7777dd1 Compare September 15, 2023 14:21
Copy link
Contributor

@b97pla b97pla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 great work!

I had some comments but feel free to disagree 😄

"required": {"type": "boolean"},
"link_type": {
"type": "string",
"enum": ["softlink", "hardlink", "copy"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we decided on removing the hardlink option


# Status codes
OK = 200
ACCEPTED = 202
NO_CONTENT = 204

BAD_REQUEST = 400
FORBIDDEN = 403
NOT_FOUND = 404
INTERNAL_SERVER_ERROR = 500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can of course import these codes directly from the http.HTTPStatus module to avoid re-defining them

except jsonschema.ValidationError as validation_error:
self.set_status(BAD_REQUEST)
self.write(str(validation_error))
return wrapper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Very nice!

staging and delivery.
"""

def initialize(self, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it an expected pattern in the handlers to have a initialize-function instead of/in addition to the constructor?

config = yaml.load(organise_config_file, Loader=yaml.CLoader)
with open(organise_config_dir / "schema.json", 'r') as organise_config_schema:
schema = json.load(organise_config_schema)
jsonschema.validate(config, schema)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for re-usability, it could be nice to break out the validation code to its own (static) function, perhaps even move it to another service if that fits with the overall code structure

maybe it's up for consideration if the validation should happen here in the handler or downstream in the service?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, this code is more or less repeated (with slight variations) in all three organize handlers, could you consider breaking it out to a helper function that can be called instead?

if self.dummy_config[key] is None:
tempdir = tempfile.TemporaryDirectory()
self.__setattr__(f"_{key}", tempdir)
self.dummy_config[key] = tempdir.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

class TestOrganiseHandlers(AsyncHTTPTestCase):
API_BASE = "/api/1.0"

def get_app(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the get_app function called automatically by the test framework when setting up the tests?

self.assertEqual(response.code, 404)

def test_project_analysis_handler_missing_config_file(self):
analysis = "rnaseq"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitpick: might be a good idea to use a dummy value instead of a potentially valid analysis name

method="POST", body='',
)

self.assertEqual(response.code, 500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is 500 but above (and below) it's a 404, is this intentional?

method="POST", body='{}',
)

self.assertEqual(response.code, 200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this give 404 or 500?

Copy link
Contributor

@monikaBrandt monikaBrandt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice! However, depending on the answer on if we really need several handlers when using a configuration file as a template for the organization I might have more comments. This is nothing that needs to be addressed now, but we should discuss it before continuing working on this project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

url(r"/api/1.0/organise/runfolder/([^/]+)", OrganiseRunfolderHandler,
name="organise_runfolder", kwargs=kwargs),

url(r"/api/1.0/organise/delivery/runfolder/([^/]+)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need one endpoint for every type of organization we want to do? Shouldn't it be enough to have one OrganiseRunfolderConfigHandler since the organization it self is defined in the config? Please correct me if I get it all wrong :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants