55# file, You can obtain one at http://mozilla.org/MPL/2.0/.
66from typing import Any
77from unittest .case import TestCase
8+ from inspect import signature
9+ import json
810
911import requests_mock
1012
@@ -19,38 +21,93 @@ def __init__(self, *args: Any) -> None:
1921 self .miapi = MirrorsAPISection ("http://test/" )
2022
2123 def test_create (self , * , rmock : requests_mock .Mocker ) -> None :
22- rmock .post ("http://test/api/mirrors" ,
23- text = """{"UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb",
24- "Name": "aptly-mirror",
25- "ArchiveRoot": "https://deb.nodesource.com/node_10.x/",
26- "Distribution": "bionic", "Components": ["main"],
27- "Architectures": ["amd64"],
28- "Meta": [{"Architectures": "i386 amd64 armhf arm64",
29- "Codename": "bionic", "Components": "main",
30- "Date": "Tue, 06 Apr 2021 21:05:41 UTC",
31- "Description": " Apt Repository for the Node.JS 10.x Branch",
32- "Label": "Node Source", "Origin": "Node Source"}],
33- "LastDownloadDate": "0001-01-01T00:00:00Z",
34- "Filter": "test", "Status": 0, "WorkerPID": 0,
35- "FilterWithDeps": true, "SkipComponentCheck": true,
36- "SkipArchitectureCheck": true, "DownloadSources": true,
37- "DownloadUdebs": true, "DownloadInstaller": true}"""
38- )
24+ expected = {"Name" : "testname" , "ArchiveURL" : "http://randomurl.url" }
25+
26+ rmock .post ("http://test/api/mirrors" , text = """{"Name":"nocheck", "ArchiveRoot":"nocheck"}""" )
27+ self .miapi .create (expected ["Name" ], expected ["ArchiveURL" ])
28+
29+ self .assertEqual (rmock .request_history [0 ].method , "POST" )
30+ self .assertEqual (len (rmock .request_history [0 ].json ()), len (expected ))
31+ self .assertEqual (rmock .request_history [0 ].json (), expected )
32+
33+ def test_create_all_args (self , * , rmock : requests_mock .Mocker ) -> None :
34+ expected = {
35+ "Name" : "aptly-mirror" ,
36+ "ArchiveURL" : "https://deb.nodesource.com/node_10.x/" ,
37+ "Distribution" : "bionic" ,
38+ "Filter" : "test" ,
39+ "Components" : ["main" ],
40+ "Architectures" : ["amd64" ],
41+ "Keyrings" : ["/path/to/keyring" ],
42+ "DownloadSources" : True ,
43+ "DownloadUdebs" : True ,
44+ "DownloadInstaller" : True ,
45+ "FilterWithDeps" : True ,
46+ "SkipComponentCheck" : True ,
47+ "SkipArchitectureCheck" : True ,
48+ "IgnoreSignatures" : True ,
49+ }
50+ # Keep us from getting out of lockstep with the number of args to create
51+ self .assertEqual (len (signature (self .miapi .create ).parameters ), len (expected ))
52+
53+ rmock .post ("http://test/api/mirrors" , text = """{"Name":"nocheck", "ArchiveRoot":"nocheck"}""" )
54+ self .miapi .create (
55+ name = "aptly-mirror" ,
56+ archiveurl = "https://deb.nodesource.com/node_10.x/" ,
57+ distribution = "bionic" ,
58+ filter = "test" ,
59+ components = ["main" ],
60+ architectures = ["amd64" ],
61+ keyrings = ["/path/to/keyring" ],
62+ download_sources = True ,
63+ download_udebs = True ,
64+ download_installer = True ,
65+ filter_with_deps = True ,
66+ skip_component_check = True ,
67+ skip_architecture_check = True ,
68+ ignore_signatures = True ,
69+ )
70+
71+ self .assertEqual (rmock .request_history [0 ].method , "POST" )
72+ self .assertEqual (len (rmock .request_history [0 ].json ()), len (expected ))
73+ self .assertEqual (rmock .request_history [0 ].json (), expected )
74+
75+ def test_mirror_from_response (self , * , rmock : requests_mock .Mocker ) -> None :
3976 self .assertSequenceEqual (
40- self .miapi .create (name = "aptly-mirror" , archiveurl = 'https://deb.nodesource.com/node_10.x/' ,
41- distribution = 'bionic' , components = ["main" ],
42- architectures = ["amd64" ],
43- filter = "test" , download_udebs = True ,
44- download_sources = True , download_installer = True ,
45- skip_component_check = True , filter_with_deps = True ,
46- keyrings = ["/path/to/keyring" ], ignore_signatures = True ),
77+ self .miapi .mirror_from_response (
78+ json .loads ("""{
79+ "UUID": "2cb5985a-a23f-4a1f-8eb6-d5409193b4eb",
80+ "Name": "aptly-mirror",
81+ "ArchiveRoot": "https://deb.nodesource.com/node_10.x/",
82+ "Distribution": "bionic",
83+ "Components": ["main"],
84+ "Architectures": ["amd64"],
85+ "LastDownloadDate": "0001-01-01T00:00:00Z",
86+ "Meta": [{"Architectures": "i386 amd64 armhf arm64",
87+ "Codename": "bionic",
88+ "Components": "main",
89+ "Date": "Tue, 06 Apr 2021 21:05:41 UTC",
90+ "Description": " Apt Repository for the Node.JS 10.x Branch",
91+ "Label": "Node Source",
92+ "Origin": "Node Source"}],
93+ "Filter": "test",
94+ "Status": 0,
95+ "WorkerPID": 0,
96+ "FilterWithDeps": true,
97+ "SkipComponentCheck": true,
98+ "SkipArchitectureCheck": true,
99+ "DownloadSources": true,
100+ "DownloadUdebs": true,
101+ "DownloadInstaller": true
102+ }""" )
103+ ),
47104 Mirror (
48105 uuid = '2cb5985a-a23f-4a1f-8eb6-d5409193b4eb' ,
49106 name = "aptly-mirror" ,
50107 archiveurl = "https://deb.nodesource.com/node_10.x/" ,
51108 distribution = 'bionic' ,
52- components = [" main" ],
53- architectures = [" amd64" ],
109+ components = [' main' ],
110+ architectures = [' amd64' ],
54111 downloaddate = '0001-01-01T00:00:00Z' ,
55112 meta = [{"Architectures" : "i386 amd64 armhf arm64" ,
56113 "Codename" : "bionic" ,
0 commit comments