import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By


server = "localhost"
port = 5000

base_url = f"http://{server}{':%d' %  port if port else '' }"

docs_url = f"{base_url}/docs"


class BaseFunctionnalTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Firefox()
        cls.addClassCleanup(cls.driver.quit)

    def test_app_homepage_is_reachale(self):
        self.driver.get(base_url)

    def test_app_has_swagger_documentation(self):
        swagger_header_content = "FastAPI 0.1.0 OAS 3.1"

        self.driver.get(docs_url)

        swagger = self.driver.find_elements(By.ID, "swagger-ui")[0]
        assert swagger_header_content in swagger.text.replace("\n", "")
