diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae95d2ebd7f8fb04d183b094a36a5d1b7b730388..3a185ec7155aca3b9edc4a7696a28db41abdf89c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,10 +19,10 @@ test-branch: image: $PYTHON_IMAGE script: - apt-get update -q && apt-get install -y -qq $PYTHON_IMAGE_DEPENDENCIES - - pip3 install -e . - - pip3 install flake8 + - pip3 install -e .[test] - flake8 - django-admin makemigrations --dry-run --check --noinput --settings=scheduler.settings.development + - django-admin test --settings=scheduler.settings.development build: stage: build diff --git a/Makefile b/Makefile index e9a8a0c2c3179d3876d52c5fb802deb4add7cbe8..751a247d780f4a7efaba7e970de3250975871b98 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,17 @@ run: install: if [ ! -d "$(VIRTUAL_ENV)" ]; then python3 -m venv "$(VIRTUAL_ENV)"; fi $(VIRTUAL_ENV)/bin/pip install -U pip - $(VIRTUAL_ENV)/bin/pip install -e . + $(VIRTUAL_ENV)/bin/pip install -e .[test] npm install $(MANAGEPY) migrate $(MANAGEPY) shell -c "from django.contrib.auth.models import User; User.objects.filter(username='admin').exists() or User.objects.create_superuser('admin', 'admin@example.com', 'password')" $(MANAGEPY) compilemessages -l de +.PHONY: test +test: + $(VIRTUAL_ENV)/bin/flake8 scheduler + $(MANAGEPY) test + .PHONY: makemessages makemessages: $(MANAGEPY) makemessages -l de -d django diff --git a/scheduler/tests.py b/scheduler/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..a5220d33d526b67fcae2c2a99750332fb5ac9298 --- /dev/null +++ b/scheduler/tests.py @@ -0,0 +1,32 @@ +from django.conf import settings +from django.test import TestCase + +from model_bakery import baker + +from .main.models import Schedule +from .main.models import Invitation + + +class TestInvitationApiView(TestCase): + def setUp(self): + self.client.defaults['HTTP_AUTHORIZATION'] = 'token ' + settings.API_TOKEN + + def test_get(self): + invitation = baker.make(Invitation) + url = '/api/{}/{}/'.format(invitation.schedule.id, invitation.token) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + def test_put(self): + schedule = baker.make(Schedule) + url = '/api/{}/{}/'.format(schedule.id, 'sometoken') + response = self.client.put(url) + self.assertEqual(response.status_code, 204) + self.assertTrue(Invitation.objects.filter(token='sometoken').exists()) + + def test_delete(self): + invitation = baker.make(Invitation) + url = '/api/{}/{}/'.format(invitation.schedule.id, invitation.token) + response = self.client.delete(url) + self.assertEqual(response.status_code, 204) + self.assertFalse(Invitation.objects.filter(token=invitation.token).exists()) diff --git a/setup.cfg b/setup.cfg index 5517183b2e0647f54d6c49f361151da2900f25e7..2f684577c2197bba3fb07fe854a1f9c19fecd557 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,6 +13,11 @@ install_requires = django-npm == 1.0.0 requests == 2.25.1 +[options.extras_require] +test = + model-bakery + flake8 + [flake8] exclude = .venv,