18
18
InvalidPermissionsException ,
19
19
SubjectNotFoundException ,
20
20
SubjectAlreadyExistsException ,
21
+ InvalidDomainNameException ,
22
+ DomainConflictException ,
21
23
)
22
24
from .conftest import RAPID_URL , RAPID_TOKEN
23
25
@@ -392,7 +394,9 @@ def test_delete_client_failure(self, requests_mock: Mocker, rapid: Rapid):
392
394
rapid .delete_client ("xxx-yyy-zzz" )
393
395
394
396
@pytest .mark .usefixtures ("requests_mock" , "rapid" )
395
- def update_subject_permissions_success (self , requests_mock : Mocker , rapid : Rapid ):
397
+ def test_update_subject_permissions_success (
398
+ self , requests_mock : Mocker , rapid : Rapid
399
+ ):
396
400
mocked_response = {"data" : "dummy" }
397
401
requests_mock .put (
398
402
f"{ RAPID_URL } /subject/permissions" , json = mocked_response , status_code = 200
@@ -401,10 +405,58 @@ def update_subject_permissions_success(self, requests_mock: Mocker, rapid: Rapid
401
405
assert res == mocked_response
402
406
403
407
@pytest .mark .usefixtures ("requests_mock" , "rapid" )
404
- def update_subject_permissions_failure (self , requests_mock : Mocker , rapid : Rapid ):
408
+ def test_update_subject_permissions_failure (
409
+ self , requests_mock : Mocker , rapid : Rapid
410
+ ):
405
411
mocked_response = {"data" : "dummy" }
406
412
requests_mock .put (
407
413
f"{ RAPID_URL } /subject/permissions" , json = mocked_response , status_code = 400
408
414
)
409
415
with pytest .raises (InvalidPermissionsException ):
410
416
rapid .update_subject_permissions ("xxx-yyy-zzz" , ["READ_ALL" ])
417
+
418
+ @pytest .mark .usefixtures ("requests_mock" , "rapid" )
419
+ def test_create_protected_domain_invalid_name_failure (
420
+ self , requests_mock : Mocker , rapid : Rapid
421
+ ):
422
+ mocked_response = {
423
+ "details" : "The value set for domain [dummy] can only contain alphanumeric and underscore `_` characters and must start with an alphabetic character"
424
+ }
425
+ requests_mock .post (
426
+ f"{ RAPID_URL } /protected_domains/dummy" ,
427
+ json = mocked_response ,
428
+ status_code = 400 ,
429
+ )
430
+ with pytest .raises (InvalidDomainNameException ) as exc_info :
431
+ rapid .create_protected_domain ("dummy" )
432
+
433
+ assert (
434
+ str (exc_info .value )
435
+ == "The value set for domain [dummy] can only contain alphanumeric and underscore `_` characters and must start with an alphabetic character"
436
+ )
437
+
438
+ @pytest .mark .usefixtures ("requests_mock" , "rapid" )
439
+ def test_create_protected_domain_conflict_failure (
440
+ self , requests_mock : Mocker , rapid : Rapid
441
+ ):
442
+ mocked_response = {"details" : "The protected domain, [dummy] already exists" }
443
+ requests_mock .post (
444
+ f"{ RAPID_URL } /protected_domains/dummy" ,
445
+ json = mocked_response ,
446
+ status_code = 409 ,
447
+ )
448
+ with pytest .raises (DomainConflictException ) as exc_info :
449
+ rapid .create_protected_domain ("dummy" )
450
+
451
+ assert str (exc_info .value ) == "The protected domain, [dummy] already exists"
452
+
453
+ @pytest .mark .usefixtures ("requests_mock" , "rapid" )
454
+ def test_create_protected_domain_success (self , requests_mock : Mocker , rapid : Rapid ):
455
+ mocked_response = {"data" : "dummy" }
456
+ requests_mock .post (
457
+ f"{ RAPID_URL } /protected_domains/dummy" ,
458
+ json = mocked_response ,
459
+ status_code = 201 ,
460
+ )
461
+ res = rapid .create_protected_domain ("dummy" )
462
+ assert res is None
0 commit comments