@@ -151,3 +151,152 @@ def check(self):
151151 'IgnoreSignatures' : True }
152152 resp = self .put_task ("/api/mirrors/" + mirror_name , json = mirror_desc )
153153 self .check_task (resp )
154+
155+
156+ class MirrorsAPITestEdit (APITest ):
157+ """
158+ POST /api/mirrors/{name} - Edit mirror configuration
159+ """
160+ def check (self ):
161+ # Create a mirror first
162+ mirror_name = self .random_name ()
163+ mirror_desc = {'Name' : mirror_name ,
164+ 'ArchiveURL' : 'http://repo.aptly.info/system-tests/packagecloud.io/varnishcache/varnish30/debian/' ,
165+ 'IgnoreSignatures' : True ,
166+ 'Distribution' : 'wheezy' ,
167+ 'Components' : ['main' ],
168+ 'Architectures' : ['amd64' ]}
169+
170+ resp = self .post ("/api/mirrors" , json = mirror_desc )
171+ self .check_equal (resp .status_code , 201 )
172+
173+ # Test editing basic properties (Filter, FilterWithDeps, Download options)
174+ edit_params = {
175+ 'Filter' : 'varnish' ,
176+ 'FilterWithDeps' : True ,
177+ 'DownloadSources' : True ,
178+ 'DownloadInstaller' : False ,
179+ 'DownloadUdebs' : False
180+ }
181+
182+ resp = self .post ("/api/mirrors/" + mirror_name , json = edit_params )
183+ self .check_equal (resp .status_code , 200 )
184+ self .check_subset ({
185+ 'Name' : mirror_name ,
186+ 'Filter' : 'varnish' ,
187+ 'FilterWithDeps' : True ,
188+ 'DownloadSources' : True
189+ }, resp .json ())
190+
191+ # Verify the changes persisted
192+ resp = self .get ("/api/mirrors/" + mirror_name )
193+ self .check_equal (resp .status_code , 200 )
194+ self .check_subset ({
195+ 'Filter' : 'varnish' ,
196+ 'FilterWithDeps' : True ,
197+ 'DownloadSources' : True
198+ }, resp .json ())
199+
200+ # Test editing with empty filter to clear it
201+ edit_params = {'Filter' : '' }
202+ resp = self .post ("/api/mirrors/" + mirror_name , json = edit_params )
203+ self .check_equal (resp .status_code , 200 )
204+ self .check_equal (resp .json ()['Filter' ], '' )
205+
206+
207+ class MirrorsAPITestEditNotFound (APITest ):
208+ """
209+ POST /api/mirrors/{name} - Edit non-existent mirror
210+ """
211+ def check (self ):
212+ resp = self .post ("/api/mirrors/non-existent-mirror" , json = {'Filter' : 'test' })
213+ self .check_equal (resp .status_code , 404 )
214+ self .check_in ('unable to edit' , resp .json ()['error' ])
215+
216+
217+ class MirrorsAPITestEditArchitectures (APITest ):
218+ """
219+ POST /api/mirrors/{name} - Edit mirror architectures (triggers fetch)
220+ """
221+ def check (self ):
222+ # Create a mirror
223+ mirror_name = self .random_name ()
224+ mirror_desc = {'Name' : mirror_name ,
225+ 'ArchiveURL' : 'http://repo.aptly.info/system-tests/security.debian.org/debian-security/' ,
226+ 'IgnoreSignatures' : True ,
227+ 'Distribution' : 'buster/updates' ,
228+ 'Components' : ['main' ],
229+ 'Architectures' : ['amd64' ]}
230+
231+ resp = self .post ("/api/mirrors" , json = mirror_desc )
232+ self .check_equal (resp .status_code , 201 )
233+
234+ # Edit architectures (should trigger a fetch)
235+ edit_params = {
236+ 'Architectures' : ['amd64' , 'i386' ],
237+ 'IgnoreSignatures' : True
238+ }
239+
240+ resp = self .post ("/api/mirrors/" + mirror_name , json = edit_params )
241+ self .check_equal (resp .status_code , 200 )
242+
243+ # Verify architectures were updated
244+ resp = self .get ("/api/mirrors/" + mirror_name )
245+ self .check_equal (resp .status_code , 200 )
246+ architectures = resp .json ()['Architectures' ]
247+ self .check_equal (sorted (architectures ), ['amd64' , 'i386' ])
248+
249+
250+ class MirrorsAPITestEditArchiveURL (APITest ):
251+ """
252+ POST /api/mirrors/{name} - Edit mirror archive URL (triggers fetch)
253+ """
254+ def check (self ):
255+ # Create a mirror
256+ mirror_name = self .random_name ()
257+ mirror_desc = {'Name' : mirror_name ,
258+ 'ArchiveURL' : 'http://repo.aptly.info/system-tests/ftp.ru.debian.org/debian' ,
259+ 'IgnoreSignatures' : True ,
260+ 'Distribution' : 'bookworm' ,
261+ 'Components' : ['main' ],
262+ 'Architectures' : ['amd64' ]}
263+
264+ resp = self .post ("/api/mirrors" , json = mirror_desc )
265+ self .check_equal (resp .status_code , 201 )
266+
267+ # Edit archive URL (should trigger a fetch)
268+ edit_params = {
269+ 'ArchiveURL' : 'http://repo.aptly.info/system-tests/ftp.ch.debian.org/debian' ,
270+ 'IgnoreSignatures' : True
271+ }
272+
273+ resp = self .post ("/api/mirrors/" + mirror_name , json = edit_params )
274+ self .check_equal (resp .status_code , 200 )
275+
276+ # Verify URL was updated
277+ resp = self .get ("/api/mirrors/" + mirror_name )
278+ self .check_equal (resp .status_code , 200 )
279+ self .check_equal (resp .json ()['ArchiveRoot' ], 'http://repo.aptly.info/system-tests/ftp.ch.debian.org/debian/' )
280+
281+
282+ class MirrorsAPITestEditFlatMirrorUdebs (APITest ):
283+ """
284+ POST /api/mirrors/{name} - Edit flat mirror with udebs (should fail)
285+ """
286+ def check (self ):
287+ # Create a flat mirror
288+ mirror_name = self .random_name ()
289+ mirror_desc = {'Name' : mirror_name ,
290+ 'ArchiveURL' : 'http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian/bullseye-cran40/' ,
291+ 'IgnoreSignatures' : True ,
292+ 'Architectures' : ['amd64' ]}
293+
294+ resp = self .post ("/api/mirrors" , json = mirror_desc )
295+ self .check_equal (resp .status_code , 201 )
296+
297+ # Try to enable udebs on a flat mirror (should fail)
298+ edit_params = {'DownloadUdebs' : True }
299+
300+ resp = self .post ("/api/mirrors/" + mirror_name , json = edit_params )
301+ self .check_equal (resp .status_code , 400 )
302+ self .check_in ("flat mirrors don't support udebs" , resp .json ()['error' ])
0 commit comments