-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to CI. Try to improve DX with makefile.
- Loading branch information
Showing
11 changed files
with
277 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[run] | ||
source = unicorn | ||
omit = | ||
unicorn/unicorn/wsgi.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.DEFAULT_GOAL := run | ||
|
||
init: prepare run migrate createsuperuser | ||
|
||
prepare: | ||
@cp .env.testing .env | ||
|
||
run: | ||
@docker compose up -d | ||
|
||
migrate: | ||
@docker compose exec web python unicorn/manage.py migrate | ||
|
||
createsuperuser: | ||
@echo "Creating a Django superuser. Please fill in the details:" | ||
@docker compose exec web python unicorn/manage.py createsuperuser | ||
|
||
loadseed: | ||
@docker compose exec web python unicorn/manage.py loaddata unicorn/seed.json | ||
|
||
test: | ||
@docker compose exec web coverage run unicorn/manage.py test unicorn | ||
|
||
coverage: | ||
@docker compose exec web coverage report -m | ||
@docker compose exec web coverage html -d unicorn/htmlcov | ||
@open unicorn/htmlcov/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
CREATE USER $DATABASE_USER WITH PASSWORD '$DATABASE_PASSWORD'; | ||
CREATE DATABASE $DATABASE_NAME; | ||
GRANT ALL PRIVILEGES ON DATABASE $DATABASE_NAME TO $DATABASE_USER; | ||
ALTER DATABASE $DATABASE_NAME OWNER TO $DATABASE_USER; | ||
ALTER USER $DATABASE_USER CREATEDB; | ||
CREATE SCHEMA $DATABASE_USER AUTHORIZATION $DATABASE_USER; | ||
\connect $DATABASE_NAME; | ||
ALTER ROLE $DATABASE_USER SET client_encoding TO 'utf8'; | ||
ALTER ROLE $DATABASE_USER SET default_transaction_isolation TO 'read committed'; | ||
ALTER ROLE $DATABASE_USER SET timezone TO 'UTC'; | ||
EOSQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from unittest import mock | ||
|
||
from competitions.constants import ( | ||
COMPETITION_VISIBILITY_CREW, | ||
COMPETITION_VISIBILITY_HIDDEN, | ||
COMPETITION_VISIBILITY_PUBLIC, | ||
GENRE_CATEGORY_OTHER, | ||
) | ||
from competitions.models import Competition, Genre | ||
from competitions.signals import add_competition_view_published | ||
from django.contrib.auth.models import Group | ||
from django.db.models.signals import post_save | ||
from django.test import TestCase | ||
from django.utils import timezone | ||
|
||
|
||
class AddCompetitionViewPublishedTestCase(TestCase): | ||
def setUp(self): | ||
post_save.connect(add_competition_view_published, sender=Competition) | ||
|
||
self.anon, _ = Group.objects.get_or_create(name="p-anonymous") | ||
self.crew, _ = Group.objects.get_or_create(name="p-crew") | ||
|
||
now = timezone.now() | ||
later = now + timezone.timedelta(days=1) | ||
|
||
self.genre = Genre.objects.create(category=GENRE_CATEGORY_OTHER, name="Genre") | ||
self.competition = Competition.objects.create( | ||
genre=self.genre, | ||
name="Competition", | ||
published=False, | ||
run_time_start=now, | ||
run_time_end=later, | ||
) | ||
|
||
def tearDown(self): | ||
post_save.disconnect(add_competition_view_published, sender=Competition) | ||
|
||
@mock.patch("competitions.signals.remove_perm") | ||
def test_visibility_hidden(self, mock_remove): | ||
self.competition.visibility = COMPETITION_VISIBILITY_HIDDEN | ||
self.competition.save() | ||
|
||
mock_remove.assert_any_call("view_competition", self.anon, self.competition) | ||
mock_remove.assert_any_call("view_competition", self.crew, self.competition) | ||
|
||
@mock.patch("competitions.signals.assign_perm") | ||
@mock.patch("competitions.signals.remove_perm") | ||
def test_visibility_crew(self, mock_remove, mock_assign): | ||
self.competition.visibility = COMPETITION_VISIBILITY_CREW | ||
self.competition.published = False | ||
self.competition.save() | ||
|
||
mock_remove.assert_any_call("view_competition", self.anon, self.competition) | ||
mock_remove.assert_any_call("view_competition", self.crew, self.competition) | ||
|
||
self.competition.published = True | ||
self.competition.save() | ||
|
||
mock_remove.assert_called_with("view_competition", self.anon, self.competition) | ||
mock_assign.assert_called_with("view_competition", self.crew, self.competition) | ||
|
||
@mock.patch("competitions.signals.assign_perm") | ||
@mock.patch("competitions.signals.remove_perm") | ||
def test_visibility_public(self, mock_remove, mock_assign): | ||
self.competition.visibility = COMPETITION_VISIBILITY_PUBLIC | ||
self.competition.published = False | ||
self.competition.save() | ||
|
||
mock_remove.assert_any_call("view_competition", self.crew, self.competition) | ||
mock_remove.assert_any_call("view_competition", self.anon, self.competition) | ||
|
||
self.competition.published = True | ||
self.competition.save() | ||
|
||
mock_remove.assert_called_with("view_competition", self.crew, self.competition) | ||
mock_assign.assert_called_with("view_competition", self.anon, self.competition) |
Oops, something went wrong.