From a55cbabaef4975d5007363e59d4560cb30a855e3 Mon Sep 17 00:00:00 2001 From: vrvarma Date: Thu, 17 Sep 2020 02:24:00 -0400 Subject: Fix osdf code after upgrading to py38 Fix osdf logging to work with 3.8 Fix osdf code that broke after migration Fix test cases after migration Fixing pep8 violations Change-Id: I11ca33959882c8b9010f00ff744d59c7eeb3c2f2 Signed-off-by: vrvarma Issue-ID: OPTFRA-796 --- test/mainapp/test_osdfapp.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'test/mainapp') diff --git a/test/mainapp/test_osdfapp.py b/test/mainapp/test_osdfapp.py index d1f6d7e..e4f12e6 100644 --- a/test/mainapp/test_osdfapp.py +++ b/test/mainapp/test_osdfapp.py @@ -17,20 +17,25 @@ # import unittest +from unittest import TestCase +from unittest import mock +from unittest.mock import patch + +from requests import Request +from requests import RequestException +from schematics.exceptions import DataError from osdf.apps import baseapp +from osdf.apps.baseapp import app 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('osdf.apps.baseapp.g', return_value={'request_id':'DUMMY-REQ'}) - self.Mock_g = self.patcher_g.start() + with app.app_context(): + self.patcher_g = patch('osdf.apps.baseapp.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() @@ -45,7 +50,7 @@ class TestOSDFApp(TestCase): 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 = baseapp.handle_business_exception(e) @@ -67,9 +72,8 @@ class TestOSDFApp(TestCase): assert resp.status_code == 500 def test_get_options_default(self): - opts = baseapp.get_options(["PROG"]) # ensure nothing breaks + baseapp.get_options(["PROG"]) # ensure nothing breaks if __name__ == "__main__": unittest.main() - -- cgit 1.2.3-korg