Removed unused DB-adapters, test cases, 60+% cover
[optf/osdf.git] / test / mainapp / test_osdfapp.py
1 import osdfapp
2 import unittest
3
4 from osdf.operation.exceptions import BusinessException
5 from requests import Request, RequestException
6 from schematics.exceptions import DataError
7 from unittest import mock, TestCase
8 from unittest.mock import patch
9
10
11 class TestOSDFApp(TestCase):
12
13     def setUp(self):
14         self.patcher_g = patch('osdfapp.g', return_value={'request_id':'DUMMY-REQ'})
15         self.Mock_g = self.patcher_g.start()
16         # self.patcher2 = patch('package.module.Class2')
17         # self.MockClass2 = self.patcher2.start()
18
19     def tearDown(self):
20         patch.stopall()
21
22     def dummy_request_exception(self):
23         e = RequestException("Web Request Exception Description")
24         e.response = mock.MagicMock()
25         e.request = Request(method="GET", url="SOME-URL")
26         e.response.status_code = 400
27         e.response.content = "Some request exception occurred"
28         # request().raise_for_status.side_effect = e
29         return e
30  
31     def test_handle_business_exception(self):
32         e = BusinessException("Business Exception Description")
33         resp = osdfapp.handle_business_exception(e)
34         assert resp.status_code == 400
35
36     def test_handle_request_exception(self):
37         e = self.dummy_request_exception()
38         resp = osdfapp.handle_request_exception(e)
39         assert resp.status_code == 400
40
41     def test_handle_data_error(self):
42         e = DataError({"A1": "A1 Data Error"})
43         resp = osdfapp.handle_data_error(e)
44         assert resp.status_code == 400
45
46     def test_internal_failure(self):
47         e = Exception("An Internal Error")
48         resp = osdfapp.internal_failure(e)
49         assert resp.status_code == 500
50
51     def test_getOptions_default(self):
52         opts = osdfapp.getOptions(["PROG"])  # ensure nothing breaks
53
54
55 if __name__ == "__main__":
56     unittest.main()
57