Verified Commit 96e2d776 authored by Joren Vrancken's avatar Joren Vrancken
Browse files

Move coverage.py settings to pyproject.toml

parent bb016ab6
......@@ -41,20 +41,18 @@ django-tests:
- git log -1
- poetry install --no-interaction
script:
- cd website
- poetry run python manage.py check
- poetry run python manage.py templatecheck --project-only
- poetry run python manage.py makemigrations --no-input --check --dry-run
- poetry run python -Wall -mcoverage run manage.py test
- coverage report --fail-under=100 --omit registrations/urls.py registrations/**.py
- coverage report --fail-under=100 --omit payments/urls.py payments/**.py
- poetry run python website/manage.py check
- poetry run python website/manage.py templatecheck --project-only
- poetry run python website/manage.py makemigrations --no-input --check --dry-run
- poetry run coverage run website/manage.py test website/
- coverage report --fail-under=100 --omit website/registrations/urls.py website/registrations/**.py
- coverage report --fail-under=100 --omit website/payments/urls.py website/payments/**.py
- coverage report
after_script:
- cd website
- coverage html --directory=covhtml --title="${CI_COMMIT_REF_SLUG} Coverage Report"
artifacts:
paths:
- website/covhtml/
- covhtml
docs tests:
stage: test
......@@ -121,7 +119,7 @@ coverage deploy:
before_script:
- "pip install awscli"
script:
- "aws s3 sync --only-show-errors website/covhtml s3://thalia-coverage/${CI_COMMIT_REF_SLUG}/"
- "aws s3 sync --only-show-errors covhtml s3://thalia-coverage/${CI_COMMIT_REF_SLUG}/"
docs deploy:
stage: "deploy"
......
......@@ -33,11 +33,11 @@ If you want to integrate `black` with your editor look in the [`black` docs](htt
There are a range of tests that can be run:
poetry run python manage.py check
poetry run python manage.py templatecheck --project-only
poetry run python manage.py makemigrations --no-input --check --dry-run
poetry run python -mcoverage run --branch --source '.' manage.py test
coverage report
poetry run python website/manage.py check
poetry run python website/manage.py templatecheck --project-only
poetry run python website/manage.py makemigrations --no-input --check --dry-run
poetry run coverage run website/manage.py test website/
poetry run coverage report
poetry
------
......
......@@ -43,6 +43,17 @@ Faker = "4.0"
coverage = "5.0.3"
black = "19.10b0"
[tool.coverage.run]
branch = true
source = ["website"]
omit = ["website/manage.py", "website/thaliawebsite/wsgi.py", "website/thaliawebsite/settings/*", "website/*/migrations/*", "website/*/test*"]
[tool.coverage.report]
precision = 2
skip_covered = true
show_missing = true
fail_under = 65.0
[tool.black]
exclude = '(/(\.eggs|\.git|\.tox)/|migrations)'
......
[run]
branch = True
omit =
*/migrations/*
*/tests.py
*/tests_*
*/tests/*
*/urls.py
*/settings/*
*/wsgi.py
manage.py
source = .
[report]
precision = 2
skip_covered = True
show_missing = True
fail_under = 65
......@@ -6,11 +6,11 @@ Use ``python ./manage.py help`` for more info.
import os
import sys
if __name__ == "__main__": # pragma: no branch
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thaliawebsite.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc: # pragma: no cover
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
......
import os
from io import BytesIO
from zipfile import ZipFile
from django.conf import settings
from django.test import Client, TestCase, override_settings
from members.models import Member
......@@ -31,7 +34,9 @@ class AlbumUploadTest(TestCase):
self.client.force_login(self.member)
def test_album_upload(self):
output_file = create_zip(["photos/fixtures/thom_assessor.png"])
output_file = create_zip(
[os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png")]
)
self.client.post(
"/admin/photos/album/add/",
{
......@@ -72,7 +77,9 @@ class AlbumUploadTest(TestCase):
self.assertEqual(Album.objects.all().count(), 1)
def test_album_upload_same_photo_twice_in_album(self):
output_file = create_zip(["photos/fixtures/thom_assessor.png"])
output_file = create_zip(
[os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png")]
)
self.client.post(
"/admin/photos/album/add/",
{
......@@ -102,7 +109,9 @@ class AlbumUploadTest(TestCase):
self.assertEqual(Photo.objects.all().count(), 1)
def test_album_upload_different_photo_in_album(self):
output_file = create_zip(["photos/fixtures/thom_assessor.png"])
output_file = create_zip(
[os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png")]
)
self.client.post(
"/admin/photos/album/add/",
{
......@@ -115,7 +124,9 @@ class AlbumUploadTest(TestCase):
follow=True,
)
output_file = create_zip(["photos/fixtures/janbeleid-hoe.jpg"])
output_file = create_zip(
[os.path.join(settings.BASE_DIR, "photos/fixtures/janbeleid-hoe.jpg")]
)
pk = Album.objects.first().pk
self.client.post(
"/admin/photos/album/{}/change/".format(pk),
......@@ -133,7 +144,9 @@ class AlbumUploadTest(TestCase):
self.assertEqual(Photo.objects.all().count(), 2)
def test_album_upload_rotated_photo_in_album(self):
output_file = create_zip(["photos/fixtures/rotated_janbeleid.jpg"])
output_file = create_zip(
[os.path.join(settings.BASE_DIR, "photos/fixtures/rotated_janbeleid.jpg")]
)
self.client.post(
"/admin/photos/album/add/",
{
......
import os
from PIL import Image
from django.test import Client, TestCase, RequestFactory, override_settings
from django.utils.datetime_safe import datetime
from django.conf import settings
from freezegun import freeze_time
from members.models import Member, Membership
......@@ -144,6 +149,9 @@ class DetermineRotationTest(TestCase):
orientations = [0, 0, 180, 180, 90, 90, 270, 270]
for i in range(1, 9):
with self.subTest(orentation=i):
with open("photos/fixtures/poker_{}.jpg".format(i), "rb") as f:
with open(
os.path.join(settings.BASE_DIR, f"photos/fixtures/poker_{i}.jpg"),
"rb",
) as f:
rot = photo_determine_rotation(Image.open(f))
self.assertEqual(orientations[i - 1], rot)
import os
from datetime import date
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import Client, TestCase, override_settings
from django.urls import reverse
from django.conf import settings
from members.models import Member, Membership
from photos.models import Album, Photo
......@@ -168,7 +171,10 @@ class AlbumTest(TestCase):
)
for i in range(10):
with open("photos/fixtures/thom_assessor.png", "rb") as f:
with open(
os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png"),
"rb",
) as f:
fi = SimpleUploadedFile(
name="photo{}.png".format(i),
content=f.read(),
......@@ -226,7 +232,10 @@ class SharedAlbumTest(TestCase):
def test_get(self):
for i in range(10):
with open("photos/fixtures/thom_assessor.png", "rb") as f:
with open(
os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png"),
"rb",
) as f:
fi = SimpleUploadedFile(
name="photo{}.png".format(i),
content=f.read(),
......@@ -264,7 +273,9 @@ class DownloadTest(TestCase):
slug="test_album",
)
with open("photos/fixtures/thom_assessor.png", "rb") as f:
with open(
os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png"), "rb"
) as f:
fi = SimpleUploadedFile(
name="photo.png", content=f.read(), content_type="image/png"
)
......@@ -307,7 +318,9 @@ class SharedDownloadTest(TestCase):
slug="test_album",
)
with open("photos/fixtures/thom_assessor.png", "rb") as f:
with open(
os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png"), "rb"
) as f:
fi = SimpleUploadedFile(
name="photo.png", content=f.read(), content_type="image/png"
)
......@@ -358,7 +371,9 @@ class AlbumDownloadTest(TestCase):
slug="test_album",
)
with open("photos/fixtures/thom_assessor.png", "rb") as f:
with open(
os.path.join(settings.BASE_DIR, "photos/fixtures/thom_assessor.png"), "rb"
) as f:
fi = SimpleUploadedFile(
name="photo.png", content=f.read(), content_type="image/png"
)
......
......@@ -6,6 +6,7 @@ from django.core.files import File
from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from django.conf import settings
from .models import Thabloid
......@@ -15,7 +16,12 @@ tmp_MEDIA_ROOT = tempfile.mkdtemp()
@override_settings(MEDIA_ROOT=tmp_MEDIA_ROOT)
class TestThabloid(TestCase):
def setUp(self):
with open("thabloid/fixtures/thabloid-1998-1999-1.pdf", "rb") as f:
with open(
os.path.join(
settings.BASE_DIR, "thabloid/fixtures/thabloid-1998-1999-1.pdf"
),
"rb",
) as f:
self.thabloid = Thabloid(year=1998, issue=1, file=File(f))
# we should wait for gs to be done before we can do cleanup
self.thabloid.save(wait=True)
......
......@@ -27,11 +27,11 @@ except ImportError:
pass
# Load production settings if DJANGO_PRODUCTION is set
if os.environ.get("DJANGO_PRODUCTION"): # pragma: nocover
if os.environ.get("DJANGO_PRODUCTION"):
from .production import *
# Load testing settings if GITLAB_CI is set
if os.environ.get("GITLAB_CI"): # pragma: nocover
if os.environ.get("GITLAB_CI"):
from .testing import *
if FIREBASE_CREDENTIALS != {}:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment