From 0ae9dde3c849198165b5f2e07024e4799c2db354 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Tue, 29 May 2012 14:10:54 +0000
Subject: [PATCH] Add HTTP/RPC+JSON unit tests

git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/rpclib-branch@541 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 tests/test_services_json.py                   | 68 +++++++++++++++++++
 ...st_webservice.py => test_services_soap.py} |  3 +-
 2 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 tests/test_services_json.py
 rename tests/{test_webservice.py => test_services_soap.py} (99%)

diff --git a/tests/test_services_json.py b/tests/test_services_json.py
new file mode 100644
index 00000000..6055a185
--- /dev/null
+++ b/tests/test_services_json.py
@@ -0,0 +1,68 @@
+"""
+Tests for the SOAP interface to Mutalyzer.
+"""
+
+
+from urllib import urlencode
+import simplejson as json
+import requests
+from nose.tools import *
+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)
+
+
+class TestServicesJson():
+    """
+    Test the Mutalyzer HTTP/RPC+JSON interface.
+    """
+    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['CheckSyntaxOutput']['valid'], True)
+
+    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['CheckSyntaxOutput']['valid'], False)
+        assert len(r['CheckSyntaxOutput']['messages']['SoapMessage']) >= 1
+
+    def test_checksyntax_empty(self):
+        """
+        Running checkSyntax with no variant name should raise exception.
+        """
+        r = call('checkSyntax')
+        assert r['Fault']
+
+    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['Transcript']['trans_start'], -99)
+        assert_equal(r['Transcript']['trans_stop'], 1066)
+        assert_equal(r['Transcript']['CDS_stop'], 774)
+
+    def test_info(self):
+        """
+        Running the info method should give us some version information.
+        """
+        r = call('info')
+        assert_equal(type(r['InfoOutput']['versionParts']['string']), list)
+        assert_equal(r['InfoOutput']['version'], mutalyzer.__version__)
diff --git a/tests/test_webservice.py b/tests/test_services_soap.py
similarity index 99%
rename from tests/test_webservice.py
rename to tests/test_services_soap.py
index 8dabe7b3..0fdbec9a 100644
--- a/tests/test_webservice.py
+++ b/tests/test_services_soap.py
@@ -46,11 +46,10 @@ class TestWSDL():
         assert 'name="Mutalyzer"' in wsdl
 
 
-class TestWebservice():
+class TestServicesSoap():
     """
     Test the Mutalyzer SOAP interface.
     """
-
     def setUp(self):
         """
         Initialize webservice entrypoint.
-- 
GitLab