Skip to content

Commit

Permalink
test: test from is resend on missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes1803 committed Dec 13, 2023
1 parent c26595c commit 77c1a9f
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion tests/unit/app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import Session

from in_concert.app.app_factory import AppFactory
from in_concert.app.models import Venue
from in_concert.app.models import Band, Venue


class TestApp:
Expand Down Expand Up @@ -156,3 +156,46 @@ def test_get_venue_should_return_venue(self, client_no_auth_checks, existing_ven
def test_get_venue_should_return_404_if_venue_not_existing(self, client_no_auth_checks):
response = client_no_auth_checks.get("/venues/123")
assert response.status_code == 404

def test_post_band_should_create_band_in_db(self, client_no_auth_checks, db_session: Session, bearer_token):
client_no_auth_checks.cookies = {"access_token": f'Bearer {bearer_token["access_token"]}'}
response = client_no_auth_checks.post(
"/bands",
data={
"name": "band name",
"city": "band city",
"state": "band state",
"zip_code": 12345,
"website": "band website",
"image_link": "band image link",
"genres": "band genres",
},
)
band_id = response.json()["id"]

with db_session:
band = db_session.get(Band, band_id)
assert band

def test_post_band_with_missing_data_should_resend_form(self, client_no_auth_checks, bearer_token):
client_no_auth_checks.cookies = {"access_token": f'Bearer {bearer_token["access_token"]}'}
response = client_no_auth_checks.post(
"/bands",
# missing name
data={
"city": "band city",
"state": "band state",
"zip_code": 12345,
"website": "band website",
"image_link": "band image link",
"genres": "band genres",
},
)
assert response.status_code == 200

html_response = response.content.decode(response.charset_encoding)
# test previous user input is saved in form if validation fails
assert 'value="band city"' in html_response


#

0 comments on commit 77c1a9f

Please sign in to comment.