Merge lp:~cjwatson/launchpad/close-account-dry-run into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18955
Proposed branch: lp:~cjwatson/launchpad/close-account-dry-run
Merge into: lp:launchpad
Diff against target: 49 lines (+22/-2)
2 files modified
lib/lp/registry/scripts/closeaccount.py (+13/-2)
lib/lp/registry/scripts/tests/test_closeaccount.py (+9/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/close-account-dry-run
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Launchpad code reviewers Pending
Review via email: mp+366853@code.launchpad.net

Commit message

Add a dry-run mode to close-account.

Description of the change

I keep finding myself hacking something like this in when testing account closures on dogfood, so it'd be better to have it as a proper option.

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

LGTM, even if unfamiliar with Launchpad code itself, this seems pretty straightforward.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/scripts/closeaccount.py'
2--- lib/lp/registry/scripts/closeaccount.py 2019-04-23 09:26:52 +0000
3+++ lib/lp/registry/scripts/closeaccount.py 2019-05-02 17:53:49 +0000
4@@ -410,6 +410,12 @@
5 "Close a person's account, deleting as much personal information "
6 "as possible.")
7
8+ def add_my_options(self):
9+ """See `LaunchpadScript`."""
10+ self.parser.add_option(
11+ "-n", "--dry-run", default=False, action="store_true",
12+ help="Do not commit changes.")
13+
14 def main(self):
15 if not self.args:
16 raise LaunchpadScriptFailure(
17@@ -421,5 +427,10 @@
18 except Exception:
19 self.txn.abort()
20 raise
21- self.logger.debug("Committing changes")
22- self.txn.commit()
23+
24+ if self.options.dry_run:
25+ self.logger.debug("Dry run, so not committing changes")
26+ self.txn.abort()
27+ else:
28+ self.logger.debug("Committing changes")
29+ self.txn.commit()
30
31=== modified file 'lib/lp/registry/scripts/tests/test_closeaccount.py'
32--- lib/lp/registry/scripts/tests/test_closeaccount.py 2019-04-23 09:26:52 +0000
33+++ lib/lp/registry/scripts/tests/test_closeaccount.py 2019-05-02 17:53:49 +0000
34@@ -180,6 +180,15 @@
35 script.logger.getLogBuffer())
36 self.assertNotRemoved(account_id, person_id)
37
38+ def test_dry_run(self):
39+ person, person_id, account_id = self.makePopulatedUser()
40+ script = self.makeScript(['--dry-run', six.ensure_str(person.name)])
41+ with dbuser('launchpad'):
42+ self.runScript(script)
43+ self.assertIn(
44+ 'Dry run, so not committing changes', script.logger.getLogBuffer())
45+ self.assertNotRemoved(account_id, person_id)
46+
47 def test_single_by_name(self):
48 person, person_id, account_id = self.makePopulatedUser()
49 script = self.makeScript([six.ensure_str(person.name)])