Skip to content

Commit

Permalink
added integration test with live test server
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Dec 28, 2023
1 parent 54578b3 commit c65040a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
10 changes: 6 additions & 4 deletions osbot_fast_api/utils/Fast_API_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests
from threading import Thread
from fastapi import FastAPI
from osbot_utils.utils.Http import wait_for_port, wait_for_port_closed
from osbot_utils.utils.Http import wait_for_port, wait_for_port_closed, is_port_open
from uvicorn import Config, Server
from osbot_utils.utils.Misc import random_port

Expand All @@ -20,6 +20,9 @@ def __init__(self, app, port=None, log_level=None):
self.server : Server = None
self.thread : Thread = None

def is_port_open(self):
return is_port_open(host=FAST_API__HOST, port=self.port)

def start(self):
self.server = Server(config=self.config)

Expand All @@ -36,10 +39,9 @@ def stop(self):
self.thread.join()
return wait_for_port_closed(host=FAST_API__HOST, port=self.port)

def url(self):
return f'http://{FAST_API__HOST}:{self.port}/'

def requests_get(self, path=''):
url = urljoin(self.url(), path)
return requests.get(url)

def url(self):
return f'http://{FAST_API__HOST}:{self.port}/'
26 changes: 22 additions & 4 deletions tests/integration/api/test_integration__Fast_API.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
from unittest import TestCase

from osbot_utils.utils.Dev import pprint
from osbot_utils.utils.Http import is_port_open

from osbot_fast_api.api.Fast_API import Fast_API
from osbot_fast_api.utils.Fast_API_Server import Fast_API_Server
from osbot_fast_api.utils.Version import Version


class test_integration__Fast_API(TestCase):
def setUp(self):
self.fast_api = Fast_API()
fast_api : Fast_API
fast_api_server : Fast_API_Server

def test_app(self):
pprint('here')
@classmethod
def setUpClass(cls) -> None:
cls.fast_api = Fast_API()
cls.fast_api_server = Fast_API_Server(app=cls.fast_api.app())
cls.fast_api_server.start()
assert cls.fast_api_server.is_port_open() is True

@classmethod
def tearDownClass(cls) -> None:
cls.fast_api_server.stop()
assert cls.fast_api_server.is_port_open() is False


def test_version(self):
response = self.fast_api_server.requests_get('/status/version')
assert response.status_code == 200
assert response.json() == {'version': Version().value() }

0 comments on commit c65040a

Please sign in to comment.