From 425b56d66df005f7d8fefb83d4c261c409e0f8f6 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Fri, 24 Apr 2020 09:22:35 +0000 Subject: [PATCH] new test for otrs exports --- test/test_ims_worker.py | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/test_ims_worker.py diff --git a/test/test_ims_worker.py b/test/test_ims_worker.py new file mode 100644 index 00000000..1dfc8f2a --- /dev/null +++ b/test/test_ims_worker.py @@ -0,0 +1,43 @@ +import os +import re + +from inventory_provider.tasks.ims_worker import export_data_for_otrs, OTRSFiles + + +def test_otrs_exports(data_config_filename, data_config, mocker): + os.environ['INVENTORY_PROVIDER_CONFIG_FILENAME'] = data_config_filename + otrs_config = data_config["otrs-export"] + mocked_writer = \ + mocker.patch('inventory_provider.tasks.ims_worker.csv.writer') + mocked_row_writer = mocked_writer.return_value.writerows + mocked_run = mocker.patch( + 'inventory_provider.tasks.ims_worker.subprocess.run') + mocker.patch( + 'inventory_provider.tasks.ims_worker.ims_data.otrs_get_customer_company_rows', # noqa + return_value=[[1, 2, 3, 4], [5, 6, 7, 8]] + ) + mocker.patch( + 'inventory_provider.tasks.ims_worker.ims_data.otrs_get_customer_users_rows', # noqa + return_value=[[9, 10, 11, 12], [13, 14, 15, 16]] + ) + + export_data_for_otrs(OTRSFiles.CUSTOMER_COMPANIES) + mocked_row_writer.assert_called_with([[1, 2, 3, 4], [5, 6, 7, 8]]) + + export_data_for_otrs(OTRSFiles.CUSTOMER_USERS) + mocked_row_writer.assert_called_with([[9, 10, 11, 12], [13, 14, 15, 16]]) + + export_data_for_otrs() + assert mocked_row_writer.call_count == 4 + + args, kwargs = mocked_run.call_args + called_with = args[0] + + t = 'rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file}" .+\\/\\* {destination}' # noqa + + p = t.format( + user=otrs_config['username'], + key_file=otrs_config['private-key'], + destination=otrs_config['destination']) + + assert re.match(p, called_with) -- GitLab