Skip to content

Commit fa79bf4

Browse files
test: add extra test cases for create_secret_data
1 parent 7980622 commit fa79bf4

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

tests/unit/test_secrets.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@
1111
from juju.secrets import create_secret_data, read_secret_data
1212

1313

14-
class TestCreateSecretData(unittest.TestCase):
15-
def test_bad_key(self):
14+
class TestCreateSecretData:
15+
@pytest.mark.parametrize("keyval", ["foo", "=bar", "baz=", "f=bar", "fo=bar", "foo_bar=baz"])
16+
def test_bad_key(self, keyval: str):
1617
with pytest.raises(ValueError):
17-
create_secret_data(["foo"])
18-
with pytest.raises(ValueError):
19-
create_secret_data(["=bar"])
18+
create_secret_data([keyval])
19+
20+
21+
@pytest.mark.parametrize(
22+
"keyval,expected_key,expected_val",
23+
[
24+
("foo=bar", "foo", "YmFy"),
25+
("hello=world", "hello", "d29ybGQ="),
26+
("goodbye#base64=world", "goodbye", "world"),
27+
("equalsign==", "equalsign", "PQ=="),
28+
("equalsign#base64=PQ==", "equalsign", "PQ=="),
29+
("pq-identity-theorem=P===Q", "pq-identity-theorem", "UD09PVE="),
30+
]
31+
)
32+
def test_goo_key_values(self, keyval: str, expected_key: str, expected_val: str):
33+
actual = create_secret_data([keyval])
34+
expected = {expected_key: expected_val}
35+
assert actual == expected
2036

21-
def test_good_key_values(self):
22-
self.assertDictEqual(
23-
create_secret_data(["foo=bar", "hello=world", "goodbye#base64=world"]),
24-
{"foo": "YmFy", "hello": "d29ybGQ=", "goodbye": "world"},
25-
)
2637

2738
def test_key_content_too_large(self):
2839
with pytest.raises(ValueError):
@@ -50,15 +61,12 @@ def test_secret_key_from_file(self):
5061

5162
data = create_secret_data(["key1=value1", f"key2#file={file_path}"])
5263

53-
self.assertDictEqual(
54-
data,
55-
{
56-
"key1": "dmFsdWUx",
57-
"key2": (
58-
"ICAgICAgICAgIC0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQogICAgICAgICAgTUlJRllqQ0NBMHFnQXdJQkFnSVFLYVBORDlZZ2dJRzYrak9jZ21wazNEQU5CZ2txaGtpRzl3MEJBUXNGQURBegogICAgICAgICAgTVJ3d0dnWURWUVFLRXhOc2FXNTFlR052Ym5SaGFXNWxjbk11YjNKbk1STXdFUVlEVlFRRERBcDBhVzFBWld4MwogICAgICAgICAgLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ=="
59-
),
60-
},
61-
)
64+
assert data == {
65+
"key1": "dmFsdWUx",
66+
"key2": (
67+
"ICAgICAgICAgIC0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQogICAgICAgICAgTUlJRllqQ0NBMHFnQXdJQkFnSVFLYVBORDlZZ2dJRzYrak9jZ21wazNEQU5CZ2txaGtpRzl3MEJBUXNGQURBegogICAgICAgICAgTVJ3d0dnWURWUVFLRXhOc2FXNTFlR052Ym5SaGFXNWxjbk11YjNKbk1STXdFUVlEVlFRRERBcDBhVzFBWld4MwogICAgICAgICAgLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ=="
68+
),
69+
}
6270

6371

6472
class TestReadSecretData(unittest.TestCase):

0 commit comments

Comments
 (0)