diff options
author | Sastry Isukapalli <sastry@research.att.com> | 2018-02-11 21:09:32 -0500 |
---|---|---|
committer | Sastry Isukapalli <sastry@research.att.com> | 2018-02-11 21:16:26 -0500 |
commit | 2d2ac618f8538fe243c292540fedfbf45e19b118 (patch) | |
tree | f8dbb42efb35d7e79a56978dfbd2e2cb03cbe0e0 /test/mainapp | |
parent | 0b855c08fd98fb8fa0f4bc40d8df430c897b4bad (diff) |
Removed unused DB-adapters, test cases, 60+% cover
We are not using OracleDB, PostgresDB, and VerticaDB, so there is no
need to keep the "dead code" -- we can always add it back as needed.
Added test cases so that all the files are at least minimally covered.
Overall coverage on my local tox shows 66% coverage (I manually ensured
all files are included in the coverage report).
Issue-ID: OPTFRA-95
Change-Id: If1cab112236b4f32a96315308ce815088fa092d1
Signed-off-by: Sastry Isukapalli <sastry@research.att.com>
Diffstat (limited to 'test/mainapp')
-rw-r--r-- | test/mainapp/test_osdfapp.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/mainapp/test_osdfapp.py b/test/mainapp/test_osdfapp.py new file mode 100644 index 0000000..2ffe4f3 --- /dev/null +++ b/test/mainapp/test_osdfapp.py @@ -0,0 +1,57 @@ +import osdfapp +import unittest + +from osdf.operation.exceptions import BusinessException +from requests import Request, RequestException +from schematics.exceptions import DataError +from unittest import mock, TestCase +from unittest.mock import patch + + +class TestOSDFApp(TestCase): + + def setUp(self): + self.patcher_g = patch('osdfapp.g', return_value={'request_id':'DUMMY-REQ'}) + self.Mock_g = self.patcher_g.start() + # self.patcher2 = patch('package.module.Class2') + # self.MockClass2 = self.patcher2.start() + + def tearDown(self): + patch.stopall() + + def dummy_request_exception(self): + e = RequestException("Web Request Exception Description") + e.response = mock.MagicMock() + e.request = Request(method="GET", url="SOME-URL") + e.response.status_code = 400 + e.response.content = "Some request exception occurred" + # request().raise_for_status.side_effect = e + return e + + def test_handle_business_exception(self): + e = BusinessException("Business Exception Description") + resp = osdfapp.handle_business_exception(e) + assert resp.status_code == 400 + + def test_handle_request_exception(self): + e = self.dummy_request_exception() + resp = osdfapp.handle_request_exception(e) + assert resp.status_code == 400 + + def test_handle_data_error(self): + e = DataError({"A1": "A1 Data Error"}) + resp = osdfapp.handle_data_error(e) + assert resp.status_code == 400 + + def test_internal_failure(self): + e = Exception("An Internal Error") + resp = osdfapp.internal_failure(e) + assert resp.status_code == 500 + + def test_getOptions_default(self): + opts = osdfapp.getOptions(["PROG"]) # ensure nothing breaks + + +if __name__ == "__main__": + unittest.main() + |