Skip to content

Commit 64718b5

Browse files
committed
Add tests for s3/__main__.py
1 parent 27c9937 commit 64718b5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/s3/test_main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
from unittest.mock import patch, MagicMock
3+
4+
import pytest
5+
6+
import gardenlinux.s3.__main__ as s3m
7+
8+
9+
@pytest.mark.parametrize(
10+
"argv,expected_method",
11+
[
12+
(
13+
[
14+
"__main__.py",
15+
"--bucket",
16+
"test-bucket",
17+
"--cname",
18+
"test-cname",
19+
"--path",
20+
"some/path",
21+
"download-artifacts-from-bucket",
22+
],
23+
"download_to_directory",
24+
),
25+
(
26+
[
27+
"__main__.py",
28+
"--bucket",
29+
"test-bucket",
30+
"--cname",
31+
"test-cname",
32+
"--path",
33+
"some/path",
34+
"upload-artifacts-to-bucket",
35+
],
36+
"upload_from_directory",
37+
),
38+
],
39+
)
40+
def test_main_calls_correct_artifacts(argv, expected_method):
41+
with patch.object(sys, "argv", argv):
42+
with patch.object(s3m, "S3Artifacts") as mock_s3_cls:
43+
mock_instance = MagicMock()
44+
mock_s3_cls.return_value = mock_instance
45+
46+
s3m.main()
47+
48+
method = getattr(mock_instance, expected_method)
49+
method.assert_called_once_with("test-cname", "some/path")
50+
51+
mock_s3_cls.assert_called_once_with("test-bucket")

0 commit comments

Comments
 (0)