Skip to content

Commit 20da277

Browse files
committed
Fix/add tests
1 parent 50c2194 commit 20da277

2 files changed

Lines changed: 110 additions & 21 deletions

File tree

dataflow_transfer/tests/test_filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ class TestRsyncIsRunning:
6969
@patch("subprocess.check_output")
7070
def test_rsync_running(self, mock_check_output):
7171
mock_check_output.return_value = b"12345"
72-
assert rsync_is_running("/some/path") is True
72+
assert rsync_is_running("/some/path", "/dst/path") is True
7373

7474
@patch("subprocess.check_output")
7575
def test_rsync_not_running(self, mock_check_output):
7676
mock_check_output.side_effect = CalledProcessError(1, "pgrep")
77-
assert rsync_is_running("/some/path") is False
77+
assert rsync_is_running("/some/path", "/dst/path") is False
7878

7979

8080
class TestSubmitBackgroundProcess:

dataflow_transfer/tests/test_run_classes.py

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def novaseqxplus_testobj(tmp_path):
1212
config = {
1313
"log": {"file": "test.log"},
1414
"transfer_details": {"user": "testuser", "host": "testhost"},
15+
"metadata_archive": "/data/metadata_archive",
1516
"statusdb": {
1617
"username": "dbuser",
1718
"password": "dbpass",
@@ -23,7 +24,12 @@ def novaseqxplus_testobj(tmp_path):
2324
"miarka_destination": "/data/NovaSeqXPlus",
2425
"metadata_for_statusdb": ["RunInfo.xml", "RunParameters.xml"],
2526
"ignore_folders": ["nosync"],
26-
"rsync_options": ["--chmod=Dg+s,g+rw"],
27+
"remote_rsync_options": ["--chmod=Dg+s,g+rw"],
28+
"metadata_rsync_options": [
29+
"--include=RunInfo.xml",
30+
"--include=RunParameters.xml",
31+
"--exclude=*",
32+
],
2733
}
2834
},
2935
}
@@ -38,6 +44,7 @@ def nextseq_testobj(tmp_path):
3844
config = {
3945
"log": {"file": "test.log"},
4046
"transfer_details": {"user": "testuser", "host": "testhost"},
47+
"metadata_archive": "/data/metadata_archive",
4148
"statusdb": {
4249
"username": "dbuser",
4350
"password": "dbpass",
@@ -49,7 +56,12 @@ def nextseq_testobj(tmp_path):
4956
"miarka_destination": "/data/NextSeq",
5057
"metadata_for_statusdb": ["RunInfo.xml", "RunParameters.xml"],
5158
"ignore_folders": ["nosync"],
52-
"rsync_options": ["--chmod=Dg+s,g+rw"],
59+
"remote_rsync_options": ["--chmod=Dg+s,g+rw"],
60+
"metadata_rsync_options": [
61+
"--include=RunInfo.xml",
62+
"--include=RunParameters.xml",
63+
"--exclude=*",
64+
],
5365
}
5466
},
5567
}
@@ -64,6 +76,7 @@ def miseqseq_testobj(tmp_path):
6476
config = {
6577
"log": {"file": "test.log"},
6678
"transfer_details": {"user": "testuser", "host": "testhost"},
79+
"metadata_archive": "/data/metadata_archive",
6780
"statusdb": {
6881
"username": "dbuser",
6982
"password": "dbpass",
@@ -75,7 +88,12 @@ def miseqseq_testobj(tmp_path):
7588
"miarka_destination": "/data/MiSeq",
7689
"metadata_for_statusdb": ["RunInfo.xml", "RunParameters.xml"],
7790
"ignore_folders": ["nosync"],
78-
"rsync_options": ["--chmod=Dg+s,g+rw"],
91+
"remote_rsync_options": ["--chmod=Dg+s,g+rw"],
92+
"metadata_rsync_options": [
93+
"--include=RunInfo.xml",
94+
"--include=RunParameters.xml",
95+
"--exclude=*",
96+
],
7997
}
8098
},
8199
}
@@ -90,6 +108,7 @@ def miseqseqi100_testobj(tmp_path):
90108
config = {
91109
"log": {"file": "test.log"},
92110
"transfer_details": {"user": "testuser", "host": "testhost"},
111+
"metadata_archive": "/data/metadata_archive",
93112
"statusdb": {
94113
"username": "dbuser",
95114
"password": "dbpass",
@@ -101,7 +120,12 @@ def miseqseqi100_testobj(tmp_path):
101120
"miarka_destination": "/data/MiSeqi100",
102121
"metadata_for_statusdb": ["RunInfo.xml", "RunParameters.xml"],
103122
"ignore_folders": ["nosync"],
104-
"rsync_options": ["--chmod=Dg+s,g+rw"],
123+
"remote_rsync_options": ["--chmod=Dg+s,g+rw"],
124+
"metadata_rsync_options": [
125+
"--include=RunInfo.xml",
126+
"--include=RunParameters.xml",
127+
"--exclude=*",
128+
],
105129
}
106130
},
107131
}
@@ -166,27 +190,32 @@ def test_sequencing_ongoing(run_fixture, request):
166190

167191

168192
@pytest.mark.parametrize(
169-
"run_fixture, final_sync",
193+
"run_fixture, remote, with_exit_code_file",
170194
[
171-
("novaseqxplus_testobj", False),
172-
("novaseqxplus_testobj", True),
173-
("nextseq_testobj", False),
174-
("nextseq_testobj", True),
175-
("miseqseq_testobj", False),
176-
("miseqseq_testobj", True),
177-
("miseqseqi100_testobj", False),
178-
("miseqseqi100_testobj", True),
195+
("novaseqxplus_testobj", False, True),
196+
("novaseqxplus_testobj", True, False),
197+
("novaseqxplus_testobj", True, True),
198+
("nextseq_testobj", False, True),
199+
("nextseq_testobj", True, False),
200+
("nextseq_testobj", True, True),
201+
("miseqseq_testobj", False, True),
202+
("miseqseq_testobj", True, False),
203+
("miseqseq_testobj", True, True),
204+
("miseqseqi100_testobj", False, True),
205+
("miseqseqi100_testobj", True, False),
206+
("miseqseqi100_testobj", True, True),
179207
],
180208
)
181-
def test_generate_rsync_command(run_fixture, final_sync, request):
209+
def test_generate_rsync_command(run_fixture, remote, with_exit_code_file, request):
182210
run_obj = request.getfixturevalue(run_fixture)
183-
rsync_command = run_obj.generate_rsync_command(is_final_sync=final_sync)
211+
rsync_command = run_obj.generate_rsync_command(
212+
remote=remote, with_exit_code_file=with_exit_code_file
213+
)
184214
assert "run-one rsync" in rsync_command
185215
assert "--log-file=" in rsync_command
186-
assert "--chmod=Dg+s,g+rw" in rsync_command
187216
assert run_obj.run_dir in rsync_command
188-
if final_sync:
189-
assert f"; echo $? > {run_obj.final_rsync_exitcode_file}" in rsync_command
217+
if with_exit_code_file:
218+
assert "; echo $? >" in rsync_command
190219

191220

192221
@pytest.mark.parametrize(
@@ -213,7 +242,7 @@ def test_generate_rsync_command(run_fixture, final_sync, request):
213242
def test_start_transfer(run_fixture, rsync_running, final, request, monkeypatch):
214243
run_obj = request.getfixturevalue(run_fixture)
215244

216-
def mock_rsync_is_running(src):
245+
def mock_rsync_is_running(src, dst):
217246
return rsync_running
218247

219248
def mock_submit_background_process(command_str):
@@ -270,6 +299,66 @@ def test_final_sync_successful(run_fixture, sync_successful, request):
270299
assert run_obj.final_sync_successful == sync_successful
271300

272301

302+
@pytest.mark.parametrize(
303+
"run_fixture, sync_successful",
304+
[
305+
("novaseqxplus_testobj", True),
306+
("novaseqxplus_testobj", False),
307+
("nextseq_testobj", True),
308+
("nextseq_testobj", False),
309+
("miseqseq_testobj", True),
310+
("miseqseq_testobj", False),
311+
("miseqseqi100_testobj", True),
312+
("miseqseqi100_testobj", False),
313+
],
314+
)
315+
def test_metadata_synced(run_fixture, sync_successful, request):
316+
run_obj = request.getfixturevalue(run_fixture)
317+
if sync_successful:
318+
# Create the final rsync exit code file with a success code
319+
with open(run_obj.metadata_rsync_exitcode_file, "w") as f:
320+
f.write("0")
321+
else:
322+
# Create the final rsync exit code file with a failure code
323+
with open(run_obj.metadata_rsync_exitcode_file, "w") as f:
324+
f.write("1")
325+
assert run_obj.metadata_synced == sync_successful
326+
327+
328+
@pytest.mark.parametrize(
329+
"run_fixture",
330+
[
331+
"novaseqxplus_testobj",
332+
"nextseq_testobj",
333+
"miseqseq_testobj",
334+
"miseqseqi100_testobj",
335+
],
336+
)
337+
def test_sync_metadata(run_fixture, request, monkeypatch):
338+
run_obj = request.getfixturevalue(run_fixture)
339+
340+
def mock_generate_rsync_command(remote, with_exit_code_file):
341+
return "rsync command"
342+
343+
def mock_rsync_is_running(src, dst):
344+
return False
345+
346+
def mock_submit_background_process(command_str):
347+
mock_submit_background_process.called = True
348+
mock_submit_background_process.command_str = command_str
349+
350+
monkeypatch.setattr(run_obj, "generate_rsync_command", mock_generate_rsync_command)
351+
monkeypatch.setattr(generic_runs.fs, "rsync_is_running", mock_rsync_is_running)
352+
monkeypatch.setattr(
353+
generic_runs.fs, "submit_background_process", mock_submit_background_process
354+
)
355+
356+
run_obj.sync_metadata()
357+
358+
assert hasattr(mock_submit_background_process, "called")
359+
assert mock_submit_background_process.command_str == "rsync command"
360+
361+
273362
@pytest.mark.parametrize(
274363
"run_fixture, status_to_check, expected_result",
275364
[

0 commit comments

Comments
 (0)