Add populated homepage test

This commit is contained in:
rubenwardy
2020-01-19 15:46:29 +00:00
parent 215839c423
commit d503908a65
3 changed files with 48 additions and 21 deletions

View File

@@ -1,11 +1,26 @@
import pytest
from app import app
from app.default_data import populate_test_data
from app.models import db, License, Tag, User, UserRank
from utils import client, recreate_db
def test_homepage_ok(client):
def test_homepage_empty(client):
"""Start with a blank database."""
assert app.config["TESTING"]
rv = client.get("/")
assert b"No packages available" in rv.data and b"packagetile" not in rv.data
def test_homepage_with_contents(client):
"""Start with a test database."""
licenses = { x.name : x for x in License.query.all() }
tags = { x.name : x for x in Tag.query.all() }
admin_user = User.query.filter_by(rank=UserRank.ADMIN).first()
populate_test_data(db.session, licenses, tags, admin_user)
db.session.commit()
rv = client.get("/")
assert b"No packages available" in rv.data
assert b"No packages available" not in rv.data and b"packagetile" in rv.data