aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2018-09-04 22:06:07 +0200
committerGravatar Johannes Christ <[email protected]>2018-09-04 22:06:07 +0200
commite211cbf6dbbe3a28ef1276af69c4f387db52d596 (patch)
tree8bb441e8528056806e129c5d45b3770bbaa0fd31
parentAdd job tags. (diff)
Set up GitLab CI properly.
-rw-r--r--.flake85
-rw-r--r--.gitlab-ci.yml87
-rw-r--r--Pipfile2
-rw-r--r--Pipfile.lock11
-rw-r--r--api/models.py4
-rw-r--r--api/tests/base.py5
-rw-r--r--api/tests/test_documentation_links.py4
-rw-r--r--api/tests/test_members.py3
-rw-r--r--api/tests/test_off_topic_channel_names.py4
-rw-r--r--api/tests/test_snake_names.py3
-rw-r--r--api/urls.py27
-rw-r--r--api/views.py2
-rw-r--r--api/viewsets.py9
-rw-r--r--tox.ini6
14 files changed, 117 insertions, 55 deletions
diff --git a/.flake8 b/.flake8
new file mode 100644
index 00000000..d34064b1
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,5 @@
+[flake8]
+max-line-length=100
+application_import_names=pysite
+exclude=__pycache__, venv, .venv, **/migrations
+import-order-style=pycharm
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 835d9ba4..d5d9b5ff 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,11 +1,8 @@
stages:
- - build
- lint
- test
- deploy
- - cleanup
-services:
- - registry
+image: python:3.7-alpine
cache:
paths:
@@ -13,52 +10,91 @@ cache:
variables:
PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
+ PIPENV_HIDE_EMOJIS: 1
+ PIPENV_IGNORE_VIRTUALENVS: 1
+ PIPENV_MAX_SUBPROCESS: 2
+ PIPENV_NOSPIN: 1
+ PIPENV_VENV_IN_PROJECT: 1
-build docker image:
- image: docker:stable-git
- stage: build
+
+.test-template: &test-template
+ stage: test
+ services:
+ - postgres:10-alpine
script:
- - docker build -t registry:5000/django-ci .
- - docker push registry:5000/django-ci
+ - python manage.py test
tags:
- docker
+ variables:
+ DATABASE_URL: postgres://django:supersecret@postgres/pysite
+ POSTGRES_DB: pysite
+ POSTGRES_PASSWORD: supersecret
+ POSTGRES_USER: django
lint:
- image: registry:5000/django-ci
stage: lint
- script:
+ before_script:
+ - apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev
+ - python3 -m pip install pipenv
- pipenv install --dev --system
+ script:
- flake8
tags:
- docker
-test:
- image: registry:5000/django-ci
- stage: test
- services:
- - postgres:10-alpine
+test on 3.7 / alpine:
+ <<: *test-template
+ image: python:3.7-alpine
before_script:
+ - apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev
+ - python3 -m pip install pipenv
- pipenv install --dev --system
- python manage.py migrate
script:
- coverage run --source=api,home,pysite,wiki --branch manage.py test
after_script:
- coverage report
- tags:
- - docker
artifacts:
paths:
- .coverage
- variables:
- DATABASE_URL: postgres://django:supersecret@postgres/pysite
- POSTGRES_DB: pysite
- POSTGRES_PASSWORD: supersecret
- POSTGRES_USER: django
+
+test on 3.6 / alpine:
+ <<: *test-template
+ image: python:3.6-alpine
+ before_script:
+ - apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev
+ - python3 -m pip install pipenv
+ - pipenv install --system
+ - python manage.py migrate
+
+test on 3.6 / stretch:
+ <<: *test-template
+ image: python:3.6-stretch
+ services:
+ - postgres:11
+ before_script:
+ - apt-get update -y
+ - apt-get install -y libpython3-dev git libpq-dev gcc cmake autoconf automake libc-dev
+ - python3 -m pip install pipenv
+ - pipenv install --system
+ - python manage.py migrate
+
+test on 3.7 / stretch:
+ <<: *test-template
+ image: python:3.6-stretch
+ services:
+ - postgres:11
+ before_script:
+ - apt-get update -y
+ - apt-get install -y libpython3-dev git libpq-dev gcc cmake autoconf automake libc-dev
+ - python3 -m pip install pipenv
+ - pipenv install --system
+ - python manage.py migrate
pages:
stage: deploy
dependencies:
- - test
+ - test on 3.7 / alpine
before_script:
- pip install coverage
script:
@@ -72,9 +108,8 @@ upload newest docker image:
image: docker:stable-git
stage: deploy
script:
+ - docker build -t registry.gitlab.com/python-discord/projects/site/django:latest
- echo "$GITLAB_DOCKER_PASSWORD" | docker login --username "$GITLAB_DOCKER_USERNAME" --password-stdin registry.gitlab.com
- - docker pull registry:5000/django-ci
- - docker image tag registry.gitlab.com/python-discord/projects/site/django:latest registry:5000/django-ci
- docker push registry.gitlab.com/python-discord/projects/site/django:latest
only:
- master
diff --git a/Pipfile b/Pipfile
index 8b87052a..42954fb5 100644
--- a/Pipfile
+++ b/Pipfile
@@ -19,6 +19,8 @@ djangorestframework-bulk = "==0.2.1"
"flake8-tidy-imports" = "==1.1.0"
"flake8-string-format" = "==0.2.3"
coverage = "==4.5.1"
+"pep8-naming" = "==0.7.0"
+mccabe = "==0.6.1"
[requires]
python_version = "3.7"
diff --git a/Pipfile.lock b/Pipfile.lock
index 0e0869d4..2bd5f10e 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "9cd6b6689e8f1f217c2e8cd4e9719b9b6bfd56d3a6f9a46449d9f258ab3a7c3d"
+ "sha256": "e741a0b3204db05c8b74ab38cc5c4fef89570b5d5409745568c9425d76200d12"
},
"pipfile-spec": 6,
"requires": {
@@ -225,6 +225,7 @@
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
],
+ "index": "pypi",
"version": "==0.6.1"
},
"pbr": {
@@ -234,6 +235,14 @@
],
"version": "==4.2.0"
},
+ "pep8-naming": {
+ "hashes": [
+ "sha256:360308d2c5d2fff8031c1b284820fbdb27a63274c0c1a8ce884d631836da4bdd",
+ "sha256:624258e0dd06ef32a9daf3c36cc925ff7314da7233209c5b01f7e5cdd3c34826"
+ ],
+ "index": "pypi",
+ "version": "==0.7.0"
+ },
"pycodestyle": {
"hashes": [
"sha256:682256a5b318149ca0d2a9185d365d8864a768a28db66a84a2ea946bcc426766",
diff --git a/api/models.py b/api/models.py
index d3986ba5..5d7dfc35 100644
--- a/api/models.py
+++ b/api/models.py
@@ -28,7 +28,7 @@ class SnakeName(models.Model):
class Role(models.Model):
"""A role on our Discord server."""
- id = models.BigIntegerField(
+ id = models.BigIntegerField( # noqa
primary_key=True,
validators=(
MinValueValidator(
@@ -69,7 +69,7 @@ class Role(models.Model):
class Member(models.Model):
"""A member of our Discord server."""
- id = models.BigIntegerField(
+ id = models.BigIntegerField( # noqa
primary_key=True,
validators=(
MinValueValidator(
diff --git a/api/tests/base.py b/api/tests/base.py
index 06f7233c..395dc55c 100644
--- a/api/tests/base.py
+++ b/api/tests/base.py
@@ -1,12 +1,11 @@
from django.contrib.auth.models import User
-from rest_framework.authtoken.models import Token
-from rest_framework.test import APIClient, APITestCase
+from rest_framework.test import APITestCase
test_user, _created = User.objects.get_or_create(
username='test',
- password='testpass',
+ password='testpass', # flake8: noqa - S106
is_superuser=True,
is_staff=True
)
diff --git a/api/tests/test_documentation_links.py b/api/tests/test_documentation_links.py
index e560a2fd..f6c78391 100644
--- a/api/tests/test_documentation_links.py
+++ b/api/tests/test_documentation_links.py
@@ -57,7 +57,7 @@ class EmptyDatabaseDocumentationLinkAPITests(APISubdomainTestCase):
class DetailLookupDocumentationLinkAPITests(APISubdomainTestCase):
@classmethod
- def setUpTestData(cls):
+ def setUpTestData(cls): # noqa
cls.doc_link = DocumentationLink.objects.create(
package='testpackage',
base_url='https://example.com',
@@ -141,7 +141,7 @@ class DocumentationLinkCreationTests(APISubdomainTestCase):
class DocumentationLinkDeletionTests(APISubdomainTestCase):
@classmethod
- def setUpTestData(cls):
+ def setUpTestData(cls): # noqa
cls.doc_link = DocumentationLink.objects.create(
package='example',
base_url='https://example.com',
diff --git a/api/tests/test_members.py b/api/tests/test_members.py
index 60ad8460..47466b62 100644
--- a/api/tests/test_members.py
+++ b/api/tests/test_members.py
@@ -1,4 +1,3 @@
-from django.test import TestCase
from django_hosts.resolvers import reverse
from .base import APISubdomainTestCase
@@ -37,7 +36,7 @@ class UnauthedDocumentationLinkAPITests(APISubdomainTestCase):
class CreationTests(APISubdomainTestCase):
@classmethod
- def setUpTestData(cls):
+ def setUpTestData(cls): # noqa
cls.role = Role.objects.create(
id=5,
name="Test role pls ignore",
diff --git a/api/tests/test_off_topic_channel_names.py b/api/tests/test_off_topic_channel_names.py
index 1b222dca..60af1f62 100644
--- a/api/tests/test_off_topic_channel_names.py
+++ b/api/tests/test_off_topic_channel_names.py
@@ -58,7 +58,7 @@ class EmptyDatabaseTests(APISubdomainTestCase):
class ListTests(APISubdomainTestCase):
@classmethod
- def setUpTestData(cls):
+ def setUpTestData(cls): # noqa
cls.test_name = OffTopicChannelName.objects.create(name='lemons-lemonade-stand')
cls.test_name_2 = OffTopicChannelName.objects.create(name='bbq-with-bisk')
@@ -125,7 +125,7 @@ class CreationTests(APISubdomainTestCase):
class DeletionTests(APISubdomainTestCase):
@classmethod
- def setUpTestData(cls):
+ def setUpTestData(cls): # noqa
cls.test_name = OffTopicChannelName.objects.create(name='lemons-lemonade-stand')
cls.test_name_2 = OffTopicChannelName.objects.create(name='bbq-with-bisk')
diff --git a/api/tests/test_snake_names.py b/api/tests/test_snake_names.py
index 6a669557..41dfae63 100644
--- a/api/tests/test_snake_names.py
+++ b/api/tests/test_snake_names.py
@@ -4,7 +4,6 @@ from .base import APISubdomainTestCase
from ..models import SnakeName
-
class StatusTests(APISubdomainTestCase):
def setUp(self):
super().setUp()
@@ -41,7 +40,7 @@ class EmptyDatabaseSnakeNameTests(APISubdomainTestCase):
class SnakeNameListTests(APISubdomainTestCase):
@classmethod
- def setUpTestData(cls):
+ def setUpTestData(cls): # noqa
cls.snake_python = SnakeName.objects.create(name='Python', scientific='Totally.')
def test_endpoint_returns_all_snakes_with_get_all_param(self):
diff --git a/api/urls.py b/api/urls.py
index 1e10cddb..f4ed641c 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -2,15 +2,32 @@ from django.urls import include, path
from rest_framework.routers import SimpleRouter
from .views import HealthcheckView
-from .viewsets import DocumentationLinkViewSet, MemberViewSet, OffTopicChannelNameViewSet, SnakeNameViewSet
+from .viewsets import (
+ DocumentationLinkViewSet, MemberViewSet,
+ OffTopicChannelNameViewSet, SnakeNameViewSet
+)
# http://www.django-rest-framework.org/api-guide/routers/#simplerouter
bot_router = SimpleRouter(trailing_slash=False)
-bot_router.register('documentation-links', DocumentationLinkViewSet)
-bot_router.register('off-topic-channel-names', OffTopicChannelNameViewSet, base_name='offtopicchannelname')
-bot_router.register('members', MemberViewSet)
-bot_router.register('snake-names', SnakeNameViewSet, base_name='snakename')
+bot_router.register(
+ 'documentation-links',
+ DocumentationLinkViewSet
+)
+bot_router.register(
+ 'off-topic-channel-names',
+ OffTopicChannelNameViewSet,
+ base_name='offtopicchannelname'
+)
+bot_router.register(
+ 'members',
+ MemberViewSet
+)
+bot_router.register(
+ 'snake-names',
+ SnakeNameViewSet,
+ base_name='snakename'
+)
app_name = 'api'
diff --git a/api/views.py b/api/views.py
index dbc04b56..c5582ec0 100644
--- a/api/views.py
+++ b/api/views.py
@@ -23,5 +23,5 @@ class HealthcheckView(APIView):
authentication_classes = ()
permission_classes = ()
- def get(self, request, format=None):
+ def get(self, request, format=None): # noqa
return Response({'status': 'ok'})
diff --git a/api/viewsets.py b/api/viewsets.py
index 677110a8..9eec3a03 100644
--- a/api/viewsets.py
+++ b/api/viewsets.py
@@ -1,6 +1,9 @@
from django.shortcuts import get_object_or_404
from rest_framework.exceptions import ParseError
-from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
+from rest_framework.mixins import (
+ CreateModelMixin, DestroyModelMixin,
+ ListModelMixin, RetrieveModelMixin
+)
from rest_framework.response import Response
from rest_framework.status import HTTP_201_CREATED
from rest_framework.viewsets import GenericViewSet, ModelViewSet, ViewSet
@@ -144,7 +147,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
'name': ["This query parameter is required."]
})
- def list(self, request):
+ def list(self, request): # noqa
if 'random_items' in request.query_params:
param = request.query_params['random_items']
try:
@@ -204,7 +207,7 @@ class SnakeNameViewSet(ViewSet):
def get_queryset(self):
return SnakeName.objects.all()
- def list(self, request):
+ def list(self, request): # noqa
if request.query_params.get('get_all'):
queryset = self.get_queryset()
serialized = self.serializer_class(queryset, many=True)
diff --git a/tox.ini b/tox.ini
deleted file mode 100644
index f0b2fc99..00000000
--- a/tox.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[flake8]
-max-line-length=120
-application_import_names=pysite
-ignore=P102,B311,W503,E226,S311,E241
-exclude=__pycache__, venv, .venv, tests, **/migrations
-import-order-style=pycharm