← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/launchpad:improve-logging-for-the-account-close-script into launchpad:master

 

Simone Pelosi has proposed merging ~pelpsi/launchpad:improve-logging-for-the-account-close-script into launchpad:master.

Commit message:
Added a log that nofifies when the account is closed
    
The new log notifies when the account is closed before committing the transaction.


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pelpsi/launchpad/+git/launchpad/+merge/442988
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/launchpad:improve-logging-for-the-account-close-script into launchpad:master.
diff --git a/lib/lp/registry/scripts/closeaccount.py b/lib/lp/registry/scripts/closeaccount.py
index 2a5657a..73510a0 100644
--- a/lib/lp/registry/scripts/closeaccount.py
+++ b/lib/lp/registry/scripts/closeaccount.py
@@ -626,6 +626,7 @@ def close_account(username, log):
             "User %s is still referenced" % person_name
         )
 
+    log.info("%s's account closed" % person_name)
     return True
 
 
diff --git a/lib/lp/registry/scripts/tests/test_closeaccount.py b/lib/lp/registry/scripts/tests/test_closeaccount.py
index e9cd611..9177ddc 100644
--- a/lib/lp/registry/scripts/tests/test_closeaccount.py
+++ b/lib/lp/registry/scripts/tests/test_closeaccount.py
@@ -83,9 +83,9 @@ class TestCloseAccount(TestCaseWithFactory):
             self.addDetail("log", script.logger.content)
             flush_database_caches()
 
-    def makePopulatedUser(self):
+    def makePopulatedUser(self, name=None):
         """Return a person and account linked to some personal information."""
-        person = self.factory.makePerson(karma=10)
+        person = self.factory.makePerson(name=name, karma=10)
         self.assertEqual(AccountStatus.ACTIVE, person.account.status)
         self.assertNotEqual([], list(person.account.openid_identifiers))
         self.factory.makeBugTask().transitionToAssignee(person, validate=False)
@@ -201,6 +201,23 @@ class TestCloseAccount(TestCaseWithFactory):
         )
         self.assertNotRemoved(account_id, person_id)
 
+    def test_close_account_logs(self):
+        person, person_id, account_id = self.makePopulatedUser(
+            name="test-account-to-close"
+        )
+        script = self.makeScript([person.name])
+        with dbuser("launchpad"):
+            self.runScript(script)
+        self.assertRemoved(account_id, person_id)
+        self.assertIn(
+            "Closing test-account-to-close's account",
+            script.logger.getLogBuffer(),
+        )
+        self.assertIn(
+            "test-account-to-close's account closed",
+            script.logger.getLogBuffer(),
+        )
+
     def test_single_by_name(self):
         person, person_id, account_id = self.makePopulatedUser()
         script = self.makeScript([person.name])