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 13, 2023
1 parent 54040f5 commit 35ed50b
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 15 deletions.
9 changes: 5 additions & 4 deletions integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import signal
import socket
import subprocess
import sys
import time
from typing import List
import platform

import pytest
from helpers.network_helpers import get_network_host


def spawn_process(command: List[str]) -> subprocess.Popen:
if sys.platform.startswith("win32"):
if platform.system() == "Windows":
command[0] = "python"
process = subprocess.Popen(
command, shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
Expand All @@ -22,7 +23,7 @@ def spawn_process(command: List[str]) -> subprocess.Popen:


def kill_process(process: subprocess.Popen) -> None:
if sys.platform.startswith("win32"):
if platform.system() == "Windows":
process.send_signal(signal.CTRL_BREAK_EVENT)
process.kill()
return
Expand Down Expand Up @@ -84,7 +85,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
Empty file.
File renamed without changes.
14 changes: 14 additions & 0 deletions integration_tests/helpers/network_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import socket
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"
7 changes: 5 additions & 2 deletions integration_tests/test_base_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import requests

from helpers.network_helpers import get_network_host


def test_default_url_index_request(default_session):
BASE_URL = "http://127.0.0.1:8080"
Expand All @@ -17,9 +19,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
2 changes: 1 addition & 1 deletion integration_tests/test_basic_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from http_methods_helpers import get
from helpers.http_methods_helpers import get


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_delete_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from http_methods_helpers import delete
from helpers.http_methods_helpers import delete


@pytest.mark.parametrize("function_type", ["sync", "async"])
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_file_download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from http_methods_helpers import get
from helpers.http_methods_helpers import get


@pytest.mark.parametrize("function_type", ["sync", "async"])
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_get_requests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from requests import Response

from http_methods_helpers import get
from helpers.http_methods_helpers import get


@pytest.mark.parametrize("function_type", ["sync", "async"])
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from http_methods_helpers import get
from helpers.http_methods_helpers import get


@pytest.mark.skip(reason="Fix middleware request headers modification")
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_patch_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from http_methods_helpers import patch
from helpers.http_methods_helpers import patch


@pytest.mark.parametrize("function_type", ["sync", "async"])
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_post_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from http_methods_helpers import post
from helpers.http_methods_helpers import post


@pytest.mark.parametrize("function_type", ["sync", "async"])
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_put_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from http_methods_helpers import put
from helpers.http_methods_helpers import put


@pytest.mark.parametrize("function_type", ["sync", "async"])
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_status_code.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from http_methods_helpers import get
from helpers.http_methods_helpers import get


def test_404_status_code(session):
Expand Down
1 change: 1 addition & 0 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import multiprocess as mp
import os
from platform import platform
import signal
from typing import Callable, List, Optional

Expand Down

0 comments on commit 35ed50b

Please sign in to comment.