Browse Source

Use GitHub actions (#295)

pull/296/head
rubenwardy 1 year ago committed by GitHub
parent
commit
dcc34570d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      .github/workflows/test.yml
  2. 22
      .gitlab-ci.yml
  3. 2
      README.md
  4. 2
      app/default_data.py
  5. 4
      app/models/packages.py
  6. 1
      app/tests/__init__.py
  7. 10
      app/tests/test_api.py
  8. 5
      app/tests/test_homepage.py
  9. 0
      utils/ci/config.cfg
  10. 0
      utils/ci/config.env

21
.github/workflows/test.yml

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Copy config
run: cp utils/ci/* .
- name: Build the Docker image
run: docker-compose build
- name: Start Docker
run: docker-compose up -d
- name: Run migrations
run: ./utils/run_migrations.sh
- name: Run tests
run: ./utils/tests_cov.sh
- name: Stop Docker
run: docker-compose down

22
.gitlab-ci.yml

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
image: docker/compose
services:
- docker:dind
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- /var/lib/docker
# build:
# stage: build
# script:
# - cp utils/gitlabci/* .
# - docker-compose build
UI_Test:
stage: test
script:
- cp utils/gitlabci/* .
- docker-compose up -d
- ./utils/run_migrations.sh
- ./utils/tests_cov.sh
- docker-compose down

2
README.md

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
# Content Database
[![Build status](https://gitlab.com/minetest/contentdb/badges/master/pipeline.svg)](https://gitlab.com/minetest/contentdb/pipelines)
![Build Status](https://github.com/minetest/contentdb/workflows/test/badge.svg)
Content database for Minetest mods, games, and more.\
Developed by rubenwardy, license AGPLv3.0+.

2
app/default_data.py

@ -53,7 +53,7 @@ def populate_test_data(session): @@ -53,7 +53,7 @@ def populate_test_data(session):
ez.rank = UserRank.EDITOR
session.add(ez)
not1 = Notification(admin_user, ez, "Awards approved", "/packages/rubenwardy/awards/")
not1 = Notification(admin_user, ez, NotificationType.PACKAGE_APPROVAL, "Awards approved", "/packages/rubenwardy/awards/")
session.add(not1)
jeija = User("Jeija")

4
app/models/packages.py

@ -795,7 +795,9 @@ class MinetestRelease(db.Model): @@ -795,7 +795,9 @@ class MinetestRelease(db.Model):
return release
if protocol_num:
return MinetestRelease.query.filter_by(protocol=protocol_num).first()
# Find the closest matching release
return MinetestRelease.query.order_by(db.desc(MinetestRelease.protocol)) \
.filter(MinetestRelease.protocol <= protocol_num).first()
return None

1
app/tests/__init__.py

@ -0,0 +1 @@ @@ -0,0 +1 @@
# This makes app/tests a package

10
app/tests/test_api.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
from app.default_data import populate_test_data
from app.models import db, Package, PackageState
from utils import parse_json, is_str, is_int, is_optional
from .utils import is_str, is_int, is_optional, parse_json
from .utils import client # noqa
def validate_package_list(packages, strict=False):
@ -73,14 +74,15 @@ def test_packages_with_protocol_high(client): @@ -73,14 +74,15 @@ def test_packages_with_protocol_high(client):
populate_test_data(db.session)
db.session.commit()
rv = client.get("/api/packages/?protocol_version=40")
rv = client.get("/api/packages/?protocol_version=100")
packages = parse_json(rv.data)
assert len(packages) == 4
for package in packages:
assert package["name"] != "mesecons"
assert package["name"] != "handholds"
assert len(packages) == 4
validate_package_list(packages, True)

5
app/tests/test_homepage.py

@ -1,12 +1,13 @@ @@ -1,12 +1,13 @@
from app.default_data import populate_test_data
from app.models import db
from .utils import client # noqa
def test_homepage_empty(client):
"""Start with a blank database."""
rv = client.get("/")
assert b"No packages available" in rv.data and b"packagetile" not in rv.data
assert b"No packages available" in rv.data and b"packagegridscrub" not in rv.data
def test_homepage_with_contents(client):
@ -17,4 +18,4 @@ def test_homepage_with_contents(client): @@ -17,4 +18,4 @@ def test_homepage_with_contents(client):
rv = client.get("/")
assert b"No packages available" not in rv.data and b"packagetile" in rv.data
assert b"packagegridscrub" in rv.data

0
utils/gitlabci/config.cfg → utils/ci/config.cfg

0
utils/gitlabci/config.env → utils/ci/config.env

Loading…
Cancel
Save