Skip to content

Commit 2bc6c23

Browse files
author
Kairo de Araujo
committed
Fix lint for tests and tuf services
Fix general linting for tests added and tuf services Signed-off-by: Kairo de Araujo <[email protected]>
1 parent f89328c commit 2bc6c23

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

tests/unit/tuf/test_services.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@
1414
import os
1515
import shutil
1616

17-
from tracemalloc import Snapshot
18-
1917
import pretend
2018
import pytest
2119

2220
from securesystemslib.exceptions import StorageError
2321
from zope.interface.verify import verifyClass
2422

2523
from warehouse.config import Environment
26-
from warehouse.tuf import hash_bins, includeme, services
24+
from warehouse.tuf import services
2725
from warehouse.tuf.constants import BIN_N_COUNT, Role
2826
from warehouse.tuf.hash_bins import HashBins
2927
from warehouse.tuf.interfaces import IKeyService, IRepositoryService, IStorageService
30-
from warehouse.tuf.repository import RolesPayload, TargetsPayload
28+
from warehouse.tuf.repository import TargetsPayload
3129

3230

3331
class TestLocalKeyService:
@@ -131,7 +129,7 @@ def test_get_oserror(self, monkeypatch):
131129
)
132130

133131
with pytest.raises(StorageError) as err:
134-
with service.get("root") as r:
132+
with service.get("root"):
135133
pass
136134

137135
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):
454452
result = service.init_repository()
455453

456454
call_args = fake_metadata_repository.initialize.calls[0].args[0]
457-
assert result == None
455+
assert result is None
458456
assert str(call_args["snapshot"].expiration) == "2019-06-17 09:05:01"
459457
assert str(call_args["timestamp"].expiration) == "2019-06-17 09:05:01"
460458
assert str(call_args["root"].expiration) == "2020-06-15 09:05:01"
@@ -474,18 +472,18 @@ def test_init_repository(self, db_request, monkeypatch):
474472
assert call_args["timestamp"].keys == "fake_key"
475473
assert call_args["root"].keys == "fake_key"
476474
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
489487
for test_call in [
490488
pretend.call(Role.SNAPSHOT.value),
491489
pretend.call(Role.ROOT.value),
@@ -553,7 +551,7 @@ def test_init_targets_delegation(self, db_request, monkeypatch):
553551
result = service.init_targets_delegation()
554552
call_args = fake_metadata_repository.delegate_targets_roles.calls[0].args[0]
555553

556-
assert result == None
554+
assert result is None
557555
assert sorted(["targets", "bins"]) == sorted(list(call_args.keys()))
558556
assert len(call_args["targets"]) == 1
559557
assert call_args["targets"][0].paths == ["*/*", "*/*/*/*"]
@@ -603,7 +601,7 @@ def test_bump_snapshot(self, db_request, monkeypatch):
603601
bump_s_calls = fake_metadata_repository.snapshot_bump_version.calls[0].kwargs
604602
bump_t_calls = fake_metadata_repository.timestamp_bump_version.calls[0].kwargs
605603

606-
assert result == None
604+
assert result is None
607605
assert fake_metadata_repository.load_role.calls == [pretend.call("snapshot")]
608606
assert str(bump_s_calls["snapshot_expires"]) == "2019-06-17 09:05:01"
609607
assert bump_s_calls["snapshot_metadata"].signed.version == 2
@@ -647,7 +645,7 @@ def test_bump_snapshot_specific_snapshot_metadata(self, db_request, monkeypatch)
647645
bump_s_calls = fake_metadata_repository.snapshot_bump_version.calls[0].kwargs
648646
bump_t_calls = fake_metadata_repository.timestamp_bump_version.calls[0].kwargs
649647

650-
assert result == None
648+
assert result is None
651649
assert str(bump_s_calls["snapshot_expires"]) == "2019-06-17 09:05:01"
652650
assert bump_s_calls["snapshot_metadata"].signed.version == 2
653651
assert bump_s_calls["store"] is True
@@ -701,7 +699,7 @@ def test_bump_bin_n_roles(self, db_request, monkeypatch):
701699

702700
result = service.bump_bin_n_roles()
703701

704-
assert result == None
702+
assert result is None
705703
# PEP458 https://peps.python.org/pep-0458/#metadata-scalability
706704
assert len(fake_metadata_repository.bump_role_version.calls) == 16384
707705
assert len(fake_metadata_repository.snapshot_update_meta.calls) == 16384
@@ -747,15 +745,15 @@ def test_add_hashed_targets(self, db_request, monkeypatch):
747745
{
748746
"info": {
749747
"hashes": {"blake2b-256": "dlskjflkdjflsdjfsdfdfsdfsdfs"},
750-
"length": 1024,
748+
"length": 1025,
751749
"custom": {"backsigned": True},
752750
},
753751
"path": "/sd/fa/dlskjflkdjflsdjfsdfdfsdfsdfs.packageyv1.tar.gz",
754752
},
755753
]
756754
result = service.add_hashed_targets(targets)
757755

758-
assert result == None
756+
assert result is None
759757
assert fake_metadata_repository.add_targets.calls == [
760758
pretend.call(
761759
{

tests/unit/tuf/test_tasks.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
import celery
1413
import pretend
15-
import pytest
1614

1715
from warehouse.tuf import tasks
1816
from warehouse.tuf.interfaces import IRepositoryService

warehouse/tuf/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def __init__(self, storage_service, key_service, request):
160160
def create_service(cls, context, request):
161161
"""
162162
Creates a new repository service object configuring services to read and write
163-
TUF role metadata (``IStorageService``) and to read private keys (``IKeyService``).
163+
TUF role metadata (``IStorageService``) and to read private keys
164+
(``IKeyService``).
164165
"""
165166
storage_service = request.find_service(IStorageService)
166167
key_service = request.find_service(IKeyService)

0 commit comments

Comments
 (0)