Merge ~cjwatson/launchpad:fix-stormify-logintoken into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 9f738a66b8a762bd0fac4b7f6bb41636382db97c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-stormify-logintoken
Merge into: launchpad:master
Diff against target: 53 lines (+14/-10)
2 files modified
lib/lp/scripts/tests/test_garbo.py (+4/-2)
lib/lp/services/verification/model/logintoken.py (+10/-8)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+446419@code.launchpad.net

Commit message

Fix bugs in conversion of LoginToken to Storm

Description of the change

`LoginTokenSet.new` needs to explicitly add the new token to the store, as it may not be linked to any other object if it doesn't have a requester (e.g. `LoginTokenType.BUGTRACKER` tokens).

`test_LoginTokenPruner` needs to flush SQL statements for new tokens to the database before trying to get their IDs.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Self-approving this, as this is just some small and fairly clear fixes in code well-covered by the test suite.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
2index 71d302f..ea92f5a 100644
3--- a/lib/lp/scripts/tests/test_garbo.py
4+++ b/lib/lp/scripts/tests/test_garbo.py
5@@ -2609,15 +2609,17 @@ class TestGarboTasks(TestCaseWithFactory):
6 email="whatever", tokentype=LoginTokenType.NEWACCOUNT
7 )
8 old_token.date_created = now - timedelta(days=666)
9- old_token_id = old_token.id
10 store.add(old_token)
11+ store.flush()
12+ old_token_id = old_token.id
13
14 # Create a token that will not be pruned.
15 current_token = LoginToken(
16 email="whatever", tokentype=LoginTokenType.NEWACCOUNT
17 )
18- current_token_id = current_token.id
19 store.add(current_token)
20+ store.flush()
21+ current_token_id = current_token.id
22
23 # Run the pruner. Batching is tested by the BulkPruner tests so
24 # no need to repeat here.
25diff --git a/lib/lp/services/verification/model/logintoken.py b/lib/lp/services/verification/model/logintoken.py
26index 572cce2..03a5bc6 100644
27--- a/lib/lp/services/verification/model/logintoken.py
28+++ b/lib/lp/services/verification/model/logintoken.py
29@@ -395,14 +395,16 @@ class LoginTokenSet:
30 "tokentype is not an item of LoginTokenType: %s" % tokentype
31 )
32 token = create_token(20)
33- return LoginToken(
34- requester=requester,
35- requesteremail=requesteremail,
36- email=email,
37- token=token,
38- tokentype=tokentype,
39- fingerprint=fingerprint,
40- redirection_url=redirection_url,
41+ return IStore(LoginToken).add(
42+ LoginToken(
43+ requester=requester,
44+ requesteremail=requesteremail,
45+ email=email,
46+ token=token,
47+ tokentype=tokentype,
48+ fingerprint=fingerprint,
49+ redirection_url=redirection_url,
50+ )
51 )
52
53 def __getitem__(self, tokentext):

Subscribers

People subscribed via source and target branches

to status/vote changes: