From 769cc8c933a79efb9bfcd9a6b2e71e4499e4b4d5 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 21 Apr 2020 22:51:16 +0200 Subject: [PATCH] Fixed the remaining tests. refs: #5 --- dsa/tests/test_housekeeping.py | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/dsa/tests/test_housekeeping.py b/dsa/tests/test_housekeeping.py index 407834a..35126f2 100644 --- a/dsa/tests/test_housekeeping.py +++ b/dsa/tests/test_housekeeping.py @@ -44,12 +44,10 @@ class TestCheckLDAPConsistency(ProcessFixtureMixin, TestCase): res = list(Inconsistency.objects.all()) self.assertEqual(len(res), len(items)) for inc, item in zip(res, items): - person = item.get("person") - if person is not None: - self.assertEqual(inc.person, person) - text = item.get("text") - if text is not None: - self.assertEqual(inc.text, text) + if "person" in item: + self.assertEqual(inc.person, item["person"]) + if "text" in item: + self.assertEqual(inc.text, item["text"]) def test_new_removed(self): with mock.patch("dsa.udldap.list_people") as m: @@ -57,10 +55,11 @@ class TestCheckLDAPConsistency(ProcessFixtureMixin, TestCase): MockEntry("newdd", supplementaryGid=["Debian"], cn="tcn", mn="tmn", sn="tsn", emailForward="test@example.org", accountStatus=None) ] - self.hk.run(CheckLDAPConsistency) - self.assertInconsistenciesEqual([ - {"person": self.persons.newdd, - "text": "newdd: created to mirror a removed DD account from LDAP"}, + with self.assertLogs() as log: + self.hk.run(CheckLDAPConsistency) + self.assertEqual(log.output, [ + "WARNING:dsa.housekeeping:test.CheckLDAPConsistency:" + " newdd: created to mirror a removed DD account from LDAP", ]) p = Person.objects.get(ldap_fields__uid="newdd") @@ -85,7 +84,8 @@ class TestCheckLDAPConsistency(ProcessFixtureMixin, TestCase): with self.assertLogs() as log: self.hk.run(CheckLDAPConsistency) self.assertEqual(log.output, [ - "WARNING:dsa.housekeeping:test.CheckLDAPConsistency: newguest: created to mirror a removed guest account from LDAP"]) + "WARNING:dsa.housekeeping:test.CheckLDAPConsistency:" + " newguest: created to mirror a removed guest account from LDAP"]) p = Person.objects.get(ldap_fields__uid="newguest") audit = ["{}:{}".format(l.author.lookup_key, l.notes) for l in p.audit_log.all()] @@ -109,8 +109,8 @@ class TestCheckLDAPConsistency(ProcessFixtureMixin, TestCase): ] self.hk.run(CheckLDAPConsistency) self.assertInconsistenciesEqual([ - {"person": self.persons.newdd, - "text": "person has fingerprint 66B4DFB68CB24EBBD8650BC4F4B4B0CC797EBFAB and gid 800 in LDAP," + {"person": None, + "text": "newdd has fingerprint 66B4DFB68CB24EBBD8650BC4F4B4B0CC797EBFAB and gid 800 in LDAP," " but is not in our db"}, ]) @@ -250,11 +250,14 @@ class TestCheckLDAPConsistency(ProcessFixtureMixin, TestCase): with self.assertLogs() as log: self.hk.run(CheckLDAPConsistency) self.assertEqual(log.output, [ - "WARNING:dsa.housekeeping:None: dd_u has accountStatus 'retiring 2018-03-20' " - '(comment: None) but in our db the state is Debian Developer, uploading ' - '[retiring]', - "INFO:dsa.housekeeping:None: dd_u changing email_ldap from dd_u@example.org to test@example.org" - " (source: LDAP)", + "INFO:dsa.housekeeping:test.CheckLDAPConsistency: dd_u changing email_ldap" + " from dd_u@example.org to test@example.org (source: LDAP)", + ]) + self.assertInconsistenciesEqual([ + {"person": self.persons.dd_u, + "text": "person has accountStatus 'retiring 2018-03-20' " + '(comment: None) but in our db the state is Debian Developer, uploading ' + '[retiring]'}, ]) process.approved_by = self.persons.dam @@ -263,7 +266,7 @@ class TestCheckLDAPConsistency(ProcessFixtureMixin, TestCase): with self.assertLogs() as log: self.hk.run(CheckLDAPConsistency) self.assertEqual(log.output, [ - "INFO:dsa.housekeeping:None: dd_u closed from dsa: retiring 2018-03-20", + "INFO:dsa.housekeeping:test.CheckLDAPConsistency: dd_u closed from dsa: retiring 2018-03-20", ]) p = self.persons.dd_u -- GitLab