def test_auth_header_set_with_token(self, env, requests): """Given an authorization token env variable, get is called with authorization header.""" env.MBED_API_AUTH_TOKEN = "token" header = {"Authorization": "Bearer token"} board_database._get_request() requests.get.assert_called_once_with(board_database._BOARD_API, headers=header)
def test_raises_tools_error_on_connection_error(self, get, caplog): get.side_effect = board_database.requests.exceptions.ConnectionError with pytest.raises(board_database.BoardAPIError): board_database._get_request() assert "Unable to connect" in caplog.text assert len(caplog.records) == 1
def test_logs_no_warning_on_success(self, get, caplog): board_database._get_request() assert not caplog.records
def test_no_auth_header_set_with_empty_token_var(self, requests): """Given no authorization token env variable, get is called with no header.""" board_database._get_request() requests.get.assert_called_once_with(board_database._BOARD_API, headers=None)
def test_requests_uses_proxy_variables(self, requests_mock): requests_mock.get(board_database._BOARD_API) board_database._get_request() assert requests_mock.last_request.proxies == {"http": "http://proxy:8080", "https": "https://proxy:8080"}
def test_logs_error_on_requests_proxy_error(self, get, caplog): get.side_effect = board_database.requests.exceptions.ProxyError with pytest.raises(board_database.BoardAPIError): board_database._get_request() assert "connect to proxy" in caplog.text
def test_logs_error_on_requests_ssl_error(self, get, caplog): get.side_effect = board_database.requests.exceptions.SSLError with pytest.raises(board_database.BoardAPIError): board_database._get_request() assert "verify an SSL" in caplog.text
def test_raises_tools_error_on_connection_error(self, get): get.side_effect = board_database.requests.exceptions.ConnectionError with self.assertRaises(board_database.BoardAPIError): board_database._get_request()