Skip to content

Commit

Permalink
Merge pull request #294 from aadityasinha-dotcom/context_manager_tests
Browse files Browse the repository at this point in the history
Updated tests to use context managers
  • Loading branch information
t1m0thyj authored Jul 1, 2024
2 parents 90d6e5b + 3514d11 commit be7b36a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/integration/test_zos_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def setUp(self):
"""Setup fixtures for Console class."""
test_profile = ProfileManager(show_warnings=False).load(profile_type="zosmf")
self.console = Console(test_profile)
self.addCleanup(lambda: self.console.__exit__(None, None, None))

def test_console_command_time_should_return_time(self):
"""Test the execution of the time command should return the current time"""
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_zos_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def setUp(self):
with open(FILES_FIXTURES_PATH, "r") as fixtures_json:
self.files_fixtures = json.load(fixtures_json)
self.files = Files(test_profile)
self.addCleanup(lambda: self.files.__exit__(None, None, None))
self.test_member_jcl = f'{self.files_fixtures["TEST_PDS"]}({self.files_fixtures["TEST_MEMBER"]})'
self.test_member_generic = f'{self.files_fixtures["TEST_PDS"]}(TEST)'
self.test_ds_upload = f'{self.files_fixtures["TEST_PDS"]}({self.files_fixtures["TEST_MEMBER_NEW"]})'
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_zos_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self):
with open(JOBS_FIXTURES_JSON_JSON_PATH, "r") as fixtures_json:
self.jobs_fixtures_json = json.load(fixtures_json)
self.jobs = Jobs(test_profile)
self.addCleanup(lambda: self.jobs.__exit__(None, None, None))

def test_get_job_status_should_return_the_status_of_a_job(self):
"""Executing the get_job_status method should return the status of a given job"""
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_zos_tso.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def setUp(self):
"""Setup fixtures for Tso class."""
test_profile = ProfileManager(show_warnings=False).load(profile_type="zosmf")
self.tso = Tso(test_profile, {"account": "IZUACCT"})
self.addCleanup(lambda: self.tso.__exit__(None, None, None))

def test_issue_command_should_return_valid_response(self):
"""Executing the issue_command method should return a valid response from TSO"""
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_zosmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setUp(self):
"""Setup fixtures for Zosmf class."""
test_profile = ProfileManager(show_warnings=False).load(profile_type="zosmf")
self.zosmf = Zosmf(test_profile)
self.addCleanup(lambda: self.zosmf.__exit__(None, None, None))

def test_get_info_should_return_valid_response(self):
"""Executing the get_info method should return a valid response."""
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/core/test_sdk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def test_object_should_be_instance_of_class(self):
"""Created object should be instance of SdkApi class."""
sdk_api = SdkApi(self.basic_props, self.default_url)
self.assertIsInstance(sdk_api, SdkApi)

@mock.patch('requests.Session.close')
def test_context_manager_closes_session(self, mock_close_request):

mock_close_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200)
with SdkApi(self.basic_props, self.default_url) as api:
pass

mock_close_request.assert_called_once()

@mock.patch("logging.Logger.error")
def test_session_no_host_logger(self, mock_logger_error: mock.MagicMock):
Expand Down

0 comments on commit be7b36a

Please sign in to comment.