commit 417e64893fa21a9ca1b9e66efa812d784a128731 Author: Arturo Filastò arturo@filasto.net Date: Tue Sep 6 16:08:27 2016 +0200
Add simple unittest for api_status --- .coveragerc | 2 +- ooni/tests/test_wui_server.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/.coveragerc b/.coveragerc index 34ed07c..4f5cfba 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,4 @@ [run] source = ooni [report] -omit = ooni/nettests/*, ooni/api/*, ooni/kit/* +omit = ooni/nettests/*, ooni/api/*, ooni/kit/*, ooni/contrib/* diff --git a/ooni/tests/test_wui_server.py b/ooni/tests/test_wui_server.py new file mode 100644 index 0000000..ebaaacd --- /dev/null +++ b/ooni/tests/test_wui_server.py @@ -0,0 +1,32 @@ +from __future__ import print_function + +import json + +from .bases import ConfigTestCase +from ooni.ui.web.server import WebUIAPI + +from mock import patch, Mock + +class TestWebUIServer(ConfigTestCase): + def setUp(self): + super(TestWebUIServer, self).setUp() + + director = Mock() + scheduler = Mock() + + self.wui_api = WebUIAPI(self.config, director, scheduler) + + def tearDown(self): + super(TestWebUIServer, self).tearDown() + self.wui_api.status_poller.stop() + self.wui_api.director_event_poller.stop() + + def test_api_status(self): + request = Mock() + resp = self.wui_api.api_status(request) + j = json.loads(resp) + expected_keys = ["software_version", "software_name", "asn", + "country_code", "director_started", "initialized", + "quota_warning"] + for key in expected_keys: + self.assertTrue(key in j)