]> git.lizzy.rs Git - cheatdb.git/commitdiff
Add populated homepage test
authorrubenwardy <rw@rubenwardy.com>
Sun, 19 Jan 2020 15:46:29 +0000 (15:46 +0000)
committerrubenwardy <rw@rubenwardy.com>
Sun, 19 Jan 2020 15:46:29 +0000 (15:46 +0000)
app/default_data.py
app/templates/macros/packagegridtile.html
app/tests/test_homepage.py

index 9898008d96377c79e546f7c715b647be57754a27..6c0fdad2e4e9a2cff6bb1212881e5566a2b86102 100644 (file)
@@ -3,13 +3,13 @@ from .utils import make_flask_user_password
 
 
 def populate(session):
-       ruben = User("rubenwardy")
-       ruben.active = True
-       ruben.password = make_flask_user_password("tuckfrump")
-       ruben.github_username = "rubenwardy"
-       ruben.forums_username = "rubenwardy"
-       ruben.rank = UserRank.ADMIN
-       session.add(ruben)
+       admin_user = User("rubenwardy")
+       admin_user.active = True
+       admin_user.password = make_flask_user_password("tuckfrump")
+       admin_user.github_username = "rubenwardy"
+       admin_user.forums_username = "rubenwardy"
+       admin_user.rank = UserRank.ADMIN
+       session.add(admin_user)
 
        tags = {}
        for tag in ["Inventory", "Mapgen", "Building", \
@@ -41,7 +41,7 @@ def populate_test_data(session, licenses, tags, admin_user):
        ez.rank = UserRank.EDITOR
        session.add(ez)
 
-       not1 = Notification(ruben, ez, "Awards approved", "/packages/rubenwardy/awards/")
+       not1 = Notification(admin_user, ez, "Awards approved", "/packages/rubenwardy/awards/")
        session.add(not1)
 
        jeija = User("Jeija")
@@ -55,8 +55,9 @@ def populate_test_data(session, licenses, tags, admin_user):
        mod.name = "alpha"
        mod.title = "Alpha Test"
        mod.license = licenses["MIT"]
+       mod.media_license = licenses["MIT"]
        mod.type = PackageType.MOD
-       mod.author = ruben
+       mod.author = admin_user
        mod.tags.append(tags["mapgen"])
        mod.tags.append(tags["environment"])
        mod.repo = "https://github.com/ezhh/other_worlds"
@@ -78,8 +79,9 @@ def populate_test_data(session, licenses, tags, admin_user):
        mod1.name = "awards"
        mod1.title = "Awards"
        mod1.license = licenses["LGPLv2.1"]
+       mod1.media_license = licenses["MIT"]
        mod1.type = PackageType.MOD
-       mod1.author = ruben
+       mod1.author = admin_user
        mod1.tags.append(tags["player_effects"])
        mod1.repo = "https://github.com/rubenwardy/awards"
        mod1.issueTracker = "https://github.com/rubenwardy/awards/issues"
@@ -115,6 +117,7 @@ awards.register_achievement("award_mesefind",{
        mod2.tags.append(tags["tools"])
        mod2.type = PackageType.MOD
        mod2.license = licenses["LGPLv3"]
+       mod2.media_license = licenses["MIT"]
        mod2.author = jeija
        mod2.repo = "https://github.com/minetest-mods/mesecons/"
        mod2.issueTracker = "https://github.com/minetest-mods/mesecons/issues"
@@ -201,6 +204,7 @@ No warranty is provided, express or implied, for any part of the project.
        mod.name = "handholds"
        mod.title = "Handholds"
        mod.license = licenses["MIT"]
+       mod.media_license = licenses["MIT"]
        mod.type = PackageType.MOD
        mod.author = ez
        mod.tags.append(tags["player_effects"])
@@ -223,6 +227,7 @@ No warranty is provided, express or implied, for any part of the project.
        mod.name = "other_worlds"
        mod.title = "Other Worlds"
        mod.license = licenses["MIT"]
+       mod.media_license = licenses["MIT"]
        mod.type = PackageType.MOD
        mod.author = ez
        mod.tags.append(tags["mapgen"])
@@ -239,15 +244,15 @@ No warranty is provided, express or implied, for any part of the project.
        mod.name = "food"
        mod.title = "Food"
        mod.license = licenses["LGPLv2.1"]
+       mod.media_license = licenses["MIT"]
        mod.type = PackageType.MOD
-       mod.author = ruben
+       mod.author = admin_user
        mod.tags.append(tags["player_effects"])
        mod.repo = "https://github.com/rubenwardy/food/"
        mod.issueTracker = "https://github.com/rubenwardy/food/issues/"
        mod.forums = 2960
        mod.short_desc = "Adds lots of food and an API to manage ingredients"
        mod.desc = "This is the long desc"
-       food = mod
        session.add(mod)
 
        mod = Package()
@@ -255,8 +260,9 @@ No warranty is provided, express or implied, for any part of the project.
        mod.name = "food_sweet"
        mod.title = "Sweet Foods"
        mod.license = licenses["CC0"]
+       mod.media_license = licenses["MIT"]
        mod.type = PackageType.MOD
-       mod.author = ruben
+       mod.author = admin_user
        mod.tags.append(tags["player_effects"])
        mod.repo = "https://github.com/rubenwardy/food_sweet/"
        mod.issueTracker = "https://github.com/rubenwardy/food_sweet/issues/"
@@ -272,7 +278,8 @@ No warranty is provided, express or implied, for any part of the project.
        game1.title = "Capture The Flag"
        game1.type = PackageType.GAME
        game1.license = licenses["LGPLv2.1"]
-       game1.author = ruben
+       game1.media_license = licenses["MIT"]
+       game1.author = admin_user
        game1.tags.append(tags["pvp"])
        game1.tags.append(tags["survival"])
        game1.tags.append(tags["multiplayer"])
@@ -301,8 +308,9 @@ Uses the CTF PvP Engine.
        mod.name = "pixelbox"
        mod.title = "PixelBOX Reloaded"
        mod.license = licenses["CC0"]
+       mod.media_license = licenses["MIT"]
        mod.type = PackageType.TXP
-       mod.author = ruben
+       mod.author = admin_user
        mod.forums = 14132
        mod.short_desc = "This is an update of the original PixelBOX texture pack by the brillant artist Gambit"
        mod.desc = "This is the long desc"
@@ -315,6 +323,8 @@ Uses the CTF PvP Engine.
        rel.approved = True
        session.add(rel)
 
+       session.commit()
+
        metas = {}
        for package in Package.query.filter_by(type=PackageType.MOD).all():
                meta = None
index 9f70c1c2bde1715e3c840a2c3cfabbd2a603b578..3fb39a8f406b1708ff931d84697dc7d62d473e11 100644 (file)
                {% else %}
                        <li><i>No packages available</i></ul>
                {% endfor %}
-               {% for i in range(4) %}
-                       <li class="packagetile flex-fill"></li>
-               {% endfor %}
+               {% if packages %}
+                       {% for i in range(4) %}
+                               <li class="packagetile flex-fill"></li>
+                       {% endfor %}
+               {% endif %}
        </ul>
 {% endmacro %}
index f0f67930b4ee5b15c50fc7fc610bc89612045735..2bfdbca1d1f55046b5246dfa31c6a4237c4dd39d 100644 (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