From 3c682af060c5aa548b58418bc1726144a745163b Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Wed, 24 Jan 2024 17:28:42 -0500 Subject: [PATCH 01/27] update to Django 4 --- setup.cfg | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index 51c08b8..9e0b95d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,10 +10,6 @@ classifiers = Development Status :: 3 - Alpha Environment :: Web Environment Framework :: Django - Framework :: Django :: 2.2 - Framework :: Django :: 3.0 - Framework :: Django :: 3.1 - Framework :: Django :: 3.2 Intended Audience :: Developers License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication Operating System :: OS Independent @@ -21,9 +17,6 @@ classifiers = Topic :: Software Development :: Libraries :: Python Modules Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 Topic :: Utilities [options] @@ -33,7 +26,7 @@ package_dir = uaa_client = uaa_client packages = find: install_requires = - django>=2.2,<3.3 + django>=4.0,<5.0 PyJWT>=2.4.0 requests>=2.11.0 From b5dec11de6c33f351012572a6ffaf516d51eeb65 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Wed, 24 Jan 2024 17:29:19 -0500 Subject: [PATCH 02/27] update code for compatibility with django 4 --- example/example/urls.py | 11 ++++++----- example/manage.py | 18 +++--------------- uaa_client/urls.py | 10 +++++----- uaa_client/views.py | 4 ++-- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/example/example/urls.py b/example/example/urls.py index 47bac77..a717dd8 100644 --- a/example/example/urls.py +++ b/example/example/urls.py @@ -15,7 +15,8 @@ """ import django from django.shortcuts import render, redirect -from django.conf.urls import url, include +from django.conf.urls import include +from django.urls import re_path from django.contrib import admin, auth from uaa_client.decorators import staff_login_required @@ -38,8 +39,8 @@ def logout(request): _kwargs["namespace"] = "uaa_client" urlpatterns = [ - url(r"^$", index), - url(r"^admin/", admin.site.urls), - url(r"^auth/", include("uaa_client.urls", **_kwargs)), - url(r"^logout/", logout, name="logout"), + re_path(r"^$", index), + re_path(r"^admin/", admin.site.urls), + re_path(r"^auth/", include("uaa_client.urls", **_kwargs)), + re_path(r"^logout/", logout, name="logout"), ] diff --git a/example/manage.py b/example/manage.py index 72c4bb0..2605e37 100644 --- a/example/manage.py +++ b/example/manage.py @@ -4,19 +4,7 @@ if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") - try: - from django.core.management import execute_from_command_line - except ImportError: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django - except ImportError: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) - raise + + from django.core.management import execute_from_command_line + execute_from_command_line(sys.argv) diff --git a/uaa_client/urls.py b/uaa_client/urls.py index fa51ec4..c1c4181 100644 --- a/uaa_client/urls.py +++ b/uaa_client/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.urls import re_path from . import views, fake_uaa_provider from .configuration import validate_configuration, require_debug @@ -7,14 +7,14 @@ app_name = "uaa_client" urlpatterns = [ - url(r"^callback$", views.oauth2_callback, name="callback"), - url(r"^login$", views.login, name="login"), - url( + re_path(r"^callback$", views.oauth2_callback, name="callback"), + re_path(r"^login$", views.login, name="login"), + re_path( r"^fake/oauth/authorize$", require_debug(fake_uaa_provider.authorize), name="fake_auth", ), - url( + re_path( r"^fake/oauth/token$", require_debug(fake_uaa_provider.access_token), name="fake_token", diff --git a/uaa_client/views.py b/uaa_client/views.py index 429e8b4..a25d854 100644 --- a/uaa_client/views.py +++ b/uaa_client/views.py @@ -5,7 +5,7 @@ from django.http import HttpResponseRedirect from django.shortcuts import resolve_url, render from django.utils.crypto import get_random_string -from django.utils.http import is_safe_url +from django.utils.http import url_has_allowed_host_and_scheme from .compat import reverse from .authentication import get_auth_url @@ -64,7 +64,7 @@ def oauth2_callback(request): next_url = request.session["oauth2_next_url"] del request.session["oauth2_next_url"] - if not is_safe_url(url=next_url, allowed_hosts=[request.get_host()]): + if not url_has_allowed_host_and_scheme(url=next_url, allowed_hosts=[request.get_host()]): next_url = resolve_url(request.build_absolute_uri(settings.LOGIN_REDIRECT_URL)) return HttpResponseRedirect(next_url) From 31d0977e06e49d9a8a2dc9914d95836eba96a649 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Wed, 24 Jan 2024 17:58:49 -0500 Subject: [PATCH 03/27] update tests to use Django 4 --- pyproject.toml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ecf4268..6c7ec8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [tool.black] line-length = 88 -target-version = ['py37'] +target-version = ['py310'] include = '\.pyi?$' exclude = ''' @@ -27,17 +27,16 @@ exclude = ''' [tool.tox] legacy_tox_ini = """ [tox] -envlist = py35-django22,py3{6,7,8,9,10}-django{22,30,31,32} +envlist = py35-django22,py3{6,7,8,9,10}-django{40,41,42} isolated_build=true [testenv:py3{5,6,7}] deps = -rrequirements-tests.txt -rrequirements-dev.txt - django22: Django>=2.2,<2.3 - django30: Django>=3.0,<3.1 - django31: Django>=3.1,<3.2 - django32: Django>=3.2,<3.3 + django40: Django>=4.0,<4.1 + django41: Django>=4.1,<4.2 + django42: Django>=4.2,<4.3 commands = # don't run mypy on versions lower than 3.8 because there's a bug that was fixed in # https://github.com/python/typeshed/pull/1142 but only fixes 3.8+ versions @@ -47,10 +46,9 @@ commands = deps = -rrequirements-tests.txt -rrequirements-dev.txt - django22: Django>=2.2,<2.3 - django30: Django>=3.0,<3.1 - django31: Django>=3.1,<3.2 - django32: Django>=3.2,<3.3 + django40: Django>=4.0,<4.1 + django41: Django>=4.1,<4.2 + django42: Django>=4.2,<4.3 commands = python -m uaa_client.runtests python -m mypy uaa_client From e91e9a91df22b5e23ea123eba3af675c9f063d31 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:16:24 -0500 Subject: [PATCH 04/27] update release docs --- RELEASE.md | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 5924341..09802d6 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -4,31 +4,18 @@ Here's how to issue a new release: 1. Bump the version number in `uaa_client/__init__.py`. -2. Move the "unreleased" section to a new version entry in +1. Move the "unreleased" section to a new version entry in `CHANGELOG.md`. -3. From the project root, install dependencies and run automated tests: +1. [Follow the development instructions](https://cg-django-uaa.readthedocs.io/en/main/developing.html) to: - ```shell - tox - ``` - -4. Run the following to ensure that everything builds and - installs OK in an isolated environment: - - ```shell - rm -rf dist build - python -m build --sdist - python test.py manualtest - ``` - - You should be able to visit and log in - as `foo@example.org` without any problems. + - [Run the unit tests](https://cg-django-uaa.readthedocs.io/en/main/developing.html#running-tests) + - [Run the example app test](https://cg-django-uaa.readthedocs.io/en/main/developing.html#using-the-example-app) -5. Commit and push your changes with a commit message like +1. Commit and push your changes with a commit message like "Bump version to v1.0.4." -6. Tag your version and push it to GitHub. For instance, if you're +1. Tag your version and push it to GitHub. For instance, if you're releasing v1.0.4, do: ```shell @@ -41,7 +28,7 @@ Here's how to issue a new release: `CHANGELOG.md` for this, as whatever you enter will show up on the [GitHub releases page][]. -7. If you haven't already done so, create a `~/.pypirc` file +1. If you haven't already done so, create a `~/.pypirc` file with the following content: ```conf @@ -55,7 +42,7 @@ Here's how to issue a new release: password: ``` -8. Run `python -m twine upload dist/*`. The new release should now +1. Run `python -m twine upload dist/*`. The new release should now be visible on [pypi][]. [GitHub releases page]: https://github.com/18F/cg-django-uaa/releases From 0204998b854657216d5034cf818090084296dbde Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:50:54 -0500 Subject: [PATCH 05/27] update version to 2.1.5 and update CHANGELOG --- CHANGELOG.md | 8 +++++++- uaa_client/__init__.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b491c..1f55801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] +## [2.1.5][] - 2024-01-25 + +* Update Django dependency to `>=4.0,<5.0` + ## [2.1.4][] - 2022-08-16 * Update PyJWT version to >= `2.4.0` to [address vulnerability](https://security.snyk.io/vuln/SNYK-PYTHON-PYJWT-2840625) @@ -82,7 +86,9 @@ This is a hotfix release to fix a broken pypi build. Initial release. -[unreleased]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.0...HEAD +[unreleased]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.5...HEAD +[2.1.5]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.4...v2.1.5 +[2.1.4]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.3...v2.1.4 [2.1.3]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.2...v2.1.3 [2.1.2]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.1...v2.1.2 [2.1.1]: https://github.com/cloud-gov/cg-django-uaa/compare/v2.1.0...v2.1.1 diff --git a/uaa_client/__init__.py b/uaa_client/__init__.py index e282938..e4518d8 100644 --- a/uaa_client/__init__.py +++ b/uaa_client/__init__.py @@ -1,3 +1,3 @@ -VERSION = "2.1.4" +VERSION = "2.1.5" default_app_config = "uaa_client.apps.UaaClientConfig" From d335dc517bda73ea166643554e448f269d09f80f Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:51:07 -0500 Subject: [PATCH 06/27] update release notes --- RELEASE.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 09802d6..8e29598 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -7,10 +7,23 @@ Here's how to issue a new release: 1. Move the "unreleased" section to a new version entry in `CHANGELOG.md`. -1. [Follow the development instructions](https://cg-django-uaa.readthedocs.io/en/main/developing.html) to: +1. From the project root, install dependencies and run automated tests: - - [Run the unit tests](https://cg-django-uaa.readthedocs.io/en/main/developing.html#running-tests) - - [Run the example app test](https://cg-django-uaa.readthedocs.io/en/main/developing.html#using-the-example-app) + ```shell + tox + ``` + +1. Run the following to ensure that everything builds and + installs OK in an isolated environment: + + ```shell + rm -rf dist build + python -m build --sdist + python test.py manualtest + ``` + + You should be able to visit and log in + as `foo@example.org` without any problems. 1. Commit and push your changes with a commit message like "Bump version to v1.0.4." From 248eec2a90a8118415467e79c5847bd09d67164a Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:51:23 -0500 Subject: [PATCH 07/27] update testing --- pyproject.toml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6c7ec8a..a413032 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,22 +27,10 @@ exclude = ''' [tool.tox] legacy_tox_ini = """ [tox] -envlist = py35-django22,py3{6,7,8,9,10}-django{40,41,42} +envlist = py3{8,9,10,11,12,13}-django{40,41,42} isolated_build=true -[testenv:py3{5,6,7}] -deps = - -rrequirements-tests.txt - -rrequirements-dev.txt - django40: Django>=4.0,<4.1 - django41: Django>=4.1,<4.2 - django42: Django>=4.2,<4.3 -commands = - # don't run mypy on versions lower than 3.8 because there's a bug that was fixed in - # https://github.com/python/typeshed/pull/1142 but only fixes 3.8+ versions - # this also skips linting and coverage checks on earlier versions, but those should be the same - python -m uaa_client.runtests -[testenv:py3{8,9,10}] +[testenv:py3{8,9,10,11,12,13}] deps = -rrequirements-tests.txt -rrequirements-dev.txt From 4737e309d017d0586ae9e531990d83783fb5e041 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:51:37 -0500 Subject: [PATCH 08/27] fix imports --- uaa_client/tests/urls.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/uaa_client/tests/urls.py b/uaa_client/tests/urls.py index ee3a6d5..b15f172 100644 --- a/uaa_client/tests/urls.py +++ b/uaa_client/tests/urls.py @@ -1,9 +1,11 @@ import django -from django.conf.urls import include, url + +from django.conf.urls import include +from django.urls import re_path _kwargs = {} if django.get_version().startswith("1.8."): _kwargs["namespace"] = "uaa_client" -urlpatterns = [url(r"^auth/", include("uaa_client.urls", **_kwargs))] +urlpatterns = [re_path(r"^auth/", include("uaa_client.urls", **_kwargs))] From 66718cc83ee8027e4f70a29aa82677ba40fd747f Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:51:49 -0500 Subject: [PATCH 09/27] update supported versions --- setup.cfg | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup.cfg b/setup.cfg index 9e0b95d..58b542c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,6 +10,9 @@ classifiers = Development Status :: 3 - Alpha Environment :: Web Environment Framework :: Django + Framework :: Django :: 4.0 + Framework :: Django :: 4.1 + Framework :: Django :: 4.2 Intended Audience :: Developers License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication Operating System :: OS Independent @@ -17,6 +20,11 @@ classifiers = Topic :: Software Development :: Libraries :: Python Modules Programming Language :: Python Programming Language :: Python :: 3 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Topic :: Utilities [options] From be3dcf0c0bdc364e77d9820f9273067356f45cf5 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Thu, 25 Jan 2024 14:56:43 -0500 Subject: [PATCH 10/27] fix imports --- uaa_client/tests/test_decorators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uaa_client/tests/test_decorators.py b/uaa_client/tests/test_decorators.py index 8e8fa83..20549a7 100644 --- a/uaa_client/tests/test_decorators.py +++ b/uaa_client/tests/test_decorators.py @@ -3,7 +3,7 @@ from django.test import TestCase, override_settings from django.http import HttpResponse from django.contrib.auth.models import User -from django.conf.urls import url +from django.urls import re_path from ..decorators import staff_login_required @@ -19,8 +19,8 @@ def staff_only_view_with_custom_login_url(request): urlpatterns = [ - url(r"^staff_only_view/$", staff_only_view), - url( + re_path(r"^staff_only_view/$", staff_only_view), + re_path( r"^staff_only_view_with_custom_login_url/$", staff_only_view_with_custom_login_url, ), From 64933b7a0efd1026a7ce40f80915ccfaef43b97b Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 17:34:05 -0500 Subject: [PATCH 11/27] update UaaRefreshMiddleware tests to pass in get_response argument initialization --- uaa_client/tests/test_middleware.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uaa_client/tests/test_middleware.py b/uaa_client/tests/test_middleware.py index 6ef246c..f749e9c 100644 --- a/uaa_client/tests/test_middleware.py +++ b/uaa_client/tests/test_middleware.py @@ -1,5 +1,6 @@ from unittest.mock import patch from django.test import TestCase +from django.http.response import HttpResponse from .. import middleware from ..middleware import UaaRefreshMiddleware, uaa_refresh_exempt @@ -8,6 +9,8 @@ def noop(): pass +def get_response(request): + return HttpResponse() class FakeUser: def __init__(self, is_authenticated): @@ -23,10 +26,10 @@ def __init__(self, is_authenticated=True, session=None): self.user = FakeUser(is_authenticated) self.session = session or {} - class MiddlewareTests(TestCase): def assertNoRefresh(self, request, view_func=noop, time=0): - mw = UaaRefreshMiddleware() + + mw = UaaRefreshMiddleware(get_response) with patch("time.time", return_value=time): with patch.object(mw, "_refresh") as m: @@ -55,7 +58,7 @@ def test_logout_when_refresh_fails(self, refresh, logout): refresh.return_value = None req = FakeRequest(session={"uaa_expiry": 150}) with patch("time.time", return_value=200): - UaaRefreshMiddleware().process_view(req, noop, [], {}) + UaaRefreshMiddleware(get_response).process_view(req, noop, [], {}) logout.assert_called_once_with(req) @patch.object(middleware, "logout") @@ -64,5 +67,5 @@ def test_no_logout_when_refresh_succeeds(self, refresh, logout): refresh.return_value = "I am a fake access token" req = FakeRequest(session={"uaa_expiry": 150}) with patch("time.time", return_value=200): - UaaRefreshMiddleware().process_view(req, noop, [], {}) + UaaRefreshMiddleware(get_response).process_view(req, noop, [], {}) logout.assert_not_called() From 952f9c43b65bf2a37f61d0e1482ee8a051615ef1 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 17:37:11 -0500 Subject: [PATCH 12/27] remove testing for python 3.13 --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a413032..3324bfe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [tool.black] line-length = 88 -target-version = ['py310'] +target-version = ['py312'] include = '\.pyi?$' exclude = ''' @@ -27,10 +27,10 @@ exclude = ''' [tool.tox] legacy_tox_ini = """ [tox] -envlist = py3{8,9,10,11,12,13}-django{40,41,42} +envlist = py3{8,9,10,11,12}-django{40,41,42} isolated_build=true -[testenv:py3{8,9,10,11,12,13}] +[testenv:py3{8,9,10,11,12}] deps = -rrequirements-tests.txt -rrequirements-dev.txt From 91eb03fbf49d127c29b3150b1c1cfc103da9810b Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 17:38:45 -0500 Subject: [PATCH 13/27] apply black formatting --- example/example/urls.py | 1 + test.py | 1 + uaa_client/tests/test_middleware.py | 5 ++++- uaa_client/views.py | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/example/example/urls.py b/example/example/urls.py index a717dd8..a4fb69e 100644 --- a/example/example/urls.py +++ b/example/example/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ + import django from django.shortcuts import render, redirect from django.conf.urls import include diff --git a/test.py b/test.py index 3cd6e66..739819e 100644 --- a/test.py +++ b/test.py @@ -2,6 +2,7 @@ This holds a couple handy commands that were in setup.py before we moved to static builds using setup.cfg """ + import os import sys import distutils.cmd diff --git a/uaa_client/tests/test_middleware.py b/uaa_client/tests/test_middleware.py index f749e9c..fb09050 100644 --- a/uaa_client/tests/test_middleware.py +++ b/uaa_client/tests/test_middleware.py @@ -9,9 +9,11 @@ def noop(): pass + def get_response(request): return HttpResponse() + class FakeUser: def __init__(self, is_authenticated): self.username = "foo" @@ -26,9 +28,10 @@ def __init__(self, is_authenticated=True, session=None): self.user = FakeUser(is_authenticated) self.session = session or {} + class MiddlewareTests(TestCase): def assertNoRefresh(self, request, view_func=noop, time=0): - + mw = UaaRefreshMiddleware(get_response) with patch("time.time", return_value=time): diff --git a/uaa_client/views.py b/uaa_client/views.py index a25d854..29de7a2 100644 --- a/uaa_client/views.py +++ b/uaa_client/views.py @@ -64,7 +64,9 @@ def oauth2_callback(request): next_url = request.session["oauth2_next_url"] del request.session["oauth2_next_url"] - if not url_has_allowed_host_and_scheme(url=next_url, allowed_hosts=[request.get_host()]): + if not url_has_allowed_host_and_scheme( + url=next_url, allowed_hosts=[request.get_host()] + ): next_url = resolve_url(request.build_absolute_uri(settings.LOGIN_REDIRECT_URL)) return HttpResponseRedirect(next_url) From 63b08ce02be903487d99df9c2f5f6c14f4c57531 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 17:39:23 -0500 Subject: [PATCH 14/27] update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f55801..9a55892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] -## [2.1.5][] - 2024-01-25 +## [2.1.5][] - 2024-01-26 * Update Django dependency to `>=4.0,<5.0` From c66a3d2bd3a07a230851048d6c4cb4db199fbdae Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 17:51:55 -0500 Subject: [PATCH 15/27] remove circleCI config --- .circleci/config.yml | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 2844620..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/python:3.6.2 - environment: - DJANGO_VERSION: 2.2.2 - steps: - - checkout - - restore_cache: - key: deps1-{{ .Branch }}-{{ checksum "requirements-dev.txt" }} - - run: - name: Install Python deps in a venv - command: | - python3 -m venv venv - . venv/bin/activate - pip install -r requirements-dev.txt - pip install -q Django==$DJANGO_VERSION - - save_cache: - key: deps1-{{ .Branch }}-{{ checksum "requirements-dev.txt" }} - paths: - - "venv" - - run: - command: | - . venv/bin/activate - python setup.py ultratest - - store_artifacts: - path: test-reports/ - destination: tr1 - - store_test_results: - path: test-reports/ From d430ffcb17d0ab128d4fb57e0f62e22f75357341 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 17:58:48 -0500 Subject: [PATCH 16/27] update manage.py --- example/manage.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/example/manage.py b/example/manage.py index 2605e37..407b506 100644 --- a/example/manage.py +++ b/example/manage.py @@ -2,9 +2,18 @@ import os import sys -if __name__ == "__main__": +def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) - from django.core.management import execute_from_command_line - execute_from_command_line(sys.argv) +if __name__ == "__main__": + main() From a846e910045085e091205acbd89c84d5a52f5d30 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Fri, 26 Jan 2024 18:04:55 -0500 Subject: [PATCH 17/27] fix docker tests to ignore sqlite database from local testing, if any --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 17599dc..233d383 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,10 @@ RUN pip install cg-django-uaa-${version}.tar.gz && \ COPY example /example +# Remove existing database from local testing, if any, +# otherwise superuser creation below will fail +RUN rm /example/db.sqlite3 + WORKDIR /example RUN python manage.py migrate && \ From 74df40de14bb8a748a97ce0bf5eabccce6c32f0b Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:34:34 -0500 Subject: [PATCH 18/27] add CI pipeline --- ci/pipeline.yml | 135 +++++++++++++++++++++++++++++++++++++++++ ci/prepare-release.sh | 4 ++ ci/prepare-release.yml | 12 ++++ ci/run-tests.sh | 10 +++ ci/run-tests.yml | 9 +++ 5 files changed, 170 insertions(+) create mode 100644 ci/pipeline.yml create mode 100644 ci/prepare-release.sh create mode 100644 ci/prepare-release.yml create mode 100644 ci/run-tests.sh create mode 100644 ci/run-tests.yml diff --git a/ci/pipeline.yml b/ci/pipeline.yml new file mode 100644 index 0000000..48cadc1 --- /dev/null +++ b/ci/pipeline.yml @@ -0,0 +1,135 @@ +--- +jobs: + +- name: run-tests + plan: + - in_parallel: + - get: cg-django-uaa-pr + trigger: true + - get: general-task + - task: run-tests + image: general-task + file: cg-django-uaa-repo-tag/ci/run-tests.yml + +- name: set-self + plan: + - get: cg-django-uaa-repo-tag + trigger: true + - set_pipeline: self + file: cg-django-uaa-repo-tag/ci/pipeline.yml + +- name: create-release + plan: + - get: cg-django-uaa-repo-tag + passed: [run-tests] + trigger: true + - task: prepare-release + file: cg-django-uaa-repo-tag/ci/prepare-release.yml + + - put: cg-django-uaa-release + params: + name: cg-django-uaa-repo-tag/tag + tag: cg-django-uaa-repo-tag/tag + generate_release_notes: true + on_failure: + put: slack + params: + text: | + :x: FAILED to release cg-django-uaa + <$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME|View build details> + channel: ((slack-failure-channel)) + username: ((slack-username)) + icon_url: ((slack-icon-url)) + on_success: + put: slack + params: + text: | + :white_check_mark: Successfully released cg-django-uaa + <$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME|View build details> + channel: ((slack-success-channel)) + username: ((slack-username)) + icon_url: ((slack-icon-url)) + +resources: +- name: cg-django-uaa-pr + type: pull-request + check_every: 1m + source: + repository: cloud-gov/cg-django-uaa + access_token: ((status-access-token)) + disable_forks: true + +# this resource is this repo +# NOTE: we only execute on tag changes not commits, see tag_regex +- name: cg-django-uaa-repo-tag + type: git + source: + uri: https://github.com/cloud-gov/cg-django-uaa.git + # only run on new tags matching pattern like: v0.1.5 + tag_regex: '^v([0-9]+\.){0,2}(\*|[0-9]+)$' + commit_verification_keys: ((cloud-gov-pgp-keys)) + +# This resource for posting to slack +- name: slack + type: slack-notification + source: + url: ((slack-webhook-url)) + +# Resource for creating a new release +- name: cg-django-uaa-release + type: github-release + source: + owner: cloud-gov + repository: cg-django-uaa + access_token: ((cg-ci-bot-ghtoken)) + +- name: general-task + type: registry-image + source: + aws_access_key_id: ((ecr_aws_key)) + aws_secret_access_key: ((ecr_aws_secret)) + repository: general-task + aws_region: us-gov-west-1 + tag: latest + +resource_types: +- name: registry-image + type: registry-image + source: + aws_access_key_id: ((ecr_aws_key)) + aws_secret_access_key: ((ecr_aws_secret)) + repository: registry-image-resource + aws_region: us-gov-west-1 + tag: latest + +- name: slack-notification + type: registry-image + source: + aws_access_key_id: ((ecr_aws_key)) + aws_secret_access_key: ((ecr_aws_secret)) + repository: slack-notification-resource + aws_region: us-gov-west-1 + tag: latest + +- name: git + type: registry-image + source: + aws_access_key_id: ((ecr_aws_key)) + aws_secret_access_key: ((ecr_aws_secret)) + repository: git-resource + aws_region: us-gov-west-1 + tag: latest + +- name: pull-request + type: registry-image + source: + aws_access_key_id: ((ecr_aws_key)) + aws_secret_access_key: ((ecr_aws_secret)) + repository: github-pr-resource + aws_region: us-gov-west-1 + tag: latest + +- name: github-release + type: registry-image + source: + repository: concourse/github-release-resource diff --git a/ci/prepare-release.sh b/ci/prepare-release.sh new file mode 100644 index 0000000..f2c24e8 --- /dev/null +++ b/ci/prepare-release.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +TAG=$(git describe --tags) +echo "$TAG" > tag diff --git a/ci/prepare-release.yml b/ci/prepare-release.yml new file mode 100644 index 0000000..30aaa0d --- /dev/null +++ b/ci/prepare-release.yml @@ -0,0 +1,12 @@ +--- +platform: linux + +inputs: +- name: cg-django-uaa-repo-tag + +outputs: +- name: cg-django-uaa-repo-tag + +run: + dir: cg-django-uaa-repo-tag + path: ci/prepare-release.sh diff --git a/ci/run-tests.sh b/ci/run-tests.sh new file mode 100644 index 0000000..4bc3328 --- /dev/null +++ b/ci/run-tests.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +python -m venv venv +source ./venv/bin/activate +python -m pip install -r requirements-dev.txt + +python -m pip install -e . + +# run tests +tox diff --git a/ci/run-tests.yml b/ci/run-tests.yml new file mode 100644 index 0000000..4ca8582 --- /dev/null +++ b/ci/run-tests.yml @@ -0,0 +1,9 @@ +--- +platform: linux + +inputs: +- name: cg-django-uaa-pr + +run: + dir: cg-django-uaa-pr + path: ci/run-tests.sh From f08ced91619eda1876aa82cae8d9f2829f3289a1 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:43:20 -0500 Subject: [PATCH 19/27] update pipeline --- ci/pipeline.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 48cadc1..246843e 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -9,7 +9,7 @@ jobs: - get: general-task - task: run-tests image: general-task - file: cg-django-uaa-repo-tag/ci/run-tests.yml + file: cg-django-uaa-pr/ci/run-tests.yml - name: set-self plan: @@ -21,16 +21,15 @@ jobs: - name: create-release plan: - get: cg-django-uaa-repo-tag - passed: [run-tests] + passed: [set-self] trigger: true - task: prepare-release file: cg-django-uaa-repo-tag/ci/prepare-release.yml - - - put: cg-django-uaa-release - params: - name: cg-django-uaa-repo-tag/tag - tag: cg-django-uaa-repo-tag/tag - generate_release_notes: true + # - put: cg-django-uaa-release + # params: + # name: cg-django-uaa-repo-tag/tag + # tag: cg-django-uaa-repo-tag/tag + # generate_release_notes: true on_failure: put: slack params: @@ -65,8 +64,9 @@ resources: type: git source: uri: https://github.com/cloud-gov/cg-django-uaa.git + branch: update-django-4 # only run on new tags matching pattern like: v0.1.5 - tag_regex: '^v([0-9]+\.){0,2}(\*|[0-9]+)$' + # tag_regex: '^v([0-9]+\.){0,2}(\*|[0-9]+)$' commit_verification_keys: ((cloud-gov-pgp-keys)) # This resource for posting to slack From 715ee20590b8cf9971b54b3c709544352704341e Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:43:42 -0500 Subject: [PATCH 20/27] update pipeline --- ci/pipeline.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 246843e..e295ff3 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -76,12 +76,12 @@ resources: url: ((slack-webhook-url)) # Resource for creating a new release -- name: cg-django-uaa-release - type: github-release - source: - owner: cloud-gov - repository: cg-django-uaa - access_token: ((cg-ci-bot-ghtoken)) +# - name: cg-django-uaa-release +# type: github-release +# source: +# owner: cloud-gov +# repository: cg-django-uaa +# access_token: ((cg-ci-bot-ghtoken)) - name: general-task type: registry-image From 97d571026d77f5ceade97bf1ccae059e082e6679 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:46:13 -0500 Subject: [PATCH 21/27] make script files executable --- ci/prepare-release.sh | 0 ci/run-tests.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ci/prepare-release.sh mode change 100644 => 100755 ci/run-tests.sh diff --git a/ci/prepare-release.sh b/ci/prepare-release.sh old mode 100644 new mode 100755 diff --git a/ci/run-tests.sh b/ci/run-tests.sh old mode 100644 new mode 100755 From 29a21c0667851604ffcf8c5bb38cdc5e98e4411e Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:52:33 -0500 Subject: [PATCH 22/27] update dependencies --- requirements-dev.txt | 1 - requirements-tests.txt | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7a4370b..372aada 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,5 @@ sphinx sphinx-autobuild sphinx-rtd-theme -mypy>=0.501 recommonmark myst-parser diff --git a/requirements-tests.txt b/requirements-tests.txt index 6647aac..786f3ae 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1 +1,3 @@ httmock>=1.2.5 +mypy>=0.501 +tox From efc691e95f5434be45788f2d454757717a804300 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:52:51 -0500 Subject: [PATCH 23/27] update test script to install test dependencies --- ci/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/run-tests.sh b/ci/run-tests.sh index 4bc3328..7c93135 100755 --- a/ci/run-tests.sh +++ b/ci/run-tests.sh @@ -2,8 +2,8 @@ python -m venv venv source ./venv/bin/activate -python -m pip install -r requirements-dev.txt +python -m pip install -r requirements-tests.txt python -m pip install -e . # run tests From b653bb2ac1799b10cab09ffe1040f8a22de75d65 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:53:03 -0500 Subject: [PATCH 24/27] update pipline to set PR status --- ci/pipeline.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index e295ff3..2cc3d87 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -7,9 +7,23 @@ jobs: - get: cg-django-uaa-pr trigger: true - get: general-task + - put: pull-request + params: + path: pull-request + status: pending - task: run-tests image: general-task file: cg-django-uaa-pr/ci/run-tests.yml + on_failure: + put: pull-request + params: + path: pull-request + status: failure + on_success: + put: pull-request + params: + path: pull-request + status: success - name: set-self plan: From 4c572c9ab246d8ed05832754ee03c481e994379d Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 10:55:38 -0500 Subject: [PATCH 25/27] update pipeline --- ci/pipeline.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 2cc3d87..af74b6e 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -7,22 +7,22 @@ jobs: - get: cg-django-uaa-pr trigger: true - get: general-task - - put: pull-request + - put: cg-django-uaa-pr params: - path: pull-request + path: cg-django-uaa-pr status: pending - task: run-tests image: general-task file: cg-django-uaa-pr/ci/run-tests.yml on_failure: - put: pull-request + put: cg-django-uaa-pr params: - path: pull-request + path: cg-django-uaa-pr status: failure on_success: - put: pull-request + put: cg-django-uaa-pr params: - path: pull-request + path: cg-django-uaa-pr status: success - name: set-self From df38f386fc9c8972adfa8e8f825fef6526a27e35 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 11:15:38 -0500 Subject: [PATCH 26/27] update test deps --- requirements-tests.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-tests.txt b/requirements-tests.txt index 786f3ae..1dc2b9e 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,3 +1,4 @@ httmock>=1.2.5 mypy>=0.501 tox +types-requests From 3764e3d865355531c7785be78037820bf9b4cec1 Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 29 Jan 2024 11:28:09 -0500 Subject: [PATCH 27/27] move tox config to tox.ini --- pyproject.toml | 18 ------------------ tox.ini | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 tox.ini diff --git a/pyproject.toml b/pyproject.toml index 3324bfe..280c4bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,21 +23,3 @@ exclude = ''' )/ ) ''' - -[tool.tox] -legacy_tox_ini = """ -[tox] -envlist = py3{8,9,10,11,12}-django{40,41,42} -isolated_build=true - -[testenv:py3{8,9,10,11,12}] -deps = - -rrequirements-tests.txt - -rrequirements-dev.txt - django40: Django>=4.0,<4.1 - django41: Django>=4.1,<4.2 - django42: Django>=4.2,<4.3 -commands = - python -m uaa_client.runtests - python -m mypy uaa_client -""" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..2a1a309 --- /dev/null +++ b/tox.ini @@ -0,0 +1,14 @@ +[tox] +envlist = py3{8,9,10,11,12}-django{40,41,42} +isolated_build = true + +[testenv:py3{8,9,10,11,12}] +deps = + -rrequirements-tests.txt + -rrequirements-dev.txt + django40: Django>=4.0,<4.1 + django41: Django>=4.1,<4.2 + django42: Django>=4.2,<4.3 +commands = + python -m uaa_client.runtests -v + python -m mypy uaa_client -v