14
14
import os
15
15
import shutil
16
16
17
- from tracemalloc import Snapshot
18
-
19
17
import pretend
20
18
import pytest
21
19
22
20
from securesystemslib .exceptions import StorageError
23
21
from zope .interface .verify import verifyClass
24
22
25
23
from warehouse .config import Environment
26
- from warehouse .tuf import hash_bins , includeme , services
24
+ from warehouse .tuf import services
27
25
from warehouse .tuf .constants import BIN_N_COUNT , Role
28
26
from warehouse .tuf .hash_bins import HashBins
29
27
from warehouse .tuf .interfaces import IKeyService , IRepositoryService , IStorageService
30
- from warehouse .tuf .repository import RolesPayload , TargetsPayload
28
+ from warehouse .tuf .repository import TargetsPayload
31
29
32
30
33
31
class TestLocalKeyService :
@@ -131,7 +129,7 @@ def test_get_oserror(self, monkeypatch):
131
129
)
132
130
133
131
with pytest .raises (StorageError ) as err :
134
- with service .get ("root" ) as r :
132
+ with service .get ("root" ):
135
133
pass
136
134
137
135
assert "Can't open /opt/warehouse/src/dev/metadata/1.root.json" in str (
@@ -454,7 +452,7 @@ def test_init_repository(self, db_request, monkeypatch):
454
452
result = service .init_repository ()
455
453
456
454
call_args = fake_metadata_repository .initialize .calls [0 ].args [0 ]
457
- assert result == None
455
+ assert result is None
458
456
assert str (call_args ["snapshot" ].expiration ) == "2019-06-17 09:05:01"
459
457
assert str (call_args ["timestamp" ].expiration ) == "2019-06-17 09:05:01"
460
458
assert str (call_args ["root" ].expiration ) == "2020-06-15 09:05:01"
@@ -474,18 +472,18 @@ def test_init_repository(self, db_request, monkeypatch):
474
472
assert call_args ["timestamp" ].keys == "fake_key"
475
473
assert call_args ["root" ].keys == "fake_key"
476
474
assert call_args ["targets" ].keys == "fake_key"
477
- assert call_args ["snapshot" ].delegation_role == None
478
- assert call_args ["timestamp" ].delegation_role == None
479
- assert call_args ["root" ].delegation_role == None
480
- assert call_args ["targets" ].delegation_role == None
481
- assert call_args ["snapshot" ].paths == None
482
- assert call_args ["timestamp" ].paths == None
483
- assert call_args ["root" ].paths == None
484
- assert call_args ["targets" ].paths == None
485
- assert call_args ["snapshot" ].path_hash_prefixes == None
486
- assert call_args ["timestamp" ].path_hash_prefixes == None
487
- assert call_args ["root" ].path_hash_prefixes == None
488
- assert call_args ["targets" ].path_hash_prefixes == None
475
+ assert call_args ["snapshot" ].delegation_role is None
476
+ assert call_args ["timestamp" ].delegation_role is None
477
+ assert call_args ["root" ].delegation_role is None
478
+ assert call_args ["targets" ].delegation_role is None
479
+ assert call_args ["snapshot" ].paths is None
480
+ assert call_args ["timestamp" ].paths is None
481
+ assert call_args ["root" ].paths is None
482
+ assert call_args ["targets" ].paths is None
483
+ assert call_args ["snapshot" ].path_hash_prefixes is None
484
+ assert call_args ["timestamp" ].path_hash_prefixes is None
485
+ assert call_args ["root" ].path_hash_prefixes is None
486
+ assert call_args ["targets" ].path_hash_prefixes is None
489
487
for test_call in [
490
488
pretend .call (Role .SNAPSHOT .value ),
491
489
pretend .call (Role .ROOT .value ),
@@ -553,7 +551,7 @@ def test_init_targets_delegation(self, db_request, monkeypatch):
553
551
result = service .init_targets_delegation ()
554
552
call_args = fake_metadata_repository .delegate_targets_roles .calls [0 ].args [0 ]
555
553
556
- assert result == None
554
+ assert result is None
557
555
assert sorted (["targets" , "bins" ]) == sorted (list (call_args .keys ()))
558
556
assert len (call_args ["targets" ]) == 1
559
557
assert call_args ["targets" ][0 ].paths == ["*/*" , "*/*/*/*" ]
@@ -603,7 +601,7 @@ def test_bump_snapshot(self, db_request, monkeypatch):
603
601
bump_s_calls = fake_metadata_repository .snapshot_bump_version .calls [0 ].kwargs
604
602
bump_t_calls = fake_metadata_repository .timestamp_bump_version .calls [0 ].kwargs
605
603
606
- assert result == None
604
+ assert result is None
607
605
assert fake_metadata_repository .load_role .calls == [pretend .call ("snapshot" )]
608
606
assert str (bump_s_calls ["snapshot_expires" ]) == "2019-06-17 09:05:01"
609
607
assert bump_s_calls ["snapshot_metadata" ].signed .version == 2
@@ -647,7 +645,7 @@ def test_bump_snapshot_specific_snapshot_metadata(self, db_request, monkeypatch)
647
645
bump_s_calls = fake_metadata_repository .snapshot_bump_version .calls [0 ].kwargs
648
646
bump_t_calls = fake_metadata_repository .timestamp_bump_version .calls [0 ].kwargs
649
647
650
- assert result == None
648
+ assert result is None
651
649
assert str (bump_s_calls ["snapshot_expires" ]) == "2019-06-17 09:05:01"
652
650
assert bump_s_calls ["snapshot_metadata" ].signed .version == 2
653
651
assert bump_s_calls ["store" ] is True
@@ -701,7 +699,7 @@ def test_bump_bin_n_roles(self, db_request, monkeypatch):
701
699
702
700
result = service .bump_bin_n_roles ()
703
701
704
- assert result == None
702
+ assert result is None
705
703
# PEP458 https://peps.python.org/pep-0458/#metadata-scalability
706
704
assert len (fake_metadata_repository .bump_role_version .calls ) == 16384
707
705
assert len (fake_metadata_repository .snapshot_update_meta .calls ) == 16384
@@ -747,15 +745,15 @@ def test_add_hashed_targets(self, db_request, monkeypatch):
747
745
{
748
746
"info" : {
749
747
"hashes" : {"blake2b-256" : "dlskjflkdjflsdjfsdfdfsdfsdfs" },
750
- "length" : 1024 ,
748
+ "length" : 1025 ,
751
749
"custom" : {"backsigned" : True },
752
750
},
753
751
"path" : "/sd/fa/dlskjflkdjflsdjfsdfdfsdfsdfs.packageyv1.tar.gz" ,
754
752
},
755
753
]
756
754
result = service .add_hashed_targets (targets )
757
755
758
- assert result == None
756
+ assert result is None
759
757
assert fake_metadata_repository .add_targets .calls == [
760
758
pretend .call (
761
759
{
0 commit comments