From e607a47617a3c602298872ff25a4df9aa6fbf66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 18 Jul 2020 17:40:33 +0200 Subject: [PATCH 1/5] Tox + CI --- .gitignore | 5 ++++- .gitlab-ci.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ tox.ini | 13 ++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .gitlab-ci.yml create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index e817f4d..8351c11 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,7 @@ __pycache__ # Vim *.swp -*.swo \ No newline at end of file +*.swo + +# Tests +.tox diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..073fdbd --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,54 @@ +image: python + +stages: + - linters + - tests + +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/vendor/pip" + +cache: + paths: + - vendor + +linters: + stage: linters + before_script: + - mkdir -p vendor/pip + - pip install --upgrade black isort flake8 + script: + - black --check . + - isort --check --diff . + - flake8 --exit-zero authens + +before_script: + - mkdir -p vendor/{apt,pip} + - apt-get update -q && apt-get -o dir::cache::archives="vendor/apt" install -yqq python3-dev libldap2-dev libsasl2-dev + - pip install tox + +python35: + image: python:3.5 + stage: tests + script: + - tox -e py35-django22 + +python36: + image: python:3.6 + stage: tests + script: + - tox -e py36-django22 + - tox -e py36-django30 + +python37: + image: python:3.7 + stage: tests + script: + - tox -e py37-django22 + - tox -e py37-django30 + +python38: + image: python:3.8 + stage: tests + script: + - tox -e py38-django22 + - tox -e py38-django30 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..2e4d276 --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +[tox] +envlist = + py{35,36,37,38}-django22, + py{36,37,38}-django30 + +[testenv] +deps = + django22: Django==2.2.* + django30: Django==3.0.* + python-cas +commands = + python --version + python runtests.py From f359a90a4764fd5d843b7b599d80c1b32bb63d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 18 Jul 2020 17:51:50 +0200 Subject: [PATCH 2/5] Add missing dep: python-ldap --- requirements.txt | 1 + tox.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 6421f80..d281cf0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ python-cas==1.5.* +python-ldap diff --git a/tox.ini b/tox.ini index 2e4d276..9a5c460 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ deps = django22: Django==2.2.* django30: Django==3.0.* python-cas + python-ldap commands = python --version python runtests.py From 22846890b14134965e247b0d8e64a3223cf895b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 18 Jul 2020 18:08:43 +0200 Subject: [PATCH 3/5] Make python-black happy --- runtests.py | 4 ++-- tests/urls.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtests.py b/runtests.py index f9079d6..0bc3f88 100644 --- a/runtests.py +++ b/runtests.py @@ -8,8 +8,8 @@ import django from django.conf import settings from django.test.utils import get_runner -if __name__ == '__main__': - os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' +if __name__ == "__main__": + os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings" django.setup() TestRunner = get_runner(settings) test_runner = TestRunner() diff --git a/tests/urls.py b/tests/urls.py index ab97673..cce086e 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -7,6 +7,7 @@ from django.urls import include, path # Two tiny views to easily test user authentication. # --- + def public_view(request): return HttpResponse("OK") From 445f6920f87fe6e44998319edbeb66390df37ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 18 Jul 2020 18:13:47 +0200 Subject: [PATCH 4/5] =?UTF-8?q?Make=20isort=20happy=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authens/forms.py | 4 ++-- authens/migrations/0001_initial.py | 3 +-- authens/migrations/0002_old_cas_account.py | 3 +-- authens/shortcuts.py | 1 - authens/utils.py | 2 +- authens/views.py | 2 +- example_site/example_site/urls.py | 1 - setup.cfg | 1 - tests/urls.py | 1 - 9 files changed, 6 insertions(+), 12 deletions(-) diff --git a/authens/forms.py b/authens/forms.py index e1def13..55ab14c 100644 --- a/authens/forms.py +++ b/authens/forms.py @@ -1,7 +1,7 @@ from django import forms -from django.contrib.auth import forms as auth_forms, authenticate -from django.utils.translation import gettext_lazy as _ +from django.contrib.auth import authenticate, forms as auth_forms from django.utils import timezone +from django.utils.translation import gettext_lazy as _ def promo_choices(): diff --git a/authens/migrations/0001_initial.py b/authens/migrations/0001_initial.py index 60b14d3..e48b86f 100644 --- a/authens/migrations/0001_initial.py +++ b/authens/migrations/0001_initial.py @@ -1,8 +1,7 @@ # Generated by Django 3.0.6 on 2020-05-17 11:58 - +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/authens/migrations/0002_old_cas_account.py b/authens/migrations/0002_old_cas_account.py index defdac9..d7a0a89 100644 --- a/authens/migrations/0002_old_cas_account.py +++ b/authens/migrations/0002_old_cas_account.py @@ -1,8 +1,7 @@ # Generated by Django 3.0.6 on 2020-06-12 17:26 - +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/authens/shortcuts.py b/authens/shortcuts.py index 8a8dd97..2bed72b 100644 --- a/authens/shortcuts.py +++ b/authens/shortcuts.py @@ -2,7 +2,6 @@ # TODO: make the python-ldap dependency optional import ldap - from django.conf import settings from django.contrib.auth import get_user_model diff --git a/authens/utils.py b/authens/utils.py index a7cbbb6..2dc0876 100644 --- a/authens/utils.py +++ b/authens/utils.py @@ -1,7 +1,7 @@ """Internal utility functions used by authens.""" +from urllib.parse import urlunparse from cas import CASClient -from urllib.parse import urlunparse def get_cas_client(request): diff --git a/authens/views.py b/authens/views.py index c1d4f66..70134ad 100644 --- a/authens/views.py +++ b/authens/views.py @@ -6,9 +6,9 @@ from django.contrib.auth import views as auth_views from django.contrib.messages.views import SuccessMessageMixin from django.core.exceptions import PermissionDenied from django.shortcuts import redirect +from django.urls import reverse_lazy from django.utils import timezone from django.utils.translation import gettext_lazy as _ -from django.urls import reverse_lazy from django.views.generic import TemplateView, View from authens.forms import OldCASAuthForm diff --git a/example_site/example_site/urls.py b/example_site/example_site/urls.py index 0781d66..ebb6718 100644 --- a/example_site/example_site/urls.py +++ b/example_site/example_site/urls.py @@ -15,7 +15,6 @@ Including another URLconf """ from django.contrib import admin from django.urls import include, path - from example import views urlpatterns = [ diff --git a/setup.cfg b/setup.cfg index ec50b39..cd19421 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,5 +19,4 @@ known_django = django known_first_party = authens,tests line_length = 88 multi_line_output = 3 -not_skip = __init__.py sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER diff --git a/tests/urls.py b/tests/urls.py index cce086e..53bcab9 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -2,7 +2,6 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponse from django.urls import include, path - # --- # Two tiny views to easily test user authentication. # --- From e91023536d6681ffeee1a13719b80d169d57cb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 18 Jul 2020 19:00:18 +0200 Subject: [PATCH 5/5] Configure tox for ignoring setup.py --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 9a5c460..86d1123 100644 --- a/tox.ini +++ b/tox.ini @@ -1,4 +1,6 @@ [tox] +# Temporaire en attendant de créer setup.py +skipsdist = True envlist = py{35,36,37,38}-django22, py{36,37,38}-django30