contentdb/app/tests/integ/test_api.py

78 lines
2.2 KiB
Python
Raw Normal View History

2023-06-19 20:32:36 +02:00
# ContentDB
# Copyright (C) rubenwardy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2020-01-19 20:09:04 +01:00
from app.default_data import populate_test_data
2020-12-04 03:23:04 +01:00
from app.models import db, Package, PackageState
from .utils import parse_json, validate_package_list
2021-05-03 18:59:23 +02:00
from .utils import client # noqa
2020-12-04 03:23:04 +01:00
2020-01-19 20:09:04 +01:00
def test_packages_empty(client):
"""Start with a blank database."""
rv = client.get("/api/packages/")
assert parse_json(rv.data) == []
def test_packages_with_contents(client):
"""Start with a test database."""
populate_test_data(db.session)
db.session.commit()
rv = client.get("/api/packages/")
packages = parse_json(rv.data)
assert len(packages) > 0
assert len(packages) == Package.query.filter_by(state=PackageState.APPROVED).count()
2020-01-19 20:09:04 +01:00
validate_package_list(packages)
# def test_packages_with_query(client):
# """Start with a test database."""
#
# populate_test_data(db.session)
# db.session.commit()
#
# rv = client.get("/api/packages/?q=food")
#
# packages = parse_json(rv.data)
#
# assert len(packages) == 2
#
# validate_package_list(packages)
#
# assert (packages[0]["name"] == "food" and packages[1]["name"] == "food_sweet") or \
# (packages[1]["name"] == "food" and packages[0]["name"] == "food_sweet")
2021-05-03 19:47:19 +02:00
def test_dependencies(client):
"""Start with a test database."""
populate_test_data(db.session)
db.session.commit()
deps = parse_json(client.get("/api/packages/rubenwardy/food_sweet/dependencies/").data)
deps = deps["rubenwardy/food_sweet"]
assert len(deps) == 1
assert not deps[0]["is_optional"]
assert len(deps[0]["packages"]) == 1
assert deps[0]["packages"][0] == "rubenwardy/food"