Merge ~jugmac00/launchpad:SignedCodeOfConduct.affirmed-cant-be-None-anymore into launchpad:master

Proposed by Jürgen Gmach
Status: Merged
Approved by: Jürgen Gmach
Approved revision: 96de8e99a7906e58209a0d04447915ff0638f9db
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~jugmac00/launchpad:SignedCodeOfConduct.affirmed-cant-be-None-anymore
Merge into: launchpad:master
Diff against target: 145 lines (+19/-43)
4 files modified
lib/lp/registry/model/codeofconduct.py (+1/-1)
lib/lp/registry/tests/test_codeofconduct.py (+18/-0)
lib/lp/scripts/garbo.py (+0/-25)
lib/lp/scripts/tests/test_garbo.py (+0/-17)
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+410429@code.launchpad.net

Commit message

SignedCodeOfConduct.affirmed can't be None anymore

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/registry/model/codeofconduct.py b/lib/lp/registry/model/codeofconduct.py
index 2c19f99..65db887 100644
--- a/lib/lp/registry/model/codeofconduct.py
+++ b/lib/lp/registry/model/codeofconduct.py
@@ -199,7 +199,7 @@ class SignedCodeOfConduct(StormBase):
199199
200 active = Bool(name='active', allow_none=False, default=False)200 active = Bool(name='active', allow_none=False, default=False)
201201
202 affirmed = Bool(name='affirmed', allow_none=True, default=False,)202 affirmed = Bool(name='affirmed', allow_none=False, default=False,)
203203
204 version = Unicode(name='version', allow_none=True, default=None)204 version = Unicode(name='version', allow_none=True, default=None)
205205
diff --git a/lib/lp/registry/tests/test_codeofconduct.py b/lib/lp/registry/tests/test_codeofconduct.py
index 049515c..cc61593 100644
--- a/lib/lp/registry/tests/test_codeofconduct.py
+++ b/lib/lp/registry/tests/test_codeofconduct.py
@@ -5,6 +5,7 @@
55
6from textwrap import dedent6from textwrap import dedent
77
8from storm.exceptions import NoneError
8from testtools.matchers import (9from testtools.matchers import (
9 ContainsDict,10 ContainsDict,
10 Equals,11 Equals,
@@ -16,6 +17,7 @@ from lp.registry.interfaces.codeofconduct import (
16 ICodeOfConductSet,17 ICodeOfConductSet,
17 ISignedCodeOfConductSet,18 ISignedCodeOfConductSet,
18 )19 )
20from lp.registry.model.codeofconduct import SignedCodeOfConduct
19from lp.services.config import config21from lp.services.config import config
20from lp.services.gpg.handler import PymeSignature22from lp.services.gpg.handler import PymeSignature
21from lp.services.gpg.interfaces import (23from lp.services.gpg.interfaces import (
@@ -242,3 +244,19 @@ class TestSignedCodeOfConductSet(TestCaseWithFactory):
242 u"You have already affirmed the current Code of Conduct.",244 u"You have already affirmed the current Code of Conduct.",
243 getUtility(ISignedCodeOfConductSet).affirmAndStore(245 getUtility(ISignedCodeOfConductSet).affirmAndStore(
244 user, current.content))246 user, current.content))
247
248
249class TestSignedCodeOfConduct(TestCaseWithFactory):
250 layer = ZopelessDatabaseLayer
251
252 def test_affirmed_cant_be_instantiated_with_none(self):
253 self.assertRaises(
254 NoneError,
255 SignedCodeOfConduct,
256 owner=self.factory.makePerson(),
257 affirmed=None
258 )
259
260 def test_affirmed_cant_be_none(self):
261 coc = SignedCodeOfConduct(owner=self.factory.makePerson())
262 self.assertRaises(NoneError, setattr, coc, "affirmed", None)
diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
index ce28426..e2471dc 100644
--- a/lib/lp/scripts/garbo.py
+++ b/lib/lp/scripts/garbo.py
@@ -75,7 +75,6 @@ from lp.code.model.revision import (
75 )75 )
76from lp.oci.model.ocirecipebuild import OCIFile76from lp.oci.model.ocirecipebuild import OCIFile
77from lp.registry.interfaces.person import IPersonSet77from lp.registry.interfaces.person import IPersonSet
78from lp.registry.model.codeofconduct import SignedCodeOfConduct
79from lp.registry.model.person import Person78from lp.registry.model.person import Person
80from lp.registry.model.product import Product79from lp.registry.model.product import Product
81from lp.registry.model.sourcepackagename import SourcePackageName80from lp.registry.model.sourcepackagename import SourcePackageName
@@ -1765,29 +1764,6 @@ class PopulateSnapBuildStoreRevision(TunableLoop):
1765 transaction.commit()1764 transaction.commit()
17661765
17671766
1768class PopulateSignedCodeOfConductAffirmed(TunableLoop):
1769 """Populates SignedCodeOfConduct.affirmed if not set"""
1770
1771 maximum_chunk_size = 5000
1772
1773 def __init__(self, log, abort_time=None):
1774 super().__init__(log, abort_time)
1775 self.store = IMasterStore(SignedCodeOfConduct)
1776
1777 def findSignedCodeOfConducts(self):
1778 return self.store.find(
1779 SignedCodeOfConduct,
1780 SignedCodeOfConduct.affirmed == None
1781 )
1782
1783 def isDone(self):
1784 return self.findSignedCodeOfConducts().is_empty()
1785
1786 def __call__(self, chunk_size):
1787 self.findSignedCodeOfConducts()[:chunk_size].set(affirmed=False)
1788 transaction.commit()
1789
1790
1791class BaseDatabaseGarbageCollector(LaunchpadCronScript):1767class BaseDatabaseGarbageCollector(LaunchpadCronScript):
1792 """Abstract base class to run a collection of TunableLoops."""1768 """Abstract base class to run a collection of TunableLoops."""
1793 script_name = None # Script name for locking and database user. Override.1769 script_name = None # Script name for locking and database user. Override.
@@ -2048,7 +2024,6 @@ class HourlyDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
2048 GitRepositoryPruner,2024 GitRepositoryPruner,
2049 RevisionCachePruner,2025 RevisionCachePruner,
2050 UnusedSessionPruner,2026 UnusedSessionPruner,
2051 PopulateSignedCodeOfConductAffirmed,
2052 ]2027 ]
2053 experimental_tunable_loops = []2028 experimental_tunable_loops = []
20542029
diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
index c539bf7..a700663 100644
--- a/lib/lp/scripts/tests/test_garbo.py
+++ b/lib/lp/scripts/tests/test_garbo.py
@@ -84,7 +84,6 @@ from lp.registry.enums import (
84from lp.registry.interfaces.accesspolicy import IAccessPolicySource84from lp.registry.interfaces.accesspolicy import IAccessPolicySource
85from lp.registry.interfaces.person import IPersonSet85from lp.registry.interfaces.person import IPersonSet
86from lp.registry.interfaces.teammembership import TeamMembershipStatus86from lp.registry.interfaces.teammembership import TeamMembershipStatus
87from lp.registry.model.codeofconduct import SignedCodeOfConduct
88from lp.registry.model.commercialsubscription import CommercialSubscription87from lp.registry.model.commercialsubscription import CommercialSubscription
89from lp.registry.model.teammembership import TeamMembership88from lp.registry.model.teammembership import TeamMembership
90from lp.scripts.garbo import (89from lp.scripts.garbo import (
@@ -97,7 +96,6 @@ from lp.scripts.garbo import (
97 load_garbo_job_state,96 load_garbo_job_state,
98 LoginTokenPruner,97 LoginTokenPruner,
99 OpenIDConsumerAssociationPruner,98 OpenIDConsumerAssociationPruner,
100 PopulateSignedCodeOfConductAffirmed,
101 PopulateSnapBuildStoreRevision,99 PopulateSnapBuildStoreRevision,
102 ProductVCSPopulator,100 ProductVCSPopulator,
103 save_garbo_job_state,101 save_garbo_job_state,
@@ -2047,21 +2045,6 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
2047 switch_dbuser('testadmin')2045 switch_dbuser('testadmin')
2048 self.assertEqual(build1._store_upload_revision, 1)2046 self.assertEqual(build1._store_upload_revision, 1)
20492047
2050 def test_PopulateSignedCodeOfConductAffirmed(self):
2051 switch_dbuser('testadmin')
2052 populator = PopulateSignedCodeOfConductAffirmed(log=None)
2053 for _ in range(5):
2054 person = self.factory.makePerson()
2055 SignedCodeOfConduct(owner=person).affirmed = None
2056
2057 result_set = populator.findSignedCodeOfConducts()
2058 self.assertGreater(result_set.count(), 0)
2059
2060 self.runHourly()
2061
2062 result_set = populator.findSignedCodeOfConducts()
2063 self.assertTrue(result_set.is_empty())
2064
20652048
2066class TestGarboTasks(TestCaseWithFactory):2049class TestGarboTasks(TestCaseWithFactory):
2067 layer = LaunchpadZopelessLayer2050 layer = LaunchpadZopelessLayer

Subscribers

People subscribed via source and target branches

to status/vote changes: