Skip to content
Draft
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: 2 additions & 0 deletions src/makeitso/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class PytestConfig(LocalConfig):
SECRET_KEY = "pytest"
# Fixed name, so tests never wipe the real database
SQLALCHEMY_DATABASE_URI = _database_uri("mis_test")
# Disable CSRF so we can run post() requests
WTF_CSRF_ENABLED = False


configs = {
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def client(app):
return app.test_client()


@pytest.fixture
def logged_in_client(app):
client = app.test_client()

with client.session_transaction() as session:
session["user"] = {"login": "testuser", "avatar_url": ""}

return client


# Empty every table after each test, so tests don't see each other's rows
@pytest.fixture(autouse=True)
def clean_db(app):
Expand Down
41 changes: 41 additions & 0 deletions tests/stacks/test_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from unittest.mock import MagicMock, patch

from makeitso.extensions import db
from makeitso.models.stack import Stack


def test_new(logged_in_client):
response = logged_in_client.get("/stacks/new")
assert response.status_code == 200

assert b"New stack" in response.data
assert b"Create stack" in response.data


def test_new_create(
logged_in_client,
):
with (
patch("makeitso.stacks.views.new.enqueue_sync") as mock_enqueue_sync,
patch("flask_wtf.form.FlaskForm.validate_on_submit") as mock_validate,
):
mock_validate.return_value = True

data = {
"organization": "test-org",
"repository": "test-repo",
"branch": "test-branch",
"environment": "testing-test",
"continuous_deploy": False,
}

response = logged_in_client.post("/stacks/new", data=data)

new_stack: Stack = db.session.execute(
db.select(Stack).filter_by(repository="test-repo")
).scalar_one()

Stack.repository

assert response.status_code == 302
assert response.headers["Location"] == f"/stacks/{new_stack.id}"
Loading