Skip to content

Commit

Permalink
Cruft update
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox committed Dec 12, 2023
1 parent 46d1b91 commit 3618c15
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"template": "https://github.com/kjaymiller/cookiecutter-relecloud",
"commit": "f86115e94dda2639d5678dad3a3232bacf583af2",
"checkout": "picklefix",
"commit": "c8fa43e87b3fa4fafa5a1a718e3f81d377865247",
"checkout": null,
"context": {
"cookiecutter": {
"project_name": "azure",
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
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pip-tools
pytest
ephemeral-port-reserve
pytest-playwright
coverage
pytest-cov

# 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: 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": "[email protected]",
"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 == "[email protected]"
assert info_request.notes == "Please send me more information."
assert info_request.cruise_id == 12345

0 comments on commit 3618c15

Please sign in to comment.