Skip to content

Commit dfc5104

Browse files
committed
Remove the "SIGNED_COMMON" constant and f-strings
Signed-off-by: Martin Vrachev <[email protected]>
1 parent a774091 commit dfc5104

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

tests/test_metadata_serialization.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ def wrapper(test_cls: "TestSerialization"):
5050

5151
class TestSerialization(unittest.TestCase):
5252

53-
SIGNED_COMMON = '"spec_version": "1.0.0", "version": 1, \
54-
"expires": "2030-01-01T00:00:00Z"'
55-
5653
valid_keys: DataSet = {
5754
"all": '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
5855
"keyval": {"public": "foo"}}',
@@ -77,14 +74,16 @@ def test_role_serialization(self, test_case_data: str):
7774

7875

7976
valid_roots: DataSet = {
80-
"all": f'{{ "_type": "root", {SIGNED_COMMON}, "consistent_snapshot": false, \
81-
"keys": {{"keyid" : {{"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }} }}, \
82-
"roles": {{ "targets": {{"keyids": ["keyid"], "threshold": 3}} }} \
83-
}}',
84-
"no consistent_snapshot": f'{{ "_type": "root", {SIGNED_COMMON}, \
85-
"keys": {{"keyid" : {{"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }}}}, \
86-
"roles": {{ "targets": {{"keyids": ["keyid"], "threshold": 3}} }} \
87-
}}',
77+
"all": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
78+
"expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
79+
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
80+
"roles": { "targets": {"keyids": ["keyid"], "threshold": 3}} \
81+
}',
82+
"no consistent_snapshot": '{ "_type": "root", "spec_version": "1.0.0", "version": 1, \
83+
"expires": "2030-01-01T00:00:00Z", \
84+
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
85+
"roles": { "targets": {"keyids": ["keyid"], "threshold": 3} } \
86+
}',
8887
}
8988

9089
@run_sub_tests_with_dataset(valid_roots)
@@ -107,9 +106,8 @@ def test_metafile_serialization(self, test_case_data: str):
107106

108107

109108
valid_timestamps: DataSet = {
110-
"all": f'{{ "_type": "timestamp", {SIGNED_COMMON}, \
111-
"meta": {{ "snapshot.json": {{ "hashes": {{"sha256" : "abc"}}, "version": 1 }} }} \
112-
}}'
109+
"all": '{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
110+
"meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}}'
113111
}
114112

115113
@run_sub_tests_with_dataset(valid_timestamps)
@@ -120,9 +118,8 @@ def test_timestamp_serialization(self, test_case_data: str):
120118

121119

122120
valid_snapshots: DataSet = {
123-
"all": f'{{ "_type": "snapshot", {SIGNED_COMMON}, \
124-
"meta": {{ "file.txt": \
125-
{{ "hashes": {{"sha256" : "abc"}}, "version": 1 }} }} }}'
121+
"all": '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
122+
"meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}}'
126123
}
127124

128125
@run_sub_tests_with_dataset(valid_snapshots)
@@ -176,21 +173,21 @@ def test_targetfile_serialization(self, test_case_data: str):
176173

177174

178175
valid_targets: DataSet = {
179-
"all attributes": f'{{"_type": "targets", {SIGNED_COMMON}, \
180-
"targets": {{ "file.txt": {{"length": 12, "hashes": {{"sha256" : "abc"}} }} }}, \
181-
"delegations": {{"keys": {{"keyid" : {{"keytype": "rsa", \
182-
"scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }}}}, \
183-
"roles": [ {{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}} ]}} \
184-
}}',
185-
"empty targets": f'{{"_type": "targets", {SIGNED_COMMON}, \
186-
"targets": {{}}, \
187-
"delegations": {{"keys": {{"keyid" : {{"keytype": "rsa", \
188-
"scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }}}}, \
189-
"roles": [ {{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}} ]}} \
190-
}}',
191-
"no delegations": f'{{"_type": "targets", {SIGNED_COMMON}, \
192-
"targets": {{ "file.txt": {{"length": 12, "hashes": {{"sha256" : "abc"}} }} }} \
193-
}}'
176+
"all attributes": '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
177+
"targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } }, \
178+
"delegations": {"keys": {"keyid" : {"keytype": "rsa", \
179+
"scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
180+
"roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]} \
181+
}',
182+
"empty targets": '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
183+
"targets": {}, \
184+
"delegations": {"keys": {"keyid" : {"keytype": "rsa", \
185+
"scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
186+
"roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]} \
187+
}',
188+
"no delegations": '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
189+
"targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } } \
190+
}'
194191
}
195192

196193
@run_sub_tests_with_dataset(valid_targets)

0 commit comments

Comments
 (0)