Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mutalyzer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirrors
mutalyzer
Commits
0f6ae962
Commit
0f6ae962
authored
11 years ago
by
Vermaat
Browse files
Options
Downloads
Patches
Plain Diff
Update unit tests for JSON services
parent
f6428b2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_services_json.py
+32
-72
32 additions, 72 deletions
tests/test_services_json.py
with
32 additions
and
72 deletions
tests/test_services_json.py
+
32
−
72
View file @
0f6ae962
"""
Tests for the SO
AP
interface to Mutalyzer.
Tests for the
J
SO
N
interface to Mutalyzer.
"""
from
urllib
import
urlencode
import
simplejson
as
json
import
requests
from
nose.tools
import
*
import
simplejson
as
json
from
spyne.server.null
import
NullServer
import
mutalyzer
SERVICE_ROOT
=
'
http://localhost/mutalyzer/json/
'
def
call
(
method
,
**
kwargs
):
"""
Do a HTTP/RPC request and decode the JSON response.
"""
r
=
requests
.
get
(
SERVICE_ROOT
+
method
+
'
?
'
+
urlencode
(
kwargs
))
return
json
.
loads
(
r
.
content
)
from
mutalyzer.services.json
import
application
class
TestServicesJson
():
"""
Test the Mutalyzer HTTP/RPC+JSON interface.
"""
def
setUp
(
self
):
"""
Initialize test server.
"""
self
.
server
=
NullServer
(
application
,
ostr
=
True
)
def
_call
(
self
,
method
,
*
args
,
**
kwargs
):
r
=
getattr
(
self
.
server
.
service
,
method
)(
*
args
,
**
kwargs
)
return
json
.
loads
(
''
.
join
(
r
))
def
test_checksyntax_valid
(
self
):
"""
Running checkSyntax with a valid variant name should return True.
"""
r
=
call
(
'
checkSyntax
'
,
variant
=
'
AB026906.1:c.274G>T
'
)
assert_equal
(
r
[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
valid
'
],
True
)
r
=
self
.
_
call
(
'
checkSyntax
'
,
variant
=
'
AB026906.1:c.274G>T
'
)
assert_equal
(
r
,
{
'
valid
'
:
True
,
'
messages
'
:
[]}
)
def
test_checksyntax_invalid
(
self
):
"""
Running checkSyntax with an invalid variant name should return False
and give at least one error message.
"""
r
=
call
(
'
checkSyntax
'
,
variant
=
'
0:abcd
'
)
assert_equal
(
r
[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
valid
'
],
False
)
assert
len
(
r
[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
messages
'
][
'
SoapMessage
'
])
>=
1
r
=
self
.
_
call
(
'
checkSyntax
'
,
variant
=
'
0:abcd
'
)
assert_equal
(
r
[
'
valid
'
],
False
)
assert
len
(
r
[
'
messages
'
])
>=
1
def
test_checksyntax_empty
(
self
):
"""
Running checkSyntax with no variant name should raise exception.
"""
r
=
call
(
'
checkSyntax
'
)
assert
r
[
'
Fault
'
]
# The validator doesn't work with NullServer, so we cannot do this
# test. See https://github.com/arskom/spyne/issues/318
#r = self._call('checkSyntax')
#assert_equal(r['faultcode'], 'Client.ValidationError')
pass
def
test_transcriptinfo_valid
(
self
):
"""
Running transcriptInfo with valid arguments should get us a Transcript
object.
"""
r
=
call
(
'
transcriptInfo
'
,
LOVD_ver
=
'
123
'
,
build
=
'
hg19
'
,
accNo
=
'
NM_002001.2
'
)
assert_equal
(
r
[
'
transcriptInfoResponse
'
][
'
transcriptInfoResult
'
][
'
trans_start
'
],
-
99
)
assert_equal
(
r
[
'
transcriptInfoResponse
'
][
'
transcriptInfoResult
'
][
'
trans_stop
'
],
1066
)
assert_equal
(
r
[
'
transcriptInfoResponse
'
][
'
transcriptInfoResult
'
][
'
CDS_stop
'
],
774
)
r
=
self
.
_
call
(
'
transcriptInfo
'
,
LOVD_ver
=
'
123
'
,
build
=
'
hg19
'
,
accNo
=
'
NM_002001.2
'
)
assert_equal
(
r
[
'
trans_start
'
],
-
99
)
assert_equal
(
r
[
'
trans_stop
'
],
1066
)
assert_equal
(
r
[
'
CDS_stop
'
],
774
)
def
test_info
(
self
):
"""
Running the info method should give us some version information.
"""
r
=
call
(
'
info
'
)
assert_equal
(
type
(
r
[
'
infoResponse
'
][
'
infoResult
'
][
'
versionParts
'
][
'
string
'
]),
list
)
assert_equal
(
r
[
'
infoResponse
'
][
'
infoResult
'
][
'
version
'
],
mutalyzer
.
__version__
)
def
test_method_get
(
self
):
"""
Using a GET request.
"""
r
=
requests
.
get
(
SERVICE_ROOT
+
'
checkSyntax
'
,
params
=
{
'
variant
'
:
'
AB026906.1:c.274G>T
'
})
assert_equal
(
json
.
loads
(
r
.
content
)[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
valid
'
],
True
)
def
test_method_get_large
(
self
):
"""
Using a GET request with too large data.
"""
r
=
requests
.
get
(
SERVICE_ROOT
+
'
checkSyntax
'
,
params
=
{
'
variant
'
:
'
AB026906.1:c.274G>T
'
,
'
dummy
'
:
'
a
'
*
1000000
})
assert
'
414 Request-URI Too Large
'
in
r
.
content
def
test_method_post_query_string
(
self
):
"""
Using a POST request with query string parameters.
"""
r
=
requests
.
post
(
SERVICE_ROOT
+
'
checkSyntax
'
,
params
=
{
'
variant
'
:
'
AB026906.1:c.274G>T
'
})
assert_equal
(
json
.
loads
(
r
.
content
)[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
valid
'
],
True
)
def
test_method_post_query_string_large
(
self
):
"""
Using a POST request with too large data in body.
"""
r
=
requests
.
post
(
SERVICE_ROOT
+
'
checkSyntax
'
,
params
=
{
'
variant
'
:
'
AB026906.1:c.274G>T
'
,
'
dummy
'
:
'
a
'
*
1000000
})
assert
'
414 Request-URI Too Large
'
in
r
.
content
def
test_method_post_body
(
self
):
"""
Using a POST request with data in body.
"""
r
=
requests
.
post
(
SERVICE_ROOT
+
'
checkSyntax
'
,
data
=
{
'
variant
'
:
'
AB026906.1:c.274G>T
'
})
assert_equal
(
json
.
loads
(
r
.
content
)[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
valid
'
],
True
)
def
test_method_post_body_large
(
self
):
"""
Using a POST request with data in body.
"""
r
=
requests
.
post
(
SERVICE_ROOT
+
'
checkSyntax
'
,
data
=
{
'
variant
'
:
'
AB026906.1:c.274G>T
'
,
'
dummy
'
:
'
a
'
*
1000000
})
assert_equal
(
json
.
loads
(
r
.
content
)[
'
checkSyntaxResponse
'
][
'
checkSyntaxResult
'
][
'
valid
'
],
True
)
r
=
self
.
_call
(
'
info
'
)
assert_equal
(
type
(
r
[
'
versionParts
'
]),
list
)
assert_equal
(
r
[
'
version
'
],
mutalyzer
.
__version__
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment