# Path: pynubank/exception.py
# class NuRequestException(NuException):
#     def __init__(self, response: Response):
#         super().__init__(f'The request made failed with HTTP status code {response.status_code}')
#         self.url = response.url
#         self.status_code = response.status_code
#         self.response = response
# 
# Path: pynubank/utils/http.py
# class HttpClient:
# 
#     def __init__(self):
#         self._cert = None
#         self._headers = {
#             'Content-Type': 'application/json',
#             'X-Correlation-Id': 'WEB-APP.pewW9',
#             'User-Agent': 'pynubank Client - https://github.com/andreroggeri/pynubank',
#         }
# 
#     def set_cert(self, cert_path: str):
#         self._cert = cert_path
# 
#     def set_header(self, name: str, value: str):
#         self._headers[name] = value
# 
#     def remove_header(self, name: str):
#         self._headers.pop(name)
# 
#     def get_header(self, name: str):
#         return self._headers.get(name)
# 
#     @property
#     def _cert_args(self):
#         return {'pkcs12_filename': self._cert, 'pkcs12_password': ''} if self._cert else {}
# 
#     def _handle_response(self, response: Response) -> dict:
#         if response.status_code != 200:
#             raise NuRequestException(response)
# 
#         return response.json()
# 
#     def raw_get(self, url: str) -> Response:
#         return get(url, headers=self._headers, **self._cert_args)
# 
#     def get(self, url: str) -> dict:
#         return self._handle_response(self.raw_get(url))
# 
#     def post(self, url: str, json: dict) -> dict:
#         return self._handle_response(post(url, json=json, headers=self._headers, **self._cert_args))


from unittest.mock import MagicMock
from requests import Response
from pynubank import NuRequestException
from pynubank.utils.http import HttpClient
import pytest




@pytest.mark.parametrize('http_status', [
    100, 101, 102, 103,
    201, 202, 203, 204, 205, 206, 207, 208, 226,
    300, 301, 302, 303, 304, 305, 306, 307, 308,
    400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 420, 421, 422,
    423,
    424, 426, 428, 429, 431, 440, 444, 449, 450, 451, 495, 496, 497, 498, 499,
    500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 520, 521, 522, 523, 524, 525, 526, 527, 530, 598
])
def test_http_get_handler_throws_exception_on_status_different_of_200(monkeypatch, http_status):
    response = Response()
    response.status_code = http_status
    monkeypatch.setattr('pynubank.utils.http.get', MagicMock(return_value=response))

    client = HttpClient()


# Path: pynubank/exception.py
# class NuRequestException(NuException):
#     def __init__(self, response: Response):
#         super().__init__(f'The request made failed with HTTP status code {response.status_code}')
#         self.url = response.url
#         self.status_code = response.status_code
#         self.response = response
# 
# Path: pynubank/utils/http.py
# class HttpClient:
# 
#     def __init__(self):
#         self._cert = None
#         self._headers = {
#             'Content-Type': 'application/json',
#             'X-Correlation-Id': 'WEB-APP.pewW9',
#             'User-Agent': 'pynubank Client - https://github.com/andreroggeri/pynubank',
#         }
# 
#     def set_cert(self, cert_path: str):
#         self._cert = cert_path
# 
#     def set_header(self, name: str, value: str):
#         self._headers[name] = value
# 
#     def remove_header(self, name: str):
#         self._headers.pop(name)
# 
#     def get_header(self, name: str):
#         return self._headers.get(name)
# 
#     @property
#     def _cert_args(self):
#         return {'pkcs12_filename': self._cert, 'pkcs12_password': ''} if self._cert else {}
# 
#     def _handle_response(self, response: Response) -> dict:
#         if response.status_code != 200:
#             raise NuRequestException(response)
# 
#         return response.json()
# 
#     def raw_get(self, url: str) -> Response:
#         return get(url, headers=self._headers, **self._cert_args)
# 
#     def get(self, url: str) -> dict:
#         return self._handle_response(self.raw_get(url))
# 
#     def post(self, url: str, json: dict) -> dict:
#         return self._handle_response(post(url, json=json, headers=self._headers, **self._cert_args))


# Path: tests/test_http_client.py
from unittest.mock import MagicMock
from requests import Response
from pynubank import NuRequestException
from pynubank.utils.http import HttpClient
import pytest





@pytest.mark.parametrize('http_status', [
    100, 101, 102, 103,
    201, 202, 203, 204, 205, 206, 207, 208, 226,
    300, 301, 302, 303, 304, 305, 306, 307, 308,
    400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 420, 421, 422,
    423,
    424, 426, 428, 429, 431, 440, 444, 449, 450, 451, 495, 496, 497, 498, 499,
    500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 520, 521, 522, 523, 524, 525, 526, 527, 530, 598
])
def test_http_get_handler_throws_exception_on_status_different_of_200(monkeypatch, http_status):
    response = Response()
    response.status_code = http_status
    monkeypatch.setattr('pynubank.utils.http.get', MagicMock(return_value=response))

    client = HttpClient()


    with pytest.raises(NuRequestException) as ex: