2
2
import logging
3
3
import requests
4
4
5
- from pubtools .pulplib import Repository , YumRepository , DetachedException , YumImporter
5
+ import pubtools .pulplib ._impl .compat_attr as attr
6
+ from pubtools .pulplib import (
7
+ Repository ,
8
+ YumRepository ,
9
+ DetachedException ,
10
+ YumImporter ,
11
+ Distributor ,
12
+ )
6
13
7
14
8
15
def test_from_data_gives_yum_repository ():
@@ -216,7 +223,16 @@ def test_related_repositories_detached_client():
216
223
217
224
218
225
def test_create_repository (client , requests_mocker ):
219
- repo = YumRepository (id = "yum_repo_new" )
226
+ repo = YumRepository (
227
+ id = "yum_repo_new" ,
228
+ distributors = [
229
+ Distributor (
230
+ id = "fake_id" ,
231
+ type_id = "yum_distributor" ,
232
+ relative_url = "yum_repo_new/foo/bar" ,
233
+ )
234
+ ],
235
+ )
220
236
221
237
# create request
222
238
requests_mocker .post (
@@ -237,13 +253,44 @@ def test_create_repository(client, requests_mocker):
237
253
"config" : {},
238
254
}
239
255
],
256
+ "distributors" : [
257
+ {
258
+ "id" : "fake_id" ,
259
+ "distributor_type_id" : "yum_distributor" ,
260
+ "config" : {"relative_url" : "yum_repo_new/foo/bar" },
261
+ "repo_id" : "yum_repo_new" ,
262
+ }
263
+ ],
240
264
}
241
265
],
242
266
)
243
267
244
- out = client .create_repository (repo )
268
+ out = client .create_repository (repo ). result ()
245
269
# check return value of create_repository() call
246
- assert out .result () == repo
270
+ # relative_url wasn't set before request for `repo`
271
+ assert repo .relative_url is None
272
+ # but it's set after creation
273
+ assert out .relative_url == "yum_repo_new/foo/bar"
274
+
275
+ # repo_id of distributor isn't set before creation call
276
+ assert repo .distributors [0 ].repo_id is None
277
+ # but it's set after creation
278
+ assert out .distributors [0 ].repo_id == "yum_repo_new"
279
+ # evolve original repo object with new values
280
+ repo = attr .evolve (
281
+ repo ,
282
+ relative_url = "yum_repo_new/foo/bar" ,
283
+ distributors = [
284
+ Distributor (
285
+ id = "fake_id" ,
286
+ type_id = "yum_distributor" ,
287
+ relative_url = "yum_repo_new/foo/bar" ,
288
+ repo_id = "yum_repo_new" ,
289
+ )
290
+ ],
291
+ )
292
+ # and do full assert
293
+ assert out == repo
247
294
248
295
hist = requests_mocker .request_history
249
296
# there should be exactly 2 requests sent - create and search
@@ -256,6 +303,14 @@ def test_create_repository(client, requests_mocker):
256
303
# are automatically added for yum repository
257
304
assert create_query ["importer_type_id" ] == "yum_importer"
258
305
assert create_query ["importer_config" ] == {}
306
+ # check distributor data
307
+ assert len (create_query ["distributors" ]) == 1
308
+ assert create_query ["distributors" ][0 ]["distributor_id" ] == "fake_id"
309
+ assert create_query ["distributors" ][0 ]["distributor_type_id" ] == "yum_distributor"
310
+ assert (
311
+ create_query ["distributors" ][0 ]["distributor_config" ]["relative_url" ]
312
+ == "yum_repo_new/foo/bar"
313
+ )
259
314
260
315
# check the search request for created repo
261
316
search_query = hist [1 ].json ()
@@ -331,7 +386,9 @@ def test_create_repository_already_exists(client, requests_mocker, caplog):
331
386
332
387
def test_create_repository_wrong_data (client , requests_mocker , caplog ):
333
388
repo = YumRepository (
334
- id = "yum_repo_existing" , importer = YumImporter (config = {"new" : "value" })
389
+ id = "yum_repo_existing" ,
390
+ importer = YumImporter (config = {"new" : "value" }),
391
+ distributors = [Distributor (id = "test_dist" , type_id = "yum_distributor" )],
335
392
)
336
393
337
394
requests_mocker .post (
@@ -353,6 +410,18 @@ def test_create_repository_wrong_data(client, requests_mocker, caplog):
353
410
"config" : {"current" : "value" },
354
411
}
355
412
],
413
+ "distributors" : [
414
+ {
415
+ "id" : "fake_id_1" ,
416
+ "distributor_type_id" : "yum_distributor" ,
417
+ "config" : {},
418
+ },
419
+ {
420
+ "id" : "fake_id_2" ,
421
+ "distributor_type_id" : "iso_distributor" ,
422
+ "config" : {},
423
+ },
424
+ ],
356
425
}
357
426
],
358
427
)
@@ -363,6 +432,8 @@ def test_create_repository_wrong_data(client, requests_mocker, caplog):
363
432
for text in (
364
433
"Repository yum_repo_existing already exists" ,
365
434
"Repository yum_repo_existing contains wrong importer config" ,
435
+ "Repository yum_repo_existing contains wrong distributor id" ,
436
+ "Repository yum_repo_existing contains unexpected distributor with type: iso_distributor" ,
366
437
"Repository yum_repo_existing exists on server and contains unexpected values" ,
367
438
):
368
439
assert text in caplog .text
0 commit comments