Skip to content

Commit aed9df0

Browse files
committed
fix: skip when httpbin isnt available
1 parent 0d66817 commit aed9df0

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/functional/test_http_client_functional.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
"""This module contains unit tests for the HTTPClient class."""
1+
"""This module contains functional tests for the HTTPClient class."""
22
# vim: set filetype=python ts=4 sw=4
33
# -*- coding: utf-8 -*-
44
import pytest
5+
import requests
56
from requests import RequestException
67
from tokendito import __title__
78
from tokendito import __version__
89
from tokendito.http_client import HTTPClient
910

1011

12+
def is_httpbin_available():
13+
"""Check if httpbin.org is available for testing."""
14+
try:
15+
response = requests.get("https://httpbin.org/get", timeout=5)
16+
return response.status_code == 200
17+
except (requests.RequestException, requests.Timeout):
18+
return False
19+
20+
21+
httpbin_available = pytest.mark.skipif(
22+
not is_httpbin_available(), reason="httpbin.org is not available"
23+
)
24+
25+
1126
@pytest.fixture
1227
def client():
1328
"""Fixture to create and return an HTTPClient instance."""
@@ -16,6 +31,7 @@ def client():
1631
return client
1732

1833

34+
@httpbin_available
1935
def test_get_request(client):
2036
"""Test the GET request functionality of HTTPClient."""
2137
# Make a GET request to the /get endpoint of httpbin which reflects the sent request data
@@ -27,6 +43,7 @@ def test_get_request(client):
2743
assert json_data["headers"]["User-Agent"] == f"{__title__}/{__version__}"
2844

2945

46+
@httpbin_available
3047
def test_post_request(client):
3148
"""Test the POST request functionality of HTTPClient."""
3249
# Make a POST request to the /post endpoint of httpbin with sample data
@@ -38,6 +55,7 @@ def test_post_request(client):
3855
assert json_data["json"] == {"key": "value"}
3956

4057

58+
@httpbin_available
4159
def test_add_cookies(client):
4260
"""Test the ability to set cookies using HTTPClient."""
4361
# Set a test cookie for the client
@@ -51,6 +69,7 @@ def test_add_cookies(client):
5169
assert json_data["cookies"] == {"test_cookie": "cookie_value"}
5270

5371

72+
@httpbin_available
5473
def test_custom_header(client):
5574
"""Test the ability to send custom headers using HTTPClient."""
5675
# Make a GET request with a custom header
@@ -75,6 +94,7 @@ def test_bad_post_request(client, mocker):
7594
client.post("https://httpbin.org/post", json={"key": "value"})
7695

7796

97+
@httpbin_available
7898
def test_reset_session(client):
7999
"""Test the reset method to ensure session is reset."""
80100
# Set a test cookie for the client

0 commit comments

Comments
 (0)