Skip to content

Commit

Permalink
Begin to set up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcadman committed Nov 18, 2024
1 parent 37eab30 commit 1d27e7b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ isort>=5.12.0
pip-audit>=2.7.0
bandit>=1.7.5
licensecheck>=2024
requests>=2.32.2
selenium>=4.13.0
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from selenium import webdriver as wd


def chrome():
options = wd.ChromeOptions()
options.add_argument("--headless=new")
return wd.Chrome(options=options)


def edge():
options = wd.EdgeOptions()
options.add_argument("--headless=new")
return wd.Edge(options=options)


def firefox():
options = wd.FirefoxOptions()
options.add_argument("-headless")
return wd.Firefox(options=options)


@pytest.fixture(params=[chrome, edge, firefox])
def driver(request):
with request.param() as _driver:
yield _driver
36 changes: 5 additions & 31 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
import requests

from webapp_python.main import RESPONSE_HEADERS
from selenium.webdriver.remote.webdriver import BaseWebDriver

from .server import get_server_url

# TODO: Use selenium


def test_main():
def test_main(driver: BaseWebDriver):
with get_server_url() as webapp_url:
response = requests.get(f"{webapp_url}", timeout=60)
assert response.status_code == 200
for key, val in RESPONSE_HEADERS.items():
assert response.headers[key] == val
assert "24/7 Bishops" in response.text
response = requests.get(f"{webapp_url}/favicon.png?v=1729", timeout=60)
assert response.status_code == 200
for key, val in RESPONSE_HEADERS.items():
assert response.headers[key] == val
response = requests.get(f"{webapp_url}/css/main.css", timeout=60)
assert response.status_code == 200
for key, val in RESPONSE_HEADERS.items():
assert response.headers[key] == val
assert "background-color: green" in response.text
driver.get(webapp_url)


def test_maint():
def test_maint(driver: BaseWebDriver):
with get_server_url(maintenance_mode=True) as webapp_url:
response = requests.get(f"{webapp_url}", timeout=60)
assert response.status_code == 503
assert "24/7 Bishops is Temporarily Unavailable" in response.text
for key, val in RESPONSE_HEADERS.items():
assert response.headers[key] == val
response = requests.post(f"{webapp_url}/random_path", timeout=60)
assert response.status_code == 503
assert "24/7 Bishops is Temporarily Unavailable" in response.text
for key, val in RESPONSE_HEADERS.items():
assert response.headers[key] == val
driver.get(webapp_url)
1 change: 1 addition & 0 deletions webapp_python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def internal_javascript(file):
except FileNotFoundError:
return NotFound()


@app.route("/images/<file>")
def internal_images(file):
try:
Expand Down

0 comments on commit 1d27e7b

Please sign in to comment.