Merge ~lvoytek/ubuntu/+source/django-oauth-toolkit:django4-compatibility into ubuntu/+source/django-oauth-toolkit:ubuntu/devel

Proposed by Lena Voytek
Status: Merged
Approved by: git-ubuntu bot
Approved revision: not available
Merged at revision: 7189c838da7ec67eca67488021621045281f55f0
Proposed branch: ~lvoytek/ubuntu/+source/django-oauth-toolkit:django4-compatibility
Merge into: ubuntu/+source/django-oauth-toolkit:ubuntu/devel
Diff against target: 228 lines (+194/-1)
4 files modified
debian/changelog (+8/-0)
debian/control (+2/-1)
debian/patches/remove-bulk_create-testsuite-for-django4.patch (+183/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
git-ubuntu bot Approve
Steve Langasek (community) Approve
Canonical Server Pending
Canonical Server Reporter Pending
Review via email: mp+450072@code.launchpad.net

Description of the change

Fix testsuite with upstream commit to work with Django 4

PPA: https://launchpad.net/~lvoytek/+archive/ubuntu/django-4-mantic

Local autopkgtest results:
autopkgtest [15:36:10]: @@@@@@@@@@@@@@@@@@@@ summary
upstream PASS
qemu-system-x86_64: terminating on signal 15 from pid 70488 (/usr/bin/python3)

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) :
review: Approve
Revision history for this message
git-ubuntu bot (git-ubuntu-bot) wrote :

Approvers: vorlon, lvoytek
Uploaders: vorlon
MP auto-approved

review: Approve
Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

Package uploaded:

Uploading django-oauth-toolkit_1.7.0-2ubuntu1.dsc
Uploading django-oauth-toolkit_1.7.0-2ubuntu1.debian.tar.xz
Uploading django-oauth-toolkit_1.7.0-2ubuntu1_source.buildinfo
Uploading django-oauth-toolkit_1.7.0-2ubuntu1_source.changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 1d4b9b3..799400f 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,11 @@
6+django-oauth-toolkit (1.7.0-2ubuntu1) mantic; urgency=medium
7+
8+ * d/p/remove-bulk_create-testsuite-for-django4.patch: Remove use of
9+ bulk_create in testsuite to maintain compatibility with Django 4
10+ (LP: #2022089)
11+
12+ -- Lena Voytek <lena.voytek@canonical.com> Mon, 28 Aug 2023 14:29:04 -0700
13+
14 django-oauth-toolkit (1.7.0-2) unstable; urgency=medium
15
16 [ Debian Janitor ]
17diff --git a/debian/control b/debian/control
18index fa92629..6d1044e 100644
19--- a/debian/control
20+++ b/debian/control
21@@ -1,7 +1,8 @@
22 Source: django-oauth-toolkit
23 Section: python
24 Priority: optional
25-Maintainer: Debian Python Team <team+python@tracker.debian.org>
26+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
27+XSBC-Original-Maintainer: Debian Python Team <team+python@tracker.debian.org>
28 Uploaders:
29 Michael Fladischer <fladi@debian.org>,
30 Thomas Goirand <zigo@debian.org>,
31diff --git a/debian/patches/remove-bulk_create-testsuite-for-django4.patch b/debian/patches/remove-bulk_create-testsuite-for-django4.patch
32new file mode 100644
33index 0000000..7ced9e7
34--- /dev/null
35+++ b/debian/patches/remove-bulk_create-testsuite-for-django4.patch
36@@ -0,0 +1,183 @@
37+Description: Remove use of bulk_create in testsuite due to changes in django 4.
38+Author: Alan Crosswell <alan@columbia.edu>
39+Origin: upstream, https://github.com/jazzband/django-oauth-toolkit/commit/a12a56e8f44ccfd5ef03c9921afe93f595bf7cfa
40+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/mantic/+source/django-oauth-toolkit/+bug/2022089
41+Last-Update: 2023-08-28
42+---
43+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
44+--- a/tests/test_models.py
45++++ b/tests/test_models.py
46+@@ -298,9 +298,11 @@
47+ super().setUp()
48+ # Insert many tokens, both expired and not, and grants.
49+ self.num_tokens = 100
50+- now = timezone.now()
51+- earlier = now - timedelta(seconds=100)
52+- later = now + timedelta(seconds=100)
53++ self.delta_secs = 1000
54++ self.now = timezone.now()
55++ self.earlier = self.now - timedelta(seconds=self.delta_secs)
56++ self.later = self.now + timedelta(seconds=self.delta_secs)
57++
58+ app = Application.objects.create(
59+ name="test_app",
60+ redirect_uris="http://localhost http://example.com http://example.org",
61+@@ -309,58 +311,54 @@
62+ authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
63+ )
64+ # make 200 access tokens, half current and half expired.
65+- expired_access_tokens = AccessToken.objects.bulk_create(
66+- AccessToken(token="expired AccessToken {}".format(i), expires=earlier)
67++ expired_access_tokens = [
68++ AccessToken(token="expired AccessToken {}".format(i), expires=self.earlier)
69+ for i in range(self.num_tokens)
70+- )
71+- current_access_tokens = AccessToken.objects.bulk_create(
72+- AccessToken(token=f"current AccessToken {i}", expires=later) for i in range(self.num_tokens)
73+- )
74++ ]
75++ for a in expired_access_tokens:
76++ a.save()
77++
78++ current_access_tokens = [
79++ AccessToken(token=f"current AccessToken {i}", expires=self.later) for i in range(self.num_tokens)
80++ ]
81++ for a in current_access_tokens:
82++ a.save()
83++
84+ # Give the first half of the access tokens a refresh token,
85+ # alternating between current and expired ones.
86+- RefreshToken.objects.bulk_create(
87++ for i in range(0, len(expired_access_tokens) // 2, 2):
88+ RefreshToken(
89+ token=f"expired AT's refresh token {i}",
90+ application=app,
91+- access_token=expired_access_tokens[i].pk,
92++ access_token=expired_access_tokens[i],
93+ user=self.user,
94+- )
95+- for i in range(0, len(expired_access_tokens) // 2, 2)
96+- )
97+- RefreshToken.objects.bulk_create(
98++ ).save()
99++
100++ for i in range(1, len(current_access_tokens) // 2, 2):
101+ RefreshToken(
102+ token=f"current AT's refresh token {i}",
103+ application=app,
104+- access_token=current_access_tokens[i].pk,
105++ access_token=current_access_tokens[i],
106+ user=self.user,
107+- )
108+- for i in range(1, len(current_access_tokens) // 2, 2)
109+- )
110++ ).save()
111++
112+ # Make some grants, half of which are expired.
113+- Grant.objects.bulk_create(
114++ for i in range(self.num_tokens):
115+ Grant(
116+ user=self.user,
117+ code=f"old grant code {i}",
118+ application=app,
119+- expires=earlier,
120++ expires=self.earlier,
121+ redirect_uri="https://localhost/redirect",
122+- )
123+- for i in range(self.num_tokens)
124+- )
125+- Grant.objects.bulk_create(
126++ ).save()
127++ for i in range(self.num_tokens):
128+ Grant(
129+ user=self.user,
130+ code=f"new grant code {i}",
131+ application=app,
132+- expires=later,
133++ expires=self.later,
134+ redirect_uri="https://localhost/redirect",
135+- )
136+- for i in range(self.num_tokens)
137+- )
138+-
139+- def test_clear_expired_tokens(self):
140+- self.oauth2_settings.REFRESH_TOKEN_EXPIRE_SECONDS = 60
141+- assert clear_expired() is None
142++ ).save()
143+
144+ def test_clear_expired_tokens_incorect_timetype(self):
145+ self.oauth2_settings.REFRESH_TOKEN_EXPIRE_SECONDS = "A"
146+@@ -372,19 +370,61 @@
147+ def test_clear_expired_tokens_with_tokens(self):
148+ self.oauth2_settings.CLEAR_EXPIRED_TOKENS_BATCH_SIZE = 10
149+ self.oauth2_settings.CLEAR_EXPIRED_TOKENS_BATCH_INTERVAL = 0.0
150+- at_count = AccessToken.objects.count()
151+- assert at_count == 2 * self.num_tokens, f"{2 * self.num_tokens} access tokens should exist."
152+- rt_count = RefreshToken.objects.count()
153+- assert rt_count == self.num_tokens // 2, f"{self.num_tokens // 2} refresh tokens should exist."
154+- gt_count = Grant.objects.count()
155+- assert gt_count == self.num_tokens * 2, f"{self.num_tokens * 2} grants should exist."
156++ self.oauth2_settings.REFRESH_TOKEN_EXPIRE_SECONDS = self.delta_secs // 2
157++
158++ # before clear_expired(), confirm setup as expected
159++ initial_at_count = AccessToken.objects.count()
160++ assert initial_at_count == 2 * self.num_tokens, f"{2 * self.num_tokens} access tokens should exist."
161++ initial_expired_at_count = AccessToken.objects.filter(expires__lte=self.now).count()
162++ assert (
163++ initial_expired_at_count == self.num_tokens
164++ ), f"{self.num_tokens} expired access tokens should exist."
165++ initial_current_at_count = AccessToken.objects.filter(expires__gt=self.now).count()
166++ assert (
167++ initial_current_at_count == self.num_tokens
168++ ), f"{self.num_tokens} current access tokens should exist."
169++ initial_rt_count = RefreshToken.objects.count()
170++ assert (
171++ initial_rt_count == self.num_tokens // 2
172++ ), f"{self.num_tokens // 2} refresh tokens should exist."
173++ initial_rt_expired_at_count = RefreshToken.objects.filter(access_token__expires__lte=self.now).count()
174++ assert (
175++ initial_rt_expired_at_count == initial_rt_count / 2
176++ ), "half the refresh tokens should be for expired access tokens."
177++ initial_rt_current_at_count = RefreshToken.objects.filter(access_token__expires__gt=self.now).count()
178++ assert (
179++ initial_rt_current_at_count == initial_rt_count / 2
180++ ), "half the refresh tokens should be for current access tokens."
181++ initial_gt_count = Grant.objects.count()
182++ assert initial_gt_count == self.num_tokens * 2, f"{self.num_tokens * 2} grants should exist."
183++
184+ clear_expired()
185+- at_count = AccessToken.objects.count()
186+- assert at_count == self.num_tokens, "Half the access tokens should not have been deleted."
187+- rt_count = RefreshToken.objects.count()
188+- assert rt_count == self.num_tokens // 2, "Half of the refresh tokens should have been deleted."
189+- gt_count = Grant.objects.count()
190+- assert gt_count == self.num_tokens, "Half the grants should have been deleted."
191++
192++ # after clear_expired():
193++ remaining_at_count = AccessToken.objects.count()
194++ assert (
195++ remaining_at_count == initial_at_count // 2
196++ ), "half the initial access tokens should still exist."
197++ remaining_expired_at_count = AccessToken.objects.filter(expires__lte=self.now).count()
198++ assert remaining_expired_at_count == 0, "no remaining expired access tokens should still exist."
199++ remaining_current_at_count = AccessToken.objects.filter(expires__gt=self.now).count()
200++ assert (
201++ remaining_current_at_count == initial_current_at_count
202++ ), "all current access tokens should still exist."
203++ remaining_rt_count = RefreshToken.objects.count()
204++ assert remaining_rt_count == initial_rt_count // 2, "half the refresh tokens should still exist."
205++ remaining_rt_expired_at_count = RefreshToken.objects.filter(
206++ access_token__expires__lte=self.now
207++ ).count()
208++ assert remaining_rt_expired_at_count == 0, "no refresh tokens for expired AT's should still exist."
209++ remaining_rt_current_at_count = RefreshToken.objects.filter(
210++ access_token__expires__gt=self.now
211++ ).count()
212++ assert (
213++ remaining_rt_current_at_count == initial_rt_current_at_count
214++ ), "all the refresh tokens for current access tokens should still exist."
215++ remaining_gt_count = Grant.objects.count()
216++ assert remaining_gt_count == initial_gt_count // 2, "half the remaining grants should still exist."
217+
218+
219+ @pytest.mark.django_db
220diff --git a/debian/patches/series b/debian/patches/series
221index 7d7a45f..553a486 100644
222--- a/debian/patches/series
223+++ b/debian/patches/series
224@@ -1,3 +1,4 @@
225 0001-Replace-CDN-URL-with-a-local-bootstrap-CSS-file.patch
226 0002-Disable-test-which-requires-remote-host.patch
227 0003-Do-not-install-tests-subpackages.patch
228+remove-bulk_create-testsuite-for-django4.patch

Subscribers

People subscribed via source and target branches

to all changes: