Skip to content

Commit

Permalink
Use public httpbin for mac runner in github actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunns committed Apr 26, 2024
1 parent 42370b9 commit b55c82b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install build tools
run: python3 -m pip install --upgrade pip setuptools wheel tox~=3.0
- name: Install and Start Colima
run: |
if [[ "${{ matrix.os }}" == *"macos"* ]]
then
brew install docker docker-compose
colima status || colima start
fi
shell: bash
- name: Run Tests
# Run tox using the version of Python in `PATH`
run: tox -e py
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
extras_require={
"optional": [
"furl>=2.0",
"imurl>=0.2",
"yarl>=1.9",
"requests>=2.0",
"Werkzeug>=2.0",
],
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# encoding=utf-8
import logging
import os
import platform
import sqlite3

import pytest
from imurl import URL
from yarl import URL

logger = logging.getLogger(__name__)
LOCAL = os.getenv("GITHUB_ACTIONS", "") != "true"
LINUX = platform.system() == "Linux"
HTTPBIN_CONTAINERISED = LINUX or LOCAL


@pytest.fixture(scope="session")
Expand All @@ -28,7 +32,7 @@ def db():

@pytest.fixture(scope="session")
def httpbin(docker_ip, docker_services) -> URL:
if platform.system() != "Windows":
if HTTPBIN_CONTAINERISED:
docker_services.start("httpbin")
port = docker_services.wait_for_service("httpbin", 80)
return URL(f"http://{docker_ip}:{port}")
Expand Down
34 changes: 17 additions & 17 deletions tests/integration/matchers/test_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding=utf-8
import logging
import os
import platform
from datetime import timedelta

Expand All @@ -17,14 +18,16 @@
logger = logging.getLogger(__name__)

INTERNET_CONNECTED = internet_connection()
LOCAL = os.getenv("GITHUB_ACTIONS", "") != "true"
HTTPBIN_CONTAINERISED = platform.system() == "Linux" or LOCAL


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_status_code(httpbin):
# Given

# When
actual = requests.get(httpbin.replace(path="/status/345"))
actual = requests.get(httpbin / "status/345")

# Then
assert_that(actual, is_response().with_status_code(345))
Expand All @@ -35,26 +38,25 @@ def test_response_status_code(httpbin):
)


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_json(httpbin):
# Given

# When
actual = requests.get(httpbin.replace(path="/json"))
actual = requests.get(httpbin / "json")

# Then
assert_that(actual, is_response().with_json(has_key("slideshow")))
assert_that(actual, not_(is_response().with_json(has_key("shitshow"))))


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_content(httpbin):
# Given

# When
actual = requests.get(
httpbin.replace(path="/anything").set_query("foo", "bar"),
headers={"X-Clacks-Overhead": "Sir Terry Pratchett"},
httpbin / "anything" % {"foo": "bar"}, headers={"X-Clacks-Overhead": "Sir Terry Pratchett"}
)

# Then
Expand All @@ -65,25 +67,23 @@ def test_response_content(httpbin):
assert_that(actual, not_(is_response().with_content(b"seems unlikely")))


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_cookies(httpbin):
# Given

# When
actual = requests.get(
httpbin.replace(path="/cookies/set").set_query("foo", "bar"), allow_redirects=False
)
actual = requests.get(httpbin / "cookies/set" % {"foo": "bar"}, allow_redirects=False)

# Then
assert_that(actual, is_response().with_status_code(302).and_cookies(has_entries(foo="bar")))


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_elapsed(httpbin):
# Given

# When
actual = requests.get(httpbin.replace(path="/delay/0.5"))
actual = requests.get(httpbin / "delay/0.5")

# Then
assert_that(
Expand All @@ -94,12 +94,12 @@ def test_response_elapsed(httpbin):
)


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_history(httpbin):
# Given

# When
actual = requests.get(httpbin.replace(path="/cookies/set").set_query("foo", "bar"))
actual = requests.get(httpbin / "cookies/set" % {"foo": "bar"})

# Then
assert_that(
Expand All @@ -111,12 +111,12 @@ def test_response_history(httpbin):
)


@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.")
@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.")
def test_response_encoding(httpbin):
# Given

# When
actual = requests.get(httpbin.replace(path="/encoding/utf8"))
actual = requests.get(httpbin / "encoding/utf8")

# Then
assert_that(actual, is_response().with_encoding("utf-8"))
Expand Down

0 comments on commit b55c82b

Please sign in to comment.