diff --git a/aptly_api/client.py b/aptly_api/client.py index 7d41ef7..bfce19b 100644 --- a/aptly_api/client.py +++ b/aptly_api/client.py @@ -33,7 +33,8 @@ def __init__(self, aptly_server_url: str, ssl_verify: Union[str, bool, None] = N self.snapshots = SnapshotAPISection(base_url=self.__aptly_server_url, ssl_verify=ssl_verify, ssl_cert=ssl_cert, http_auth=http_auth, timeout=timeout) self.mirrors = MirrorsAPISection( - base_url=self.__aptly_server_url, ssl_verify=ssl_verify, ssl_cert=ssl_cert, http_auth=http_auth, timeout=timeout) + base_url=self.__aptly_server_url, ssl_verify=ssl_verify, + ssl_cert=ssl_cert, http_auth=http_auth, timeout=timeout) @property def aptly_server_url(self) -> str: diff --git a/aptly_api/parts/mirrors.py b/aptly_api/parts/mirrors.py index 5ce1b75..3bedc35 100644 --- a/aptly_api/parts/mirrors.py +++ b/aptly_api/parts/mirrors.py @@ -3,10 +3,10 @@ # 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, Union, cast, Optional, List +from typing import NamedTuple, Sequence, Dict, cast, Optional, List from urllib.parse import quote -from aptly_api.base import BaseAPIClient, AptlyAPIException +from aptly_api.base import BaseAPIClient from aptly_api.parts.packages import Package, PackageAPISection @@ -41,7 +41,8 @@ def mirror_from_response(api_response: Dict[str, str]) -> Mirror: archiveurl=cast( str, api_response["ArchiveRoot"]), distribution=cast( - str, api_response["Distribution"]) if "Distribution" in api_response else None, + str, api_response["Distribution"]) + if "Distribution" in api_response else None, components=cast(List[str], api_response["Components"] )if "Components" in api_response else None, architectures=cast(List[str], api_response["Architectures"] @@ -49,13 +50,15 @@ def mirror_from_response(api_response: Dict[str, str]) -> Mirror: meta=cast(List[Dict[str, str]], api_response["Meta"] ) if "Meta" in api_response else None, downloaddate=cast( - str, api_response["LastDownloadDate"]) if "LastDownloadDate" in api_response else None, + str, api_response["LastDownloadDate"]) + if "LastDownloadDate" in api_response else None, filter=cast(str, api_response["Filter"] ) if "Filter" in api_response else None, status=cast(int, api_response["Status"] )if "Status" in api_response else None, worker_pid=cast( - int, api_response["WorkerPID"])if "WorkerPID" in api_response else None, + int, api_response["WorkerPID"]) + if "WorkerPID" in api_response else None, filter_with_deps=cast(bool, api_response["FilterWithDeps"]), skip_component_check=cast( bool, api_response["SkipComponentCheck"]), diff --git a/aptly_api/parts/snapshots.py b/aptly_api/parts/snapshots.py index 3cf9376..0bff9a7 100644 --- a/aptly_api/parts/snapshots.py +++ b/aptly_api/parts/snapshots.py @@ -12,7 +12,6 @@ from aptly_api.base import BaseAPIClient, AptlyAPIException from aptly_api.parts.packages import Package, PackageAPISection -from aptly_api.parts.mirrors import Mirror Snapshot = NamedTuple('Snapshot', [ ('name', str), diff --git a/aptly_api/tests/__init__.py b/aptly_api/tests/__init__.py index a66487b..e551fe6 100644 --- a/aptly_api/tests/__init__.py +++ b/aptly_api/tests/__init__.py @@ -12,4 +12,4 @@ from .test_publish import * # noqa from .test_repos import * # noqa from .test_snapshots import * # noqa -from .test_mirrors import * +from .test_mirrors import * # noqa diff --git a/aptly_api/tests/test_mirrors.py b/aptly_api/tests/test_mirrors.py index d20f5ae..240bcfe 100644 --- a/aptly_api/tests/test_mirrors.py +++ b/aptly_api/tests/test_mirrors.py @@ -8,7 +8,6 @@ import requests_mock -from aptly_api.base import AptlyAPIException from aptly_api.parts.packages import Package from aptly_api.parts.mirrors import MirrorsAPISection, Mirror @@ -21,7 +20,21 @@ def __init__(self, *args: Any) -> None: def test_create(self, *, rmock: requests_mock.Mocker) -> None: rmock.post("http://test/api/mirrors", - text='{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb", "Name": "aptly-mirror", "ArchiveRoot": "https://deb.nodesource.com/node_10.x/", "Distribution": "bionic", "Components": ["main"], "Architectures": ["amd64"], "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"}, "LastDownloadDate": "0001-01-01T00:00:00Z", "Filter": "test", "Status": 0, "WorkerPID": 0, "FilterWithDeps": true, "SkipComponentCheck": true, "SkipArchitectureCheck": true, "DownloadSources": true, "DownloadUdebs": true, "DownloadInstaller": true}' + text="""{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb", + "Name": "aptly-mirror", + "ArchiveRoot": "https://deb.nodesource.com/node_10.x/", + "Distribution": "bionic", "Components": ["main"], + "Architectures": ["amd64"], + "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"}, + "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/', @@ -60,7 +73,21 @@ def test_create(self, *, rmock: requests_mock.Mocker) -> None: def test_list(self, *, rmock: requests_mock.Mocker) -> None: rmock.get("http://test/api/mirrors", - text='[{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb", "Name": "aptly-mirror", "ArchiveRoot": "https://deb.nodesource.com/node_10.x/", "Distribution": "bionic", "Components": ["main"], "Architectures": ["amd64"], "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"}, "LastDownloadDate": "0001-01-01T00:00:00Z", "Filter": "", "Status": 0, "WorkerPID": 0, "FilterWithDeps": false, "SkipComponentCheck": false, "SkipArchitectureCheck": false, "DownloadSources": false, "DownloadUdebs": false, "DownloadInstaller": false}]' + text="""[{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb", + "Name": "aptly-mirror", + "ArchiveRoot": "https://deb.nodesource.com/node_10.x/", + "Distribution": "bionic", "Components": ["main"], + "Architectures": ["amd64"], + "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"}, + "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(), @@ -95,7 +122,21 @@ def test_list(self, *, rmock: requests_mock.Mocker) -> None: def test_show(self, *, rmock: requests_mock.Mocker) -> None: rmock.get("http://test/api/mirrors/aptly-mirror", - text='{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb", "Name": "aptly-mirror", "ArchiveRoot": "https://deb.nodesource.com/node_10.x/", "Distribution": "bionic", "Components": ["main"], "Architectures": ["amd64"], "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"}, "LastDownloadDate": "0001-01-01T00:00:00Z", "Filter": "", "Status": 0, "WorkerPID": 0, "FilterWithDeps": false, "SkipComponentCheck": false, "SkipArchitectureCheck": false, "DownloadSources": false, "DownloadUdebs": false, "DownloadInstaller": false}' + text="""{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb", + "Name": "aptly-mirror", + "ArchiveRoot": "https://deb.nodesource.com/node_10.x/", + "Distribution": "bionic", "Components": ["main"], + "Architectures": ["amd64"], + "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"}, + "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"), @@ -148,8 +189,9 @@ def test_list_packages_details(self, *, rmock: requests_mock.Mocker) -> None: text="""[{ "Architecture":"amd64", "Conflicts": "nodejs-dev, nodejs-legacy, npm", - "Depends":"1libc6 (>= 2.9), libgcc1 (>= 1:3.4), libstdc++6 (>= 4.4.0), python-minimal, ca-certificates", - "Description":"Node.js event-based server-side javascript engine\\n", + "Depends":"1libc6 (>= 2.9), libgcc1 (>= 1:3.4),""" + """ libstdc++6 (>= 4.4.0), python-minimal, ca-certificates", + "Description":" Node.js event-based server-side javascript engine\\n", "Filename":"nodejs_10.24.1-1nodesource1_amd64.deb", "FilesHash":"1f74a6abf6acc572", "Homepage":"https://nodejs.org", @@ -163,7 +205,8 @@ def test_list_packages_details(self, *, rmock: requests_mock.Mocker) -> None: "Provides":"nodejs-dev, nodejs-legacy, npm", "SHA1":"a3bc5a29614eab366bb3644abb1e602b5c8953d5", "SHA256":"4b374d16b536cf1a3963ddc4575ed2b68b28b0b5ea6eefe93c942dfc0ed35177", - "SHA512":"bf203bb319de0c5f7ed3b6ba69de39b1ea8b5086b872561379bd462dd93f07969ca64fa01ade01ff08fa13a4e5e28625b59292ba44bc01ba876ec95875630460", + "SHA512":"bf203bb319de0c5f7ed3b6ba69de39b1ea8b5086b872561379bd462dd93f0796""" + """9ca64fa01ade01ff08fa13a4e5e28625b59292ba44bc01ba876ec95875630460", "Section":"web", "ShortKey":"Pamd64 nodejs 10.24.1-1nodesource1", "Size":"15949164", @@ -179,10 +222,11 @@ def test_list_packages_details(self, *, rmock: requests_mock.Mocker) -> None: short_key='Pamd64 nodejs 10.24.1-1nodesource1', files_hash='1f74a6abf6acc572', fields={ - 'Architecture': 'amd64', + "Architecture": "amd64", 'Conflicts': 'nodejs-dev, nodejs-legacy, npm', - 'Depends': '1libc6 (>= 2.9), libgcc1 (>= 1:3.4), libstdc++6 (>= 4.4.0), python-minimal, ca-certificates', - 'Description': 'Node.js event-based server-side javascript engine\n', + 'Depends': '1libc6 (>= 2.9), libgcc1 (>= 1:3.4), ' + 'libstdc++6 (>= 4.4.0), python-minimal, ca-certificates', + 'Description': ' Node.js event-based server-side javascript engine\n', 'Filename': 'nodejs_10.24.1-1nodesource1_amd64.deb', 'FilesHash': '1f74a6abf6acc572', 'Homepage': 'https://nodejs.org', @@ -197,7 +241,7 @@ def test_list_packages_details(self, *, rmock: requests_mock.Mocker) -> None: 'SHA1': 'a3bc5a29614eab366bb3644abb1e602b5c8953d5', 'SHA256': '4b374d16b536cf1a3963ddc4575ed2b68b28b0b5ea6eefe93c942dfc0ed35177', 'SHA512': 'bf203bb319de0c5f7ed3b6ba69de39b1ea8b5086b872561379bd462dd93f0796' - '9ca64fa01ade01ff08fa13a4e5e28625b59292ba44bc01ba876ec95875630460', + '9ca64fa01ade01ff08fa13a4e5e28625b59292ba44bc01ba876ec95875630460', 'Section': 'web', 'ShortKey': 'Pamd64 nodejs 10.24.1-1nodesource1', 'Size': '15949164',