Skip to content

Commit

Permalink
Fix lint for tests and tuf services
Browse files Browse the repository at this point in the history
Fix general linting for tests added and tuf services

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
  • Loading branch information
Kairo de Araujo committed Mar 30, 2022
1 parent 2d21fdf commit f300b2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
46 changes: 22 additions & 24 deletions tests/unit/tuf/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
import os
import shutil

from tracemalloc import Snapshot

import pretend
import pytest

from securesystemslib.exceptions import StorageError
from zope.interface.verify import verifyClass

from warehouse.config import Environment
from warehouse.tuf import hash_bins, includeme, services
from warehouse.tuf import services
from warehouse.tuf.constants import BIN_N_COUNT, Role
from warehouse.tuf.hash_bins import HashBins
from warehouse.tuf.interfaces import IKeyService, IRepositoryService, IStorageService
from warehouse.tuf.repository import RolesPayload, TargetsPayload
from warehouse.tuf.repository import TargetsPayload


class TestLocalKeyService:
Expand Down Expand Up @@ -131,7 +129,7 @@ def test_get_oserror(self, monkeypatch):
)

with pytest.raises(StorageError) as err:
with service.get("root") as r:
with service.get("root"):
pass

assert "Can't open /opt/warehouse/src/dev/metadata/1.root.json" in str(
Expand Down Expand Up @@ -454,7 +452,7 @@ def test_init_repository(self, db_request, monkeypatch):
result = service.init_repository()

call_args = fake_metadata_repository.initialize.calls[0].args[0]
assert result == None
assert result is None
assert str(call_args["snapshot"].expiration) == "2019-06-17 09:05:01"
assert str(call_args["timestamp"].expiration) == "2019-06-17 09:05:01"
assert str(call_args["root"].expiration) == "2020-06-15 09:05:01"
Expand All @@ -474,18 +472,18 @@ def test_init_repository(self, db_request, monkeypatch):
assert call_args["timestamp"].keys == "fake_key"
assert call_args["root"].keys == "fake_key"
assert call_args["targets"].keys == "fake_key"
assert call_args["snapshot"].delegation_role == None
assert call_args["timestamp"].delegation_role == None
assert call_args["root"].delegation_role == None
assert call_args["targets"].delegation_role == None
assert call_args["snapshot"].paths == None
assert call_args["timestamp"].paths == None
assert call_args["root"].paths == None
assert call_args["targets"].paths == None
assert call_args["snapshot"].path_hash_prefixes == None
assert call_args["timestamp"].path_hash_prefixes == None
assert call_args["root"].path_hash_prefixes == None
assert call_args["targets"].path_hash_prefixes == None
assert call_args["snapshot"].delegation_role is None
assert call_args["timestamp"].delegation_role is None
assert call_args["root"].delegation_role is None
assert call_args["targets"].delegation_role is None
assert call_args["snapshot"].paths is None
assert call_args["timestamp"].paths is None
assert call_args["root"].paths is None
assert call_args["targets"].paths is None
assert call_args["snapshot"].path_hash_prefixes is None
assert call_args["timestamp"].path_hash_prefixes is None
assert call_args["root"].path_hash_prefixes is None
assert call_args["targets"].path_hash_prefixes is None
for test_call in [
pretend.call(Role.SNAPSHOT.value),
pretend.call(Role.ROOT.value),
Expand Down Expand Up @@ -553,7 +551,7 @@ def test_init_targets_delegation(self, db_request, monkeypatch):
result = service.init_targets_delegation()
call_args = fake_metadata_repository.delegate_targets_roles.calls[0].args[0]

assert result == None
assert result is None
assert sorted(["targets", "bins"]) == sorted(list(call_args.keys()))
assert len(call_args["targets"]) == 1
assert call_args["targets"][0].paths == ["*/*", "*/*/*/*"]
Expand Down Expand Up @@ -603,7 +601,7 @@ def test_bump_snapshot(self, db_request, monkeypatch):
bump_s_calls = fake_metadata_repository.snapshot_bump_version.calls[0].kwargs
bump_t_calls = fake_metadata_repository.timestamp_bump_version.calls[0].kwargs

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

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

result = service.bump_bin_n_roles()

assert result == None
assert result is None
# PEP458 https://peps.python.org/pep-0458/#metadata-scalability
assert len(fake_metadata_repository.bump_role_version.calls) == 16384
assert len(fake_metadata_repository.snapshot_update_meta.calls) == 16384
Expand Down Expand Up @@ -747,15 +745,15 @@ def test_add_hashed_targets(self, db_request, monkeypatch):
{
"info": {
"hashes": {"blake2b-256": "dlskjflkdjflsdjfsdfdfsdfsdfs"},
"length": 1024,
"length": 1025,
"custom": {"backsigned": True},
},
"path": "/sd/fa/dlskjflkdjflsdjfsdfdfsdfsdfs.packageyv1.tar.gz",
},
]
result = service.add_hashed_targets(targets)

assert result == None
assert result is None
assert fake_metadata_repository.add_targets.calls == [
pretend.call(
{
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/tuf/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import celery
import pretend
import pytest

from warehouse.tuf import tasks
from warehouse.tuf.interfaces import IRepositoryService
Expand Down
3 changes: 2 additions & 1 deletion warehouse/tuf/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def __init__(self, storage_service, key_service, request):
def create_service(cls, context, request):
"""
Creates a new repository service object configuring services to read and write
TUF role metadata (``IStorageService``) and to read private keys (``IKeyService``).
TUF role metadata (``IStorageService``) and to read private keys
(``IKeyService``).
"""
storage_service = request.find_service(IStorageService)
key_service = request.find_service(IKeyService)
Expand Down

0 comments on commit f300b2f

Please sign in to comment.