Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Port for Posting Global Paths in Tests #365

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/local_pathfinding/local_pathfinding/global_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ def get_path(file_path: str) -> Path:
return path


def post_path(path: Path) -> bool:
def post_path(path: Path, url: str = PATH_URL) -> bool:
"""Sends the global path to NET via POST request.

Args:
path (Path): The global path.
url (str): URL to post path to. Should always use default value except for tests.

Returns:
bool: Whether or not the global path was successfully posted.
Expand All @@ -160,8 +161,9 @@ def post_path(path: Path) -> bool:
data = {"waypoints": waypoints, "timestamp": timestamp}

json_data = json.dumps(data).encode("utf-8")

try:
urlopen(PATH_URL, json_data)
urlopen(url, json_data)
return True
except HTTPError as http_error:
print(f"HTTP Error: {http_error.code}")
Expand Down
5 changes: 4 additions & 1 deletion src/local_pathfinding/test/post_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer

TEST_PORT = 8085
POST_TEST_URL = "http://localhost:" + str(TEST_PORT) + "/global-path"


class CustomRequestHandler(BaseHTTPRequestHandler):
def _set_response(self, status_code=200, content_type="application/json"):
Expand All @@ -32,7 +35,7 @@ def do_POST(self):
)


def run_server(port=8081) -> HTTPServer:
def run_server(port=TEST_PORT) -> HTTPServer:
server_address = ("localhost", port)
httpd = HTTPServer(server_address, CustomRequestHandler)

Expand Down
8 changes: 4 additions & 4 deletions src/local_pathfinding/test/test_global_path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

import post_server
import post_server as ps
import pytest
from custom_interfaces.msg import HelperLatLon, Path

Expand Down Expand Up @@ -338,11 +338,11 @@ def test_post_path(global_path: Path):
"""

# Launch http server
server = post_server.run_server()
server = ps.run_server()

assert post_path(global_path), "Failed to post global path"
assert post_path(global_path, url=ps.POST_TEST_URL), "Failed to post global path"

post_server.shutdown_server(httpd=server)
ps.shutdown_server(httpd=server)


# ------------------------- TEST WRITE_TO_FILE ------------------------------
Expand Down