diff --git a/.coveragerc b/.coveragerc index 33c4d45..1c85306 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,4 @@ [run] source = unicorn +omit = + unicorn/unicorn/wsgi.py \ No newline at end of file diff --git a/.env.development b/.env.testing similarity index 82% rename from .env.development rename to .env.testing index a0a0c7d..0bd9d45 100644 --- a/.env.development +++ b/.env.testing @@ -1,8 +1,8 @@ -SECRET_KEY="n0zdo8!t*rU9_KfHAlsOEJ^VuX6WB)NP5IFT43$Seg=#(QmYRD" +SECRET_KEY="insecure-key-jN?b3Gb+h|HTRwI6~1Vi5v4ZI2r8|m::MrInqKzz][I/" DATABASE_HOST=db -DATABASE_NAME=postgres -DATABASE_USER=postgres -DATABASE_PASSWORD=postgres +DATABASE_NAME=unicorn +DATABASE_USER=unicorn +DATABASE_PASSWORD="insecure-password-0sy3wBnJs.#%@h2TrDsy?I*p#wU+MV" DEBUG=somethingtruethy REDIS_CONNECTION=redis://cache:6379/1 diff --git a/.github/workflows/build-backend.yml b/.github/workflows/build-backend.yml index 5517dd3..44d7189 100644 --- a/.github/workflows/build-backend.yml +++ b/.github/workflows/build-backend.yml @@ -7,7 +7,7 @@ on: branches: ["main"] env: - PYTHON_VERSION: "3.10" + PYTHON_VERSION: "3.11" POETRY_VERSION: "1.7.1" # Remember to also update in pyproject.toml IMAGE_NAME: unicorn-backend @@ -32,8 +32,65 @@ jobs: - name: Execute Pre-Commit run: pre-commit run --show-diff-on-failure --color=always --all-files + test: + runs-on: ubuntu-latest + + env: + DATABASE_USER: unicorn + DATABASE_NAME: unicorn + DATABASE_PASSWORD: insecure-password-0sy3wBnJs.#%@h2TrDsy?I*p#wU+MV + POSTGRES_USER: postgres + POSTGRES_PASSWORD: insecure-password-1KUkde2hxN4d3AvxhDsOkdsQTh4LE53c + + services: + db: + image: postgres:15 + env: + POSTGRES_USER: ${{ env.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} + DATABASE_USER: ${{ env.DATABASE_USER }} + DATABASE_NAME: ${{ env.DATABASE_NAME }} + DATABASE_PASSWORD: ${{ env.DATABASE_PASSWORD }} + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + --name test_db + ports: + - 5432:5432 + + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Run database initialization script + run: docker exec -i test_db /bin/bash < scripts/dbinit/initialize-database.sh + - name: Set up python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: ${{ env.POETRY_VERSION }} + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: v1-venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + run: poetry install --no-interaction --no-root + - name: Set pythonpath + run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV + - name: Test + run: DATABASE_HOST=localhost poetry run python unicorn/manage.py test unicorn + build: - needs: [validate] + needs: [validate, test] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e374352 --- /dev/null +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index f9973a5..fe675ca 100644 --- a/README.md +++ b/README.md @@ -3,27 +3,29 @@ ## Running locally (with Docker 🐳) +TL;DR: run `make init` the first time. + Before running, make sure to create and populate local environment variables. You can copy the provided example file and then modifying default or adding values to blank settings. ``` -cp .env.example .env +make prepare ``` Then, in order to start the development stack, run the following command: ``` -docker-compose up -d +make run ``` When running for the first time, or after clearing the database, remember to run the following commands as well: ``` -docker-compose exec web python unicorn/manage.py migrate -docker-compose exec web python unicorn/manage.py createsuperuser +make migrate +make createsuperuser ``` You should now be able to access the application at http://localhost:8000/ Some apps may also provide seed data. This can be loaded by running the following command with appropriate adjustments to the last argument. ``` -docker-compose exec web python unicorn/manage.py loaddata unicorn/seed.json +make loadseed ``` @@ -33,6 +35,8 @@ Ensure you have `pre-commit` installed - `brew install pre-commit` (or replace b Run `pre-commit install` to have it check your staged changes before allowing you to commit. To skip the pre-commit checks (usually not recommended, but helpful when you'd want to save WIP or similar), use `git commit --no-verify`. +Also, make sure to check that tests are passing with `make test`. Coverage can optionally be checked with `make coverage`. + # Authentication providers ## Keycloak diff --git a/docker-compose.yml b/docker-compose.yml index b808b86..a3349f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,23 @@ -version: '3.7' +version: "3.7" services: db: - image: postgres:14-alpine + image: postgres:15-alpine ports: - - "127.0.0.1:5432:5432" + - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data/ + - ./scripts/dbinit/:/docker-entrypoint-initdb.d/ environment: - POSTGRES_PASSWORD=postgres + env_file: .env + restart: unless-stopped cache: image: redis:alpine ports: - - "127.0.0.1:6379:6379" + - "6379:6379" + restart: unless-stopped web: build: @@ -23,10 +27,11 @@ services: volumes: - ./unicorn:/app/unicorn ports: - - "127.0.0.1:8000:8000" + - "8000:8000" depends_on: - db + - cache env_file: .env volumes: - postgres_data: \ No newline at end of file + postgres_data: diff --git a/poetry.lock b/poetry.lock index 291e0d6..2f6c1dc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -298,6 +298,70 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "coverage" +version = "7.4.0" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "coverage-7.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:36b0ea8ab20d6a7564e89cb6135920bc9188fb5f1f7152e94e8300b7b189441a"}, + {file = "coverage-7.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0676cd0ba581e514b7f726495ea75aba3eb20899d824636c6f59b0ed2f88c471"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0ca5c71a5a1765a0f8f88022c52b6b8be740e512980362f7fdbb03725a0d6b9"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a7c97726520f784239f6c62506bc70e48d01ae71e9da128259d61ca5e9788516"}, + {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:815ac2d0f3398a14286dc2cea223a6f338109f9ecf39a71160cd1628786bc6f5"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:80b5ee39b7f0131ebec7968baa9b2309eddb35b8403d1869e08f024efd883566"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5b2ccb7548a0b65974860a78c9ffe1173cfb5877460e5a229238d985565574ae"}, + {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:995ea5c48c4ebfd898eacb098164b3cc826ba273b3049e4a889658548e321b43"}, + {file = "coverage-7.4.0-cp310-cp310-win32.whl", hash = "sha256:79287fd95585ed36e83182794a57a46aeae0b64ca53929d1176db56aacc83451"}, + {file = "coverage-7.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:5b14b4f8760006bfdb6e08667af7bc2d8d9bfdb648351915315ea17645347137"}, + {file = "coverage-7.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:04387a4a6ecb330c1878907ce0dc04078ea72a869263e53c72a1ba5bbdf380ca"}, + {file = "coverage-7.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ea81d8f9691bb53f4fb4db603203029643caffc82bf998ab5b59ca05560f4c06"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:74775198b702868ec2d058cb92720a3c5a9177296f75bd97317c787daf711505"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:76f03940f9973bfaee8cfba70ac991825611b9aac047e5c80d499a44079ec0bc"}, + {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:485e9f897cf4856a65a57c7f6ea3dc0d4e6c076c87311d4bc003f82cfe199d25"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:6ae8c9d301207e6856865867d762a4b6fd379c714fcc0607a84b92ee63feff70"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:bf477c355274a72435ceb140dc42de0dc1e1e0bf6e97195be30487d8eaaf1a09"}, + {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:83c2dda2666fe32332f8e87481eed056c8b4d163fe18ecc690b02802d36a4d26"}, + {file = "coverage-7.4.0-cp311-cp311-win32.whl", hash = "sha256:697d1317e5290a313ef0d369650cfee1a114abb6021fa239ca12b4849ebbd614"}, + {file = "coverage-7.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:26776ff6c711d9d835557ee453082025d871e30b3fd6c27fcef14733f67f0590"}, + {file = "coverage-7.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:13eaf476ec3e883fe3e5fe3707caeb88268a06284484a3daf8250259ef1ba143"}, + {file = "coverage-7.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846f52f46e212affb5bcf131c952fb4075b55aae6b61adc9856222df89cbe3e2"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26f66da8695719ccf90e794ed567a1549bb2644a706b41e9f6eae6816b398c4a"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:164fdcc3246c69a6526a59b744b62e303039a81e42cfbbdc171c91a8cc2f9446"}, + {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:316543f71025a6565677d84bc4df2114e9b6a615aa39fb165d697dba06a54af9"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:bb1de682da0b824411e00a0d4da5a784ec6496b6850fdf8c865c1d68c0e318dd"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:0e8d06778e8fbffccfe96331a3946237f87b1e1d359d7fbe8b06b96c95a5407a"}, + {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a56de34db7b7ff77056a37aedded01b2b98b508227d2d0979d373a9b5d353daa"}, + {file = "coverage-7.4.0-cp312-cp312-win32.whl", hash = "sha256:51456e6fa099a8d9d91497202d9563a320513fcf59f33991b0661a4a6f2ad450"}, + {file = "coverage-7.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:cd3c1e4cb2ff0083758f09be0f77402e1bdf704adb7f89108007300a6da587d0"}, + {file = "coverage-7.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e9d1bf53c4c8de58d22e0e956a79a5b37f754ed1ffdbf1a260d9dcfa2d8a325e"}, + {file = "coverage-7.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:109f5985182b6b81fe33323ab4707011875198c41964f014579cf82cebf2bb85"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3cc9d4bc55de8003663ec94c2f215d12d42ceea128da8f0f4036235a119c88ac"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cc6d65b21c219ec2072c1293c505cf36e4e913a3f936d80028993dd73c7906b1"}, + {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5a10a4920def78bbfff4eff8a05c51be03e42f1c3735be42d851f199144897ba"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b8e99f06160602bc64da35158bb76c73522a4010f0649be44a4e167ff8555952"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:7d360587e64d006402b7116623cebf9d48893329ef035278969fa3bbf75b697e"}, + {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:29f3abe810930311c0b5d1a7140f6395369c3db1be68345638c33eec07535105"}, + {file = "coverage-7.4.0-cp38-cp38-win32.whl", hash = "sha256:5040148f4ec43644702e7b16ca864c5314ccb8ee0751ef617d49aa0e2d6bf4f2"}, + {file = "coverage-7.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:9864463c1c2f9cb3b5db2cf1ff475eed2f0b4285c2aaf4d357b69959941aa555"}, + {file = "coverage-7.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:936d38794044b26c99d3dd004d8af0035ac535b92090f7f2bb5aa9c8e2f5cd42"}, + {file = "coverage-7.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:799c8f873794a08cdf216aa5d0531c6a3747793b70c53f70e98259720a6fe2d7"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7defbb9737274023e2d7af02cac77043c86ce88a907c58f42b580a97d5bcca9"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a1526d265743fb49363974b7aa8d5899ff64ee07df47dd8d3e37dcc0818f09ed"}, + {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf635a52fc1ea401baf88843ae8708591aa4adff875e5c23220de43b1ccf575c"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:756ded44f47f330666843b5781be126ab57bb57c22adbb07d83f6b519783b870"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:0eb3c2f32dabe3a4aaf6441dde94f35687224dfd7eb2a7f47f3fd9428e421058"}, + {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:bfd5db349d15c08311702611f3dccbef4b4e2ec148fcc636cf8739519b4a5c0f"}, + {file = "coverage-7.4.0-cp39-cp39-win32.whl", hash = "sha256:53d7d9158ee03956e0eadac38dfa1ec8068431ef8058fe6447043db1fb40d932"}, + {file = "coverage-7.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:cfd2a8b6b0d8e66e944d47cdec2f47c48fef2ba2f2dff5a9a75757f64172857e"}, + {file = "coverage-7.4.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:c530833afc4707fe48524a44844493f36d8727f04dcce91fb978c414a8556cc6"}, + {file = "coverage-7.4.0.tar.gz", hash = "sha256:707c0f58cb1712b8809ece32b68996ee1e609f71bd14615bd8f87a1293cb610e"}, +] + +[package.extras] +toml = ["tomli"] + [[package]] name = "cryptography" version = "41.0.7" @@ -1533,4 +1597,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "5cd4ce9806aa511a0d9497a5c9f77f118e823b6d76d19bf909384ea982eb2f59" +content-hash = "310fbf2cbf81211d3c16311b75a5db9862495c2ae4422ad0c3b2b26d373f06e4" diff --git a/pyproject.toml b/pyproject.toml index f7ad0e7..9fa4a67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ django-redis = "~5.4.0" pillow = "^10.2.0" django-auditlog = "~2.3.0" psycopg = {extras = ["binary"], version = "^3.1.16"} +coverage = "^7.4.0" [tool.poetry.group.dev.dependencies] diff --git a/scripts/dbinit/initialize-database.sh b/scripts/dbinit/initialize-database.sh new file mode 100755 index 0000000..1175dc2 --- /dev/null +++ b/scripts/dbinit/initialize-database.sh @@ -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 \ No newline at end of file diff --git a/unicorn/competitions/tests/test_signals.py b/unicorn/competitions/tests/test_signals.py new file mode 100644 index 0000000..7fd5365 --- /dev/null +++ b/unicorn/competitions/tests/test_signals.py @@ -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) diff --git a/unicorn/unicorn/settings.py b/unicorn/unicorn/settings.py index 233ac16..a7e8201 100644 --- a/unicorn/unicorn/settings.py +++ b/unicorn/unicorn/settings.py @@ -25,10 +25,12 @@ ) TESTING = sys.argv[1:2] == ["test"] + +env_file_name = ".env" if TESTING: - environ.Env.read_env(os.path.join(BASE_DIR, "development.example.env")) -else: - environ.Env.read_env(os.path.join(BASE_DIR, ".env")) + env_file_name = ".env.testing" + +environ.Env.read_env(os.path.join(BASE_DIR, env_file_name)) # Import required configuration parameters ALLOWED_HOSTS = CSRF_TRUSTED_ORIGINS = DATABASE = SECRET_KEY = None