File: test_exceptions.py

package info (click to toggle)
python-azure 20201208%2Bgit-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,437,920 kB
  • sloc: python: 4,287,452; javascript: 269; makefile: 198; sh: 187; xml: 106
file content (27 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from azure.core.exceptions import HttpResponseError, map_error
from azure.keyvault.keys._shared.exceptions import error_map
import pytest

from _shared.helpers import mock_response


def test_error_map():
    """error_map should map all error codes to a subclass of HttpResponseError"""

    error_code = "oops"
    error_message = "something went wrong"
    error_body = {"error": {"code": error_code, "message": error_message}}  # Key Vault error responses look like this

    for status_code in range(400, 600):
        response = mock_response(status_code=status_code, json_payload=error_body)

        with pytest.raises(HttpResponseError) as ex:
            map_error(status_code, response, error_map)

        # the concrete error should include error information returned by Key Vault
        assert error_code in ex.value.message
        assert error_message in ex.value.message