Skip to content

Commit

Permalink
fix tests a lil more
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeAeich committed May 13, 2024
1 parent 6c9d1be commit afc0b94
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions tests/test_unit/service/FilerClassTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from unittest.mock import patch


@patch('service.path.HOST_BASE_PATH', '/home/tfga/workspace/cwl-tes')
@patch('service.path.CONTAINER_BASE_PATH', '/transfer')
@patch('service.path.TRANSFER_PVC_NAME', 'transfer-pvc')
@patch('tesk.service.path.HOST_BASE_PATH', '/home/tfga/workspace/cwl-tes')
@patch('tesk.service.path.CONTAINER_BASE_PATH', '/transfer')
@patch('tesk.service.path.TRANSFER_PVC_NAME', 'transfer-pvc')
@patch.dict(
os.environ,
{
Expand Down
10 changes: 5 additions & 5 deletions tests/test_unit/service/TaskMasterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def test_pullPolicyAlways(self):
)

@patch(
'service.taskmaster.args',
'tesk.service.taskmaster.args',
Namespace(debug=True, namespace='default', pull_policy_always=True),
)
@patch('service.taskmaster.logger', newLogger(logging.DEBUG))
@patch('service.taskmaster.PVC.create', pvcCreateMock)
@patch('service.taskmaster.PVC.delete', pvcDeleteMock)
@patch('service.taskmaster.Job.run_to_completion', jobRunToCompletionMock)
@patch('tesk.service.taskmaster.logger', newLogger(logging.DEBUG))
@patch('tesk.service.taskmaster.PVC.create', pvcCreateMock)
@patch('tesk.service.taskmaster.PVC.delete', pvcDeleteMock)
@patch('tesk.service.taskmaster.Job.run_to_completion', jobRunToCompletionMock)
def test_run_task(self):
with open('tests/resources/inputFile.json') as fh:
data = json.load(fh)
Expand Down
24 changes: 12 additions & 12 deletions tests/test_unit/service/test_filer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def stripLines(txt):
return '\n'.join([line.strip() for line in txt.splitlines()[1:]])


@patch('service.path.HOST_BASE_PATH', '/home/tfga/workspace/cwl-tes')
@patch('service.path.CONTAINER_BASE_PATH', '/transfer')
@patch('tesk.service.path.HOST_BASE_PATH', '/home/tfga/workspace/cwl-tes')
@patch('tesk.service.path.CONTAINER_BASE_PATH', '/transfer')
class FilerTest(unittest.TestCase, AssertThrowsMixin):
@classmethod
def setUpClass(cls):
logConfig(logging.DEBUG) # Doesn't work...

@patch('service.filer.copyDir')
@patch('service.filer.shutil.copy')
@patch('tesk.service.filer.copyDir')
@patch('tesk.service.filer.shutil.copy')
def test_download_file(self, copyMock, copyDirMock):
filedata = {
'url': 'file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/md5',
Expand All @@ -69,8 +69,8 @@ def test_download_file(self, copyMock, copyDirMock):
'/var/lib/cwl/stgda974802-fa81-4f0b-' '8fe4-341d5655af4b/md5',
)

@patch('service.filer.copyDir')
@patch('service.filer.shutil.copy')
@patch('tesk.service.filer.copyDir')
@patch('tesk.service.filer.shutil.copy')
def test_download_dir(self, copyMock, copyDirMock):
filedata = {
'url': 'file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/',
Expand All @@ -85,8 +85,8 @@ def test_download_dir(self, copyMock, copyDirMock):

copyDirMock.assert_called_once_with('/transfer/tmphrtip1o8', '/TclSZU')

@patch('service.filer.copyDir')
@patch('service.filer.shutil.copy')
@patch('tesk.service.filer.copyDir')
@patch('tesk.service.filer.shutil.copy')
def test_upload_dir(self, copyMock, copyDirMock):
filedata = {
'url': 'file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/',
Expand All @@ -101,8 +101,8 @@ def test_upload_dir(self, copyMock, copyDirMock):

copyDirMock.assert_called_once_with('/TclSZU', '/transfer/tmphrtip1o8')

@patch('service.filer.copyDir')
@patch('service.filer.copyFile')
@patch('tesk.service.filer.copyDir')
@patch('tesk.service.filer.copyFile')
def test_upload_file(self, copyFileMock, copyDirMock):
filedata = {
'url': 'file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/md5',
Expand All @@ -117,8 +117,8 @@ def test_upload_file(self, copyFileMock, copyDirMock):

copyFileMock.assert_called_once_with('/TclSZU/md5', '/transfer/tmphrtip1o8/md5')

@patch('service.filer.copyDir')
@patch('service.filer.copyFile')
@patch('tesk.service.filer.copyDir')
@patch('tesk.service.filer.copyFile')
def test_upload_file_glob(self, copyFileMock, copyDirMock):
filedata = {
'url': 'file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/md5*',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unit/service/test_filer_general_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_process_file_with_scheme(mocker):
'path': '.',
'type': 'FILE',
}
mock_new_Trans = mocker.patch('service.filer.newTransput')
mock_new_Trans = mocker.patch('tesk.service.filer.newTransput')
process_file('inputs', filedata)

mock_new_Trans.assert_called_once_with('http', 'www.foo.bar')
Expand Down
16 changes: 8 additions & 8 deletions tests/test_unit/service/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_job(self):

@patch('kubernetes.client.BatchV1Api.create_namespaced_job')
@patch(
'service.job.Job.get_status',
'tesk.service.job.Job.get_status',
side_effect=[
('Running', True),
('Running', True),
Expand All @@ -237,10 +237,10 @@ def test_run_to_completion_success(
)
self.assertEqual(status, 'Complete')

@patch('service.job.Job.delete')
@patch('service.taskmaster.check_cancelled', return_value=True)
@patch('tesk.service.job.Job.delete')
@patch('tesk.service.taskmaster.check_cancelled', return_value=True)
@patch('kubernetes.client.BatchV1Api.create_namespaced_job')
@patch('service.job.Job.get_status', side_effect=[('Running', True)])
@patch('tesk.service.job.Job.get_status', side_effect=[('Running', True)])
def test_run_to_completion_cancelled(
self,
mock_get_status,
Expand All @@ -261,12 +261,12 @@ def test_run_to_completion_cancelled(
)
self.assertEqual(status, 'Cancelled')

@patch('service.taskmaster.check_cancelled', return_value=False)
@patch('tesk.service.taskmaster.check_cancelled', return_value=False)
@patch(
'kubernetes.client.BatchV1Api.create_namespaced_job',
side_effect=ApiException(status=409, reason='conflict'),
)
@patch('service.job.Job.get_status', side_effect=[('Complete', True)])
@patch('tesk.service.job.Job.get_status', side_effect=[('Complete', True)])
@patch(
'kubernetes.client.BatchV1Api.read_namespaced_job',
side_effect=read_namespaced_job_running,
Expand Down Expand Up @@ -317,8 +317,8 @@ def test_run_to_completion_check_other_K8_exception(
'kubernetes.client.BatchV1Api.read_namespaced_job',
side_effect=read_namespaced_job_error,
)
@patch('service.job.Job.delete')
@patch('service.taskmaster.check_cancelled', return_value=False)
@patch('tesk.service.job.Job.delete')
@patch('tesk.service.taskmaster.check_cancelled', return_value=False)
@patch('kubernetes.client.BatchV1Api.create_namespaced_job')
def test_run_to_completion_error( # noqa: PLR0913
self,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_unit/service/test_s3_filer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import boto3
import pytest

# from service.extract_endpoint import extract_endpoint
# from tesk.service.extract_endpoint import extract_endpoint
from moto import mock_aws

from tesk.service.filer_s3 import S3Transput
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_check_if_bucket_exists(moto_boto, path, url, ftype, expected):
assert trans.check_if_bucket_exists(client) == expected


# @patch('service.filer.os.makedirs')
# @patch('tesk.service.filer.os.makedirs')
# @patch('builtins.open')
# @patch('s3transfer.utils.OSUtils.rename_file')
@pytest.mark.parametrize(
Expand All @@ -89,10 +89,10 @@ def test_s3_download_file(moto_boto, path, url, ftype, expected, fs, caplog): #
assert os.path.exists(path) is True


@patch('service.filer.os.makedirs')
@patch('tesk.service.filer.os.makedirs')
@patch('builtins.open')
@patch('s3transfer.utils.OSUtils.rename_file')
# @patch("service.filer_s3.extract_endpoint", return_value="http://s3.amazonaws.com")
# @patch("tesk.service.filer_s3.extract_endpoint", return_value="http://s3.amazonaws.com")
@pytest.mark.parametrize(
'path, url, ftype,expected',
[
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_upload_directory_for_unknown_file_type(moto_boto, fs, monkeypatch, capl
assert 'Object is neither file or directory' in caplog.text


@patch('service.filer.os.path.exists', return_value=1)
@patch('tesk.service.filer.os.path.exists', return_value=1)
def test_extract_url_from_config_file(mock_path_exists):
"""
Testing extraction of endpoint url from default file location
Expand Down
40 changes: 20 additions & 20 deletions tests/test_unit/service/test_taskmaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def setUp(self):

taskmaster.created_jobs = []

@patch('service.taskmaster.PVC.create')
@patch('service.taskmaster.Job.run_to_completion', return_value='Complete')
@patch('service.taskmaster.logger')
@patch('tesk.service.taskmaster.PVC.create')
@patch('tesk.service.taskmaster.Job.run_to_completion', return_value='Complete')
@patch('tesk.service.taskmaster.logger')
def test_pvc_creation(self, mock_logger, mock_run_to_compl, mock_pvc_create):
"""
Testing to check if the PVC volume was created successfully
Expand All @@ -86,10 +86,10 @@ def test_create_pvc_check_for_other_exceptions(self, mock_create_namespaced_pvc)
with self.assertRaises(ApiException):
self.pvc.create()

@patch('service.taskmaster.PVC.delete')
@patch('service.taskmaster.PVC.create')
@patch('service.taskmaster.Job.run_to_completion', return_value='error')
@patch('service.taskmaster.logger')
@patch('tesk.service.taskmaster.PVC.delete')
@patch('tesk.service.taskmaster.PVC.create')
@patch('tesk.service.taskmaster.Job.run_to_completion', return_value='error')
@patch('tesk.service.taskmaster.logger')
def test_pvc_failure(
self, mock_logger, run_to_compl, mock_pvc_create, mock_pvc_delete
):
Expand All @@ -99,10 +99,10 @@ def test_pvc_failure(

self.assertRaises(SystemExit, init_pvc, self.data, self.filer)

@patch('service.taskmaster.PVC.delete')
@patch('service.taskmaster.Job.delete')
@patch('service.taskmaster.Job.run_to_completion', return_value='Error')
@patch('service.taskmaster.logger')
@patch('tesk.service.taskmaster.PVC.delete')
@patch('tesk.service.taskmaster.Job.delete')
@patch('tesk.service.taskmaster.Job.run_to_completion', return_value='Error')
@patch('tesk.service.taskmaster.logger')
def test_run_executor_failure(
self, mock_logger, mock_run_to_compl, mock_job_delete, mock_pvc_delete
):
Expand All @@ -114,9 +114,9 @@ def test_run_executor_failure(
taskmaster.args.namespace,
)

@patch('service.taskmaster.PVC')
@patch('service.taskmaster.Job.run_to_completion', return_value='Complete')
@patch('service.taskmaster.logger')
@patch('tesk.service.taskmaster.PVC')
@patch('tesk.service.taskmaster.Job.run_to_completion', return_value='Complete')
@patch('tesk.service.taskmaster.logger')
def test_run_executor_complete(self, mock_logger, mock_run_to_compl, mock_pvc):
""" """
self.assertEqual(
Expand All @@ -126,12 +126,12 @@ def test_run_executor_complete(self, mock_logger, mock_run_to_compl, mock_pvc):
None,
)

@patch('service.taskmaster.logger')
@patch('tesk.service.taskmaster.logger')
def test_generate_mount(self, mock_logger):
""" """
self.assertIsInstance(generate_mounts(self.data, self.pvc), list)

@patch('service.taskmaster.logger')
@patch('tesk.service.taskmaster.logger')
def test_append_mount(self, mock_logger):
""" """
volume_mounts = []
Expand All @@ -150,10 +150,10 @@ def test_append_mount(self, mock_logger):
],
)

@patch('service.taskmaster.logger')
@patch('service.taskmaster.PVC.create')
@patch('service.taskmaster.PVC.delete')
@patch('service.taskmaster.Job.run_to_completion', return_value='Complete')
@patch('tesk.service.taskmaster.logger')
@patch('tesk.service.taskmaster.PVC.create')
@patch('tesk.service.taskmaster.PVC.delete')
@patch('tesk.service.taskmaster.Job.run_to_completion', return_value='Complete')
def test_run_task(self, mock_job, mock_pvc_create, mock_pvc_delete, mock_logger):
""" """
run_task(self.data, taskmaster.args.filer_name, taskmaster.args.filer_version)
Expand Down

0 comments on commit afc0b94

Please sign in to comment.