66
77import pytest
88from freezegun import freeze_time
9- from mock_vws import MockVWS
9+ from mock_vws import MockVWS , VuMarkGenerationFailure
1010from mock_vws .database import CloudDatabase
1111from mock_vws .states import States
1212
1717)
1818from vws .exceptions .vws_exceptions import (
1919 AuthenticationFailureError ,
20+ AuthorizationFailedError ,
2021 BadImageError ,
2122 BadRequestError ,
2223 DateRangeError ,
2526 InvalidAcceptHeaderError ,
2627 InvalidInstanceIdError ,
2728 InvalidTargetTypeError ,
29+ LicenseCheckFailedError ,
2830 MetadataTooLargeError ,
2931 ProjectHasNoAPIAccessError ,
3032 ProjectInactiveError ,
3133 ProjectSuspendedError ,
34+ QuotaExceededError ,
3235 RequestQuotaReachedError ,
3336 RequestTimeTooSkewedError ,
3437 TargetNameExistError ,
@@ -412,6 +415,7 @@ def test_vwsexception_inheritance() -> None:
412415 """VWS-related exceptions should inherit from VWSException."""
413416 subclasses = [
414417 AuthenticationFailureError ,
418+ AuthorizationFailedError ,
415419 BadImageError ,
416420 BadRequestError ,
417421 DateRangeError ,
@@ -420,10 +424,12 @@ def test_vwsexception_inheritance() -> None:
420424 InvalidAcceptHeaderError ,
421425 InvalidInstanceIdError ,
422426 InvalidTargetTypeError ,
427+ LicenseCheckFailedError ,
423428 MetadataTooLargeError ,
424429 ProjectInactiveError ,
425430 ProjectHasNoAPIAccessError ,
426431 ProjectSuspendedError ,
432+ QuotaExceededError ,
427433 RequestQuotaReachedError ,
428434 RequestTimeTooSkewedError ,
429435 TargetNameExistError ,
@@ -492,6 +498,50 @@ def test_invalid_target_type(
492498 assert exc .value .response .status_code == HTTPStatus .UNPROCESSABLE_ENTITY
493499
494500
501+ @pytest .mark .parametrize (
502+ argnames = ("failure" , "exception_type" , "status_code" ),
503+ argvalues = [
504+ (
505+ VuMarkGenerationFailure .QUOTA_EXCEEDED ,
506+ QuotaExceededError ,
507+ HTTPStatus .FORBIDDEN ,
508+ ),
509+ (
510+ VuMarkGenerationFailure .LICENSE_CHECK_FAILED ,
511+ LicenseCheckFailedError ,
512+ HTTPStatus .FORBIDDEN ,
513+ ),
514+ (
515+ VuMarkGenerationFailure .AUTHORIZATION_FAILED ,
516+ AuthorizationFailedError ,
517+ HTTPStatus .UNAUTHORIZED ,
518+ ),
519+ ],
520+ )
521+ def test_documented_vumark_error_codes (
522+ * ,
523+ failure : VuMarkGenerationFailure ,
524+ exception_type : type [VWSError ],
525+ status_code : HTTPStatus ,
526+ ) -> None :
527+ """Documented VuMark failures raise matching exceptions."""
528+ with MockVWS (vumark_generation_failure = failure ):
529+ vumark_service = VuMarkService (
530+ server_access_key = uuid .uuid4 ().hex ,
531+ server_secret_key = uuid .uuid4 ().hex ,
532+ )
533+
534+ with pytest .raises (expected_exception = exception_type ) as exc :
535+ vumark_service .generate_vumark_instance (
536+ target_id = "exampletargetid" ,
537+ instance_id = "example_instance_id" ,
538+ accept = VuMarkAccept .PNG ,
539+ )
540+
541+ assert exc .value .response .status_code == status_code
542+ assert failure .value in exc .value .response .text
543+
544+
495545def test_base_exception (
496546 * ,
497547 vws_client : VWS ,
0 commit comments