Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
elixir
beacon
Commits
8a39c6b0
Commit
8a39c6b0
authored
Jun 12, 2019
by
Jacek Lebioda
Browse files
Validation improvements
parent
4137cb3f
Pipeline
#10644
passed with stage
in 42 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
code/backend/beacon/data_types.py
View file @
8a39c6b0
...
...
@@ -43,9 +43,11 @@ def validate_input(**kwargs):
Validates query parameters. If there's a violation,
an `APIArgumentError` exception is raised
"""
def
wrap
(
name
,
message
,
regexp
,
can_skip
=
False
):
def
wrap
(
name
,
message
,
regexp
,
optional
=
False
):
re_regexp
=
re
.
compile
(
regexp
,
re
.
IGNORECASE
)
if
not
test_input_with_regex
(
kwargs
,
name
,
re_regexp
)
and
not
can_skip
:
if
name
not
in
kwargs
and
not
optional
:
raise
APIArgumentError
(
"A required value is missing: {0}"
.
format
(
name
))
if
name
in
kwargs
and
kwargs
[
name
]
is
not
None
and
not
re_regexp
.
match
(
kwargs
[
name
]):
arg
=
kwargs
.
get
(
name
)
if
kwargs
.
get
(
name
)
is
not
None
else
'<<None>>'
raise
APIArgumentError
(
"Invalid {0} ({1}) - {2}"
.
format
(
name
,
arg
,
message
))
...
...
@@ -55,33 +57,33 @@ def validate_input(**kwargs):
wrap
(
'start'
,
'should be a positive number'
,
r
'^\d
+
$'
,
True
)
r
'^\d
*
$'
,
optional
=
True
)
wrap
(
'startMin'
,
'should be an empty string or a positive number'
,
r
'^\d*$'
,
True
)
optional
=
True
)
wrap
(
'startMax'
,
'should be an empty string or a positive number'
,
r
'^\d*$'
,
True
)
optional
=
True
)
wrap
(
'end'
,
'should be an empty string or a positive number'
,
r
'^\d*$'
,
True
)
optional
=
True
)
wrap
(
'endMin'
,
'should be an empty string or a positive number'
,
r
'^\d*$'
,
True
)
optional
=
True
)
wrap
(
'endMax'
,
'should be an empty string or a positive number'
,
r
'^\d*$'
,
True
)
optional
=
True
)
wrap
(
'assemblyId'
,
'accepted ones are: GRCh38, GRCh37 and NCBI36'
,
...
...
@@ -94,12 +96,12 @@ def validate_input(**kwargs):
wrap
(
'alternateBases'
,
'should contain only A, C, T, G, D'
,
r
'^[actgd]*$'
,
True
)
optional
=
True
)
wrap
(
'includeDatasetResponses'
,
'accepts only "ALL", "HIT", "MISS", "NONE" and empty string'
,
r
'^(hit|all|miss|none)?$'
,
True
)
optional
=
True
)
return
True
...
...
@@ -218,9 +220,10 @@ def create_beacon_allele_request(**kwargs):
'datasetIds', 'includeDatasetResponses'
"""
fields_required
=
[
'referenceName'
,
'start'
,
'referenceBases'
,
'alternateBases'
,
'assemblyId'
]
fields_optional
=
[
'datasetIds'
,
'includeDatasetResponses'
,
fields_required
=
[
'referenceName'
]
fields_optional
=
[
'start'
,
'referenceBases'
,
'alternateBases'
,
'assemblyId'
,
'datasetIds'
,
'includeDatasetResponses'
,
'startMin'
,
'startMax'
,
'end'
,
'endMin'
,
'endMax'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment