From 922498114a60016a29bdf457e4725968195fe196 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 16 Aug 2018 22:43:34 +0200 Subject: Make test user superuser. --- api/tests/base.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'api') diff --git a/api/tests/base.py b/api/tests/base.py index aa8157bc..06f7233c 100644 --- a/api/tests/base.py +++ b/api/tests/base.py @@ -3,9 +3,13 @@ from rest_framework.authtoken.models import Token from rest_framework.test import APIClient, APITestCase -test_user = User.objects.get(username='test') -if test_user is None: - test_user = User.objects.create_user('test', 'test@example.com', 'testpass') +test_user, _created = User.objects.get_or_create( + username='test', + email='test@example.com', + password='testpass', + is_superuser=True, + is_staff=True +) class APISubdomainTestCase(APITestCase): @@ -13,6 +17,12 @@ class APISubdomainTestCase(APITestCase): Configures the test client to use the proper subdomain for requests and forces authentication for the test user. + The test user is considered staff and superuser. + If you want to test for a custom user (for example, to test model permissions), + create the user, assign the relevant permissions, and use + `self.client.force_authenticate(user=created_user)` to force authentication + through the created user. + Using this performs the following niceties for you which ease writing tests: - setting the `HTTP_HOST` request header to `api.pythondiscord.local:8000`, and - forcing authentication for the test user. -- cgit v1.2.3 From 37ff9fe6cdc6fff84ccda6c5d610a521288d99ce Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 30 Aug 2018 20:02:09 +0200 Subject: Proeprly set up lint and test stages. --- .gitlab-ci.yml | 24 ++++++++++++++++++++++-- Dockerfile | 2 +- api/admin.py | 2 +- home/admin.py | 2 +- home/models.py | 2 +- home/views.py | 2 +- pysite/hosts.py | 8 ++++---- pysite/settings.py | 2 +- wiki/admin.py | 2 +- wiki/models.py | 2 +- wiki/tests.py | 2 +- wiki/views.py | 2 +- 12 files changed, 36 insertions(+), 16 deletions(-) (limited to 'api') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe86b32c..c8bcb91e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,11 @@ +stages: + - build + - lint + - test + build base image: image: docker:stable-git + stage: build script: - sh scripts/deploy-ci.sh tags: @@ -10,7 +16,21 @@ build base image: - django+add-gitlab-ci lint: - image: pythondiscord/django-site-ci:latest + image: registry.gitlab.com/python-discord/projects/site/django-base:latest + stage: lint script: - - pipenv install --system --dev + - pipenv install --dev --system - flake8 + +test: + image: registry.gitlab.com/python-discord/projects/site/django-base:latest + stage: test + services: + - postgres:10-alpine + script: + - pipenv run manage.py test + variables: + DATABASE_URL: postgres://django:supersecret@postgres/pysite + POSTGRES_DB: pysite + POSTGRES_PASSWORD: supersecret + POSTGRES_USER: django diff --git a/Dockerfile b/Dockerfile index b62eb93d..c4489027 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1 @@ -FROM pythondiscord/django-site-ci:latest +FROM registry.gitlab.com/python-discord/projects/site/django-base:latest diff --git a/api/admin.py b/api/admin.py index 8c38f3f3..4185d360 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/home/admin.py b/home/admin.py index 8c38f3f3..4185d360 100644 --- a/home/admin.py +++ b/home/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/home/models.py b/home/models.py index 71a83623..0b4331b3 100644 --- a/home/models.py +++ b/home/models.py @@ -1,3 +1,3 @@ -from django.db import models +# from django.db import models # Create your models here. diff --git a/home/views.py b/home/views.py index 91ea44a2..fd0e0449 100644 --- a/home/views.py +++ b/home/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +# from django.shortcuts import render # Create your views here. diff --git a/pysite/hosts.py b/pysite/hosts.py index 827f49c3..67fc2451 100644 --- a/pysite/hosts.py +++ b/pysite/hosts.py @@ -4,10 +4,10 @@ from django_hosts import host, patterns host_patterns = patterns( '', # > | Subdomain | URL Module | Host entry name | - #host(r"admin", "admin", name="admin"), + # host(r"admin", "admin", name="admin"), host(r'api', 'api.urls', name='api'), - #host(r"staff", "staff", name="staff"), - #host(r"wiki", "wiki", name="wiki"), - #host(r"ws", "ws", name="ws"), + # host(r"staff", "staff", name="staff"), + # host(r"wiki", "wiki", name="wiki"), + # host(r"ws", "ws", name="ws"), host(r'.*', 'home.urls', name=settings.DEFAULT_HOST) ) diff --git a/pysite/settings.py b/pysite/settings.py index 3392426d..16235e09 100644 --- a/pysite/settings.py +++ b/pysite/settings.py @@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ """ import os -import sys +# import sys import environ diff --git a/wiki/admin.py b/wiki/admin.py index 8c38f3f3..4185d360 100644 --- a/wiki/admin.py +++ b/wiki/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/wiki/models.py b/wiki/models.py index 71a83623..0b4331b3 100644 --- a/wiki/models.py +++ b/wiki/models.py @@ -1,3 +1,3 @@ -from django.db import models +# from django.db import models # Create your models here. diff --git a/wiki/tests.py b/wiki/tests.py index 7ce503c2..a79ca8be 100644 --- a/wiki/tests.py +++ b/wiki/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +# from django.test import TestCase # Create your tests here. diff --git a/wiki/views.py b/wiki/views.py index 91ea44a2..fd0e0449 100644 --- a/wiki/views.py +++ b/wiki/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +# from django.shortcuts import render # Create your views here. -- cgit v1.2.3