Skip to content
Open
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
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/kjaymiller/cookiecutter-relecloud",
"commit": "e7c6d743ed8bd795bc2fd8befda01b7980933dbb",
"commit": "0b15622bae4686ee9a3a607f19f22899425ca77e",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"files.exclude": {
".coverage": true,
".pytest_cache": true,
"__pycache__": true
"__pycache__": true,
".ruff_cache": true
},
"[python]": {
"editor.formatOnSave": true,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/azure-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.txt
python3 -m playwright install --with-deps
python3 -m playwright install chromium --with-deps
python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.txt
playwright install --with-deps
playwright install chromium --with-deps
python3 -m pip install -e src
- name: Seed data and run Pytest tests
run: |
Expand Down
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
],
"jinja": true,
"justMyCode": false
},
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"env": {"PYTEST_ADDOPTS": "--no-cov"}
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export POSTGRES_PASSWORD=<YOUR PASSWORD>
If you're running the app inside VS Code or GitHub Codespaces, you can use the "Run and Debug" button to start the app.

```sh
python3 -m flask --app src.flaskapp run --reload --port=8000
python3 -m flask --app src.flaskapp run --debug --reload --port=8000
```


Expand All @@ -56,7 +56,7 @@ python3 -m flask --app src.flaskapp run --reload --port=8000

```sh
python3 -m pip install -r requirements-dev.txt
python3 -m playwright install --with-deps
python3 -m playwright install chromium --with-deps
```

3. Run the tests:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ known-first-party = ["flaskapp"]

[tool.pytest.ini_options]
addopts = "-ra -vv"

[tool.coverage.report]
show_missing = true
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pip-tools
pytest
ephemeral-port-reserve
pytest-playwright
coverage
pytest-cov
axe-playwright-python

# Linters
ruff
4 changes: 2 additions & 2 deletions src/flaskapp/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def cruise_detail(pk: int):
)


@bp.get("/info_request/")
@bp.get("/info_request")
def info_request():
all_cruises = db.session.execute(db.select(models.Cruise)).scalars().all()

return render_template("info_request_create.html", cruises=all_cruises, message=request.args.get("message"))


@bp.post("/info_request/")
@bp.post("/info_request")
def create_info_request():
name = request.form["name"]
db_info_request = models.InfoRequest(
Expand Down
15 changes: 10 additions & 5 deletions src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
{% if prod %}
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
{% endif %}

<!--main CSS theme file -->
<link rel="stylesheet" href="{{ url_for('static', filename='res/css/theme.css') }}" />

<style>
/* Accessibility overrides */
.btn-primary {
background-color: #006ee5;
}
</style>
<!-- For new browsers - multisize ico -->
<link rel="icon" type="image/x-icon" sizes="16x16 32x32" href="{{ url_for('static', filename='res/img/favicon.ico') }}">

<!-- For iPad with high-resolution Retina display running iOS ≥ 7: -->
<link rel="apple-touch-icon" sizes="152x152" href="{{ url_for('static', filename='res/img/favicon-152-precomposed.png') }}">

<!-- For iPhone with high-resolution Retina display running iOS ≥ 7: -->
<link rel="apple-touch-icon" sizes="120x120" href="{{ url_for('static', filename='res/img/favicon-120-precomposed.png') }}">

<!-- Chrome for Android -->
<link rel="manifest" href="manifest.json">
<link rel="icon" sizes="192x192" href="{{ url_for('static', filename='res/img/favicon-192.png') }}">
Expand Down
4 changes: 2 additions & 2 deletions src/templates/info_request_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ <h1 id="page-title">Request information</h2>
<p>Fill out the form below to request information about our cruises</p>

<form method="post">
<form method="post" action="/info_request/">
<form method="post" action="/info_request">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="cruise_id">Cruise:</label>
<select name="cruise_id">
<select name="cruise_id" id="cruise_id">
{% for cruise in cruises %}
<option value="{{ cruise.id }}">{{ cruise.name }}</option>
{% endfor %}
Expand Down
15 changes: 15 additions & 0 deletions src/tests/local/test_gunicorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
from unittest import mock

import pytest
from gunicorn.app.wsgiapp import run


def test_config_imports():
argv = ["gunicorn", "--check-config", "flaskapp:create_app()", "-c", "src/gunicorn.conf.py"]

with mock.patch.object(sys, "argv", argv):
with pytest.raises(SystemExit) as excinfo:
run()

assert excinfo.value.args[0] == 0
76 changes: 76 additions & 0 deletions src/tests/local/test_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import pytest

from flaskapp import db, models


@pytest.fixture
def client(app_with_db):
return app_with_db.test_client()


def test_index(client):
response = client.get("/")

assert response.status_code == 200
assert b"Welcome to ReleCloud" in response.data


def test_about(client):
response = client.get("/about")

assert response.status_code == 200
assert b"About ReleCloud" in response.data


def test_destinations(client):
response = client.get("/destinations")

assert response.status_code == 200
assert b"Destinations" in response.data
assert b"The Sun" in response.data


def test_destination_detail(client):
response = client.get("/destination/1")

assert response.status_code == 200
assert b"The Sun" in response.data


def test_cruise_detail(client):
response = client.get("/cruise/1")

assert response.status_code == 200
assert b"The Sun and Earth" in response.data


def test_info_request(client):
response = client.get("/info_request")

assert response.status_code == 200
assert b"Request Info" in response.data


def test_create_info_request(app_with_db, client):
response = client.post(
"/info_request",
data={
"name": "Amanda Valdez",
"email": "michellewatson@gmail.com",
"notes": "Please send me more information.",
"cruise_id": "12345",
},
)

assert response.status_code == 302
assert (
response.headers["Location"]
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
)

with app_with_db.app_context():
info_request = db.session.query(models.InfoRequest).order_by(models.InfoRequest.id.desc()).first()
assert info_request.name == "Amanda Valdez"
assert info_request.email == "michellewatson@gmail.com"
assert info_request.notes == "Please send me more information."
assert info_request.cruise_id == 12345
13 changes: 13 additions & 0 deletions src/tests/local/test_playwright.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import re

import pytest
from axe_playwright_python.sync_playwright import Axe
from playwright.sync_api import Page, expect


def check_for_violations(page: Page):
results = Axe().run(page)
assert results.violations_count == 0, results.generate_report()


def test_home(page: Page, live_server_url: str):
"""Test that the home page loads"""
page.goto(live_server_url)
expect(page).to_have_title("ReleCloud - Expand your horizons")
check_for_violations(page)


@pytest.mark.parametrize(
Expand All @@ -26,19 +33,22 @@ def test_header_has_request_info(page: Page, live_server_url: str, page_title, p
# Request Info
request_info = header.get_by_role("link", name=page_title)
expect(request_info).to_have_attribute("href", re.compile(rf".*{page_url}.*"))
check_for_violations(page)


def test_request_information(page: Page, live_server_url: str):
"""Test that the request info form page loads"""
page.goto(live_server_url)
page.get_by_role("link", name="Request Information").click()
expect(page).to_have_title("ReleCloud - Request information")
check_for_violations(page)


def test_destinations(page: Page, live_server_url: str):
page.goto(live_server_url)
page.get_by_role("link", name="Destinations").click()
expect(page).to_have_title("ReleCloud - Destinations")
check_for_violations(page)


destinations = (
Expand Down Expand Up @@ -80,6 +90,7 @@ def test_destination_options(
page.get_by_role("link", name="Destinations").click()
expect(page).to_have_title("ReleCloud - Destinations")
expect(page.get_by_text(destination)).to_be_visible()
check_for_violations(page)


@pytest.mark.parametrize(
Expand All @@ -97,10 +108,12 @@ def test_destination_options_have_cruises(page: Page, live_server_url: str, dest

for page_cruise in page_cruises:
assert page_cruise.text_content() in cruises
check_for_violations(page)


def test_about(page: Page, live_server_url: str):
"""Test that the request info form page loads"""
page.goto(live_server_url)
page.get_by_role("link", name="About").click()
expect(page.locator("#page-title")).to_have_text(re.compile(r".*about.*", re.IGNORECASE))
check_for_violations(page)