Skip to content

Commit

Permalink
fix: Fix Windows tests
Browse files Browse the repository at this point in the history
get conditional global hosts as windows does not allow 0.0.0.0 host
  • Loading branch information
sansyrox committed Feb 11, 2023
1 parent 16bdfb4 commit a1d6bdd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
15 changes: 14 additions & 1 deletion integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import time
from typing import List
import platform

import pytest

Expand Down Expand Up @@ -33,6 +34,18 @@ def kill_process(process: subprocess.Popen) -> None:
pass


def get_network_host():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
# windows return ip address else return 0.0.0.0
# windows doesn't support 0.0.0.0

if platform.system() == "Windows":
return ip_address
else:
return "0.0.0.0"


def start_server(domain: str, port: int, is_dev: bool = False) -> subprocess.Popen:
"""
Call this method to wait for the server to start
Expand Down Expand Up @@ -84,7 +97,7 @@ def default_session():

@pytest.fixture(scope="session")
def global_session():
domain = "0.0.0.0"
domain = get_network_host()
port = 8080
os.environ["ROBYN_URL"] = domain
process = start_server(domain, port)
Expand Down
20 changes: 17 additions & 3 deletions integration_tests/test_base_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import os

import socket
import requests
import platform


def get_network_host():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
# windows return ip address else return 0.0.0.0
# windows doesn't support 0.0.0.0

if platform.system() == "Windows":
return ip_address
else:
return "0.0.0.0"


def test_default_url_index_request(default_session):
Expand All @@ -17,9 +30,10 @@ def test_local_index_request(session):


def test_global_index_request(global_session):
BASE_URL = "http://0.0.0.0:8080"
host = get_network_host()
BASE_URL = f"http://{host}:8080"
res = requests.get(f"{BASE_URL}")
assert os.getenv("ROBYN_URL") == "0.0.0.0"
assert os.getenv("ROBYN_URL") == f"{host}"
assert res.status_code == 200


Expand Down

0 comments on commit a1d6bdd

Please sign in to comment.