Skip to content

Commit

Permalink
Apply changes to mitigate mypy reported errors:
Browse files Browse the repository at this point in the history
* Incompatible type assignments
* Incompatible types for arguments
* Incompatible return values
  • Loading branch information
xaoc7 authored and jdelic committed Aug 13, 2024
1 parent 3112113 commit 41c580d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 70 deletions.
42 changes: 21 additions & 21 deletions aptly_api/parts/mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import NamedTuple, Sequence, Dict, cast, Optional, List
from typing import NamedTuple, Sequence, Dict, cast, Optional, List, Union
from urllib.parse import quote

from aptly_api.base import BaseAPIClient
from aptly_api.parts.packages import Package, PackageAPISection


Mirror = NamedTuple('Mirror', [
('uuid', str),
('uuid', Optional[str]),
('name', str),
('archiveurl', str),
('distribution', str),
('components', Sequence[str]),
('architectures', Sequence[str]),
('meta', Sequence[Dict[str, str]]),
('downloaddate', str),
('filter', str),
('status', int),
('worker_pid', int),
('distribution', Optional[str]),
('components', Optional[Sequence[str]]),
('architectures', Optional[Sequence[str]]),
('meta', Optional[Sequence[Dict[str, str]]]),
('downloaddate', Optional[str]),
('filter', Optional[str]),
('status', Optional[int]),
('worker_pid', Optional[int]),
('filter_with_deps', bool),
('skip_component_check', bool),
('skip_architecture_check', bool),
Expand All @@ -30,6 +30,9 @@
('download_installer', bool)
])

T_BodyDict = Dict[str, Union[str, bool, Sequence[Dict[str, str]],
Sequence[str], Dict[str, Union[bool, str]]]]


class MirrorsAPISection(BaseAPIClient):
@staticmethod
Expand Down Expand Up @@ -79,22 +82,21 @@ def list(self) -> Sequence[Mirror]:
)
return mirrors

def update(self, name: str, ignore_signatures: bool = False) -> Sequence[Mirror]:
def update(self, name: str, ignore_signatures: bool = False) -> None:
body = {}
if ignore_signatures:
body["IgnoreSignatures"] = ignore_signatures
resp = self.do_put("api/mirrors/%s" % (quote(name)), json=body)
return resp
self.do_put("api/mirrors/%s" % (quote(name)), json=body)

def edit(self, name: str, newname: Optional[str] = None, archiveurl: Optional[str] = None,
filter: Optional[str] = None, architectures: Optional[List[str]] = None,
components: Optional[List[str]] = None, keyrings: Optional[List[str]] = None,
filter_with_deps: bool = False, skip_existing_packages: bool = False,
download_sources: bool = False, download_udebs: bool = False,
skip_component_check: bool = False, ignore_checksums: bool = False,
ignore_signatures: bool = False, force_update: bool = False) -> Mirror:
ignore_signatures: bool = False, force_update: bool = False) -> None:

body = {}
body = {} # type: T_BodyDict
if newname:
body["Name"] = newname
if archiveurl:
Expand Down Expand Up @@ -124,8 +126,7 @@ def edit(self, name: str, newname: Optional[str] = None, archiveurl: Optional[st
if force_update:
body["ForceUpdate"] = force_update

resp = self.do_put("api/mirrors/%s" % (quote(name)), json=body)
return resp
self.do_put("api/mirrors/%s" % (quote(name)), json=body)

def show(self, name: str) -> Mirror:
resp = self.do_get("api/mirrors/%s" % (quote(name)))
Expand All @@ -149,9 +150,8 @@ def list_packages(self, name: str, query: Optional[str] = None, with_deps: bool
ret.append(PackageAPISection.package_from_response(rpkg))
return ret

def delete(self, name: str) -> Sequence[Mirror]:
resp = self.do_delete("api/mirrors/%s" % quote(name))
return resp
def delete(self, name: str) -> None:
self.do_delete("api/mirrors/%s" % quote(name))

def create(self, name: str, archiveurl: str, distribution: Optional[str] = None,
filter: Optional[str] = None, components: Optional[List[str]] = None,
Expand All @@ -162,7 +162,7 @@ def create(self, name: str, archiveurl: str, distribution: Optional[str] = None,
data = {
"Name": name,
"ArchiveURL": archiveurl
}
} # type: T_BodyDict

if ignore_signatures:
data["IgnoreSignatures"] = ignore_signatures
Expand Down
98 changes: 49 additions & 49 deletions aptly_api/tests/test_mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class MirrorsAPISectionTests(TestCase):
def __init__(self, *args: Any) -> None:
super().__init__(*args)
self.mapi = MirrorsAPISection("http://test/")
self.miapi = MirrorsAPISection("http://test/")

def test_create(self, *, rmock: requests_mock.Mocker) -> None:
rmock.post("http://test/api/mirrors",
Expand All @@ -25,25 +25,25 @@ def test_create(self, *, rmock: requests_mock.Mocker) -> None:
"ArchiveRoot": "https://deb.nodesource.com/node_10.x/",
"Distribution": "bionic", "Components": ["main"],
"Architectures": ["amd64"],
"Meta": {"Architectures": "i386 amd64 armhf arm64",
"Meta": [{"Architectures": "i386 amd64 armhf arm64",
"Codename": "bionic", "Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"},
"Label": "Node Source", "Origin": "Node Source"}],
"LastDownloadDate": "0001-01-01T00:00:00Z",
"Filter": "test", "Status": 0, "WorkerPID": 0,
"FilterWithDeps": true, "SkipComponentCheck": true,
"SkipArchitectureCheck": true, "DownloadSources": true,
"DownloadUdebs": true, "DownloadInstaller": true}"""
)
self.assertEqual(
self.mapi.create(name="aptly-mirror", archiveurl='https://deb.nodesource.com/node_10.x/',
distribution='bionic', components=["main"],
architectures=["amd64"],
filter="test", download_udebs=True,
download_sources=True, download_installer=True,
skip_component_check=True, filter_with_deps=True,
keyrings="/path/to/keyring", ignore_signatures=True),
self.assertSequenceEqual(
self.miapi.create(name="aptly-mirror", archiveurl='https://deb.nodesource.com/node_10.x/',
distribution='bionic', components=["main"],
architectures=["amd64"],
filter="test", download_udebs=True,
download_sources=True, download_installer=True,
skip_component_check=True, filter_with_deps=True,
keyrings=["/path/to/keyring"], ignore_signatures=True),
Mirror(
uuid='2cb5985a-a23f-4a1f-8eb6-d5409193b4eb',
name="aptly-mirror",
Expand All @@ -52,12 +52,12 @@ def test_create(self, *, rmock: requests_mock.Mocker) -> None:
components=["main"],
architectures=["amd64"],
downloaddate='0001-01-01T00:00:00Z',
meta={"Architectures": "i386 amd64 armhf arm64",
meta=[{"Architectures": "i386 amd64 armhf arm64",
"Codename": "bionic",
"Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"},
"Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"}],
filter="test",
status=0,
worker_pid=0,
Expand All @@ -78,19 +78,19 @@ def test_list(self, *, rmock: requests_mock.Mocker) -> None:
"ArchiveRoot": "https://deb.nodesource.com/node_10.x/",
"Distribution": "bionic", "Components": ["main"],
"Architectures": ["amd64"],
"Meta": {"Architectures": "i386 amd64 armhf arm64",
"Meta": [{"Architectures": "i386 amd64 armhf arm64",
"Codename": "bionic", "Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"},
"Label": "Node Source", "Origin": "Node Source"}],
"LastDownloadDate": "0001-01-01T00:00:00Z", "Filter": "",
"Status": 0, "WorkerPID": 0, "FilterWithDeps": false,
"SkipComponentCheck": false, "SkipArchitectureCheck": false,
"DownloadSources": false, "DownloadUdebs": false,
"DownloadInstaller": false}]"""
)
self.assertSequenceEqual(
self.mapi.list(),
self.miapi.list(),
[
Mirror(
uuid='2cb5985a-a23f-4a1f-8eb6-d5409193b4eb',
Expand All @@ -100,12 +100,12 @@ def test_list(self, *, rmock: requests_mock.Mocker) -> None:
components=["main"],
architectures=["amd64"],
downloaddate='0001-01-01T00:00:00Z',
meta={"Architectures": "i386 amd64 armhf arm64",
meta=[{"Architectures": "i386 amd64 armhf arm64",
"Codename": "bionic",
"Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"},
"Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"}],
filter="",
status=0,
worker_pid=0,
Expand All @@ -127,19 +127,19 @@ def test_show(self, *, rmock: requests_mock.Mocker) -> None:
"ArchiveRoot": "https://deb.nodesource.com/node_10.x/",
"Distribution": "bionic", "Components": ["main"],
"Architectures": ["amd64"],
"Meta": {"Architectures": "i386 amd64 armhf arm64",
"Meta": [{"Architectures": "i386 amd64 armhf arm64",
"Codename": "bionic", "Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"},
"Label": "Node Source", "Origin": "Node Source"}],
"LastDownloadDate": "0001-01-01T00:00:00Z", "Filter": "",
"Status": 0, "WorkerPID": 0, "FilterWithDeps": false,
"SkipComponentCheck": false, "SkipArchitectureCheck": false,
"DownloadSources": false, "DownloadUdebs": false,
"DownloadInstaller": false}"""
)
self.assertEqual(
self.mapi.show(name="aptly-mirror"),
self.assertSequenceEqual(
self.miapi.show(name="aptly-mirror"),
Mirror(
uuid='2cb5985a-a23f-4a1f-8eb6-d5409193b4eb',
name="aptly-mirror",
Expand All @@ -148,12 +148,12 @@ def test_show(self, *, rmock: requests_mock.Mocker) -> None:
components=["main"],
architectures=["amd64"],
downloaddate='0001-01-01T00:00:00Z',
meta={"Architectures": "i386 amd64 armhf arm64",
meta=[{"Architectures": "i386 amd64 armhf arm64",
"Codename": "bionic",
"Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"},
"Components": "main",
"Date": "Tue, 06 Apr 2021 21:05:41 UTC",
"Description": " Apt Repository for the Node.JS 10.x Branch",
"Label": "Node Source", "Origin": "Node Source"}],
filter="",
status=0,
worker_pid=0,
Expand All @@ -171,7 +171,7 @@ def test_list_packages(self, *, rmock: requests_mock.Mocker) -> None:
rmock.get("http://test/api/mirrors/aptly-mirror/packages",
text='["Pamd64 nodejs 10.24.1-1nodesource1 1f74a6abf6acc572"]')
self.assertSequenceEqual(
self.mapi.list_packages(
self.miapi.list_packages(
name="aptly-mirror", query=("nodejs"), with_deps=True),
[
Package(
Expand Down Expand Up @@ -213,8 +213,8 @@ def test_list_packages_details(self, *, rmock: requests_mock.Mocker) -> None:
"Version":"10.24.1-1nodesource1"
}]"""
)
self.assertEqual(
self.mapi.list_packages(
self.assertSequenceEqual(
self.miapi.list_packages(
"aptly-mirror", detailed=True, with_deps=True, query="nodejs"),
[
Package(
Expand Down Expand Up @@ -253,32 +253,32 @@ def test_list_packages_details(self, *, rmock: requests_mock.Mocker) -> None:

def test_delete(self, *, rmock: requests_mock.Mocker) -> None:
with self.assertRaises(requests_mock.NoMockAddress):
self.mapi.delete(name="aptly-mirror")
self.miapi.delete(name="aptly-mirror")

def test_update(self, *, rmock: requests_mock.Mocker) -> None:
with self.assertRaises(requests_mock.NoMockAddress):
self.mapi.update(name="aptly-mirror", ignore_signatures=True)
self.miapi.update(name="aptly-mirror", ignore_signatures=True)

def test_edit(self, *, rmock: requests_mock.Mocker) -> None:
with self.assertRaises(requests_mock.NoMockAddress):
self.mapi.edit(name="aptly-mirror", newname="aptly-mirror-renamed",
archiveurl='https://deb.nodesource.com/node_10.x/',
architectures=["i386", "amd64"], filter="test",
components=["main"], keyrings="/path/to/keyring",
skip_existing_packages=True, ignore_checksums=True,
download_udebs=True, download_sources=True,
skip_component_check=True, filter_with_deps=True,
ignore_signatures=True, force_update=True),
self.miapi.edit(name="aptly-mirror", newname="aptly-mirror-renamed",
archiveurl='https://deb.nodesource.com/node_10.x/',
architectures=["i386", "amd64"], filter="test",
components=["main"], keyrings=["/path/to/keyring"],
skip_existing_packages=True, ignore_checksums=True,
download_udebs=True, download_sources=True,
skip_component_check=True, filter_with_deps=True,
ignore_signatures=True, force_update=True)

def test_delete_validation(self, *, rmock: requests_mock.Mocker) -> None:
rmock.delete("http://test/api/mirrors/aptly-mirror")
self.mapi.delete(name="aptly-mirror")
self.miapi.delete(name="aptly-mirror")

def test_update_validation(self, *, rmock: requests_mock.Mocker) -> None:
rmock.put("http://test/api/mirrors/aptly-mirror")
self.mapi.update(name="aptly-mirror")
self.miapi.update(name="aptly-mirror")

def test_edit_validation(self, *, rmock: requests_mock.Mocker) -> None:
rmock.put("http://test/api/mirrors/aptly-mirror",
text='{"Name":"aptly-mirror-bla", "IgnoreSignatures": true}')
self.mapi.edit(name="aptly-mirror", newname="aptly-mirror-renamed")
self.miapi.edit(name="aptly-mirror", newname="aptly-mirror-renamed")

0 comments on commit 41c580d

Please sign in to comment.