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
diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
index 71d302f..ea92f5a 100644
--- a/lib/lp/scripts/tests/test_garbo.py
+++ b/lib/lp/scripts/tests/test_garbo.py
@@ -2609,15 +2609,17 @@ class TestGarboTasks(TestCaseWithFactory):
2609 email="whatever", tokentype=LoginTokenType.NEWACCOUNT2609 email="whatever", tokentype=LoginTokenType.NEWACCOUNT
2610 )2610 )
2611 old_token.date_created = now - timedelta(days=666)2611 old_token.date_created = now - timedelta(days=666)
2612 old_token_id = old_token.id
2613 store.add(old_token)2612 store.add(old_token)
2613 store.flush()
2614 old_token_id = old_token.id
26142615
2615 # Create a token that will not be pruned.2616 # Create a token that will not be pruned.
2616 current_token = LoginToken(2617 current_token = LoginToken(
2617 email="whatever", tokentype=LoginTokenType.NEWACCOUNT2618 email="whatever", tokentype=LoginTokenType.NEWACCOUNT
2618 )2619 )
2619 current_token_id = current_token.id
2620 store.add(current_token)2620 store.add(current_token)
2621 store.flush()
2622 current_token_id = current_token.id
26212623
2622 # Run the pruner. Batching is tested by the BulkPruner tests so2624 # Run the pruner. Batching is tested by the BulkPruner tests so
2623 # no need to repeat here.2625 # no need to repeat here.
diff --git a/lib/lp/services/verification/model/logintoken.py b/lib/lp/services/verification/model/logintoken.py
index 572cce2..03a5bc6 100644
--- a/lib/lp/services/verification/model/logintoken.py
+++ b/lib/lp/services/verification/model/logintoken.py
@@ -395,14 +395,16 @@ class LoginTokenSet:
395 "tokentype is not an item of LoginTokenType: %s" % tokentype395 "tokentype is not an item of LoginTokenType: %s" % tokentype
396 )396 )
397 token = create_token(20)397 token = create_token(20)
398 return LoginToken(398 return IStore(LoginToken).add(
399 requester=requester,399 LoginToken(
400 requesteremail=requesteremail,400 requester=requester,
401 email=email,401 requesteremail=requesteremail,
402 token=token,402 email=email,
403 tokentype=tokentype,403 token=token,
404 fingerprint=fingerprint,404 tokentype=tokentype,
405 redirection_url=redirection_url,405 fingerprint=fingerprint,
406 redirection_url=redirection_url,
407 )
406 )408 )
407409
408 def __getitem__(self, tokentext):410 def __getitem__(self, tokentext):

Subscribers

People subscribed via source and target branches

to status/vote changes: