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
1diff --git a/lib/lp/registry/model/codeofconduct.py b/lib/lp/registry/model/codeofconduct.py
2index 2c19f99..65db887 100644
3--- a/lib/lp/registry/model/codeofconduct.py
4+++ b/lib/lp/registry/model/codeofconduct.py
5@@ -199,7 +199,7 @@ class SignedCodeOfConduct(StormBase):
6
7 active = Bool(name='active', allow_none=False, default=False)
8
9- affirmed = Bool(name='affirmed', allow_none=True, default=False,)
10+ affirmed = Bool(name='affirmed', allow_none=False, default=False,)
11
12 version = Unicode(name='version', allow_none=True, default=None)
13
14diff --git a/lib/lp/registry/tests/test_codeofconduct.py b/lib/lp/registry/tests/test_codeofconduct.py
15index 049515c..cc61593 100644
16--- a/lib/lp/registry/tests/test_codeofconduct.py
17+++ b/lib/lp/registry/tests/test_codeofconduct.py
18@@ -5,6 +5,7 @@
19
20 from textwrap import dedent
21
22+from storm.exceptions import NoneError
23 from testtools.matchers import (
24 ContainsDict,
25 Equals,
26@@ -16,6 +17,7 @@ from lp.registry.interfaces.codeofconduct import (
27 ICodeOfConductSet,
28 ISignedCodeOfConductSet,
29 )
30+from lp.registry.model.codeofconduct import SignedCodeOfConduct
31 from lp.services.config import config
32 from lp.services.gpg.handler import PymeSignature
33 from lp.services.gpg.interfaces import (
34@@ -242,3 +244,19 @@ class TestSignedCodeOfConductSet(TestCaseWithFactory):
35 u"You have already affirmed the current Code of Conduct.",
36 getUtility(ISignedCodeOfConductSet).affirmAndStore(
37 user, current.content))
38+
39+
40+class TestSignedCodeOfConduct(TestCaseWithFactory):
41+ layer = ZopelessDatabaseLayer
42+
43+ def test_affirmed_cant_be_instantiated_with_none(self):
44+ self.assertRaises(
45+ NoneError,
46+ SignedCodeOfConduct,
47+ owner=self.factory.makePerson(),
48+ affirmed=None
49+ )
50+
51+ def test_affirmed_cant_be_none(self):
52+ coc = SignedCodeOfConduct(owner=self.factory.makePerson())
53+ self.assertRaises(NoneError, setattr, coc, "affirmed", None)
54diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
55index ce28426..e2471dc 100644
56--- a/lib/lp/scripts/garbo.py
57+++ b/lib/lp/scripts/garbo.py
58@@ -75,7 +75,6 @@ from lp.code.model.revision import (
59 )
60 from lp.oci.model.ocirecipebuild import OCIFile
61 from lp.registry.interfaces.person import IPersonSet
62-from lp.registry.model.codeofconduct import SignedCodeOfConduct
63 from lp.registry.model.person import Person
64 from lp.registry.model.product import Product
65 from lp.registry.model.sourcepackagename import SourcePackageName
66@@ -1765,29 +1764,6 @@ class PopulateSnapBuildStoreRevision(TunableLoop):
67 transaction.commit()
68
69
70-class PopulateSignedCodeOfConductAffirmed(TunableLoop):
71- """Populates SignedCodeOfConduct.affirmed if not set"""
72-
73- maximum_chunk_size = 5000
74-
75- def __init__(self, log, abort_time=None):
76- super().__init__(log, abort_time)
77- self.store = IMasterStore(SignedCodeOfConduct)
78-
79- def findSignedCodeOfConducts(self):
80- return self.store.find(
81- SignedCodeOfConduct,
82- SignedCodeOfConduct.affirmed == None
83- )
84-
85- def isDone(self):
86- return self.findSignedCodeOfConducts().is_empty()
87-
88- def __call__(self, chunk_size):
89- self.findSignedCodeOfConducts()[:chunk_size].set(affirmed=False)
90- transaction.commit()
91-
92-
93 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
94 """Abstract base class to run a collection of TunableLoops."""
95 script_name = None # Script name for locking and database user. Override.
96@@ -2048,7 +2024,6 @@ class HourlyDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
97 GitRepositoryPruner,
98 RevisionCachePruner,
99 UnusedSessionPruner,
100- PopulateSignedCodeOfConductAffirmed,
101 ]
102 experimental_tunable_loops = []
103
104diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
105index c539bf7..a700663 100644
106--- a/lib/lp/scripts/tests/test_garbo.py
107+++ b/lib/lp/scripts/tests/test_garbo.py
108@@ -84,7 +84,6 @@ from lp.registry.enums import (
109 from lp.registry.interfaces.accesspolicy import IAccessPolicySource
110 from lp.registry.interfaces.person import IPersonSet
111 from lp.registry.interfaces.teammembership import TeamMembershipStatus
112-from lp.registry.model.codeofconduct import SignedCodeOfConduct
113 from lp.registry.model.commercialsubscription import CommercialSubscription
114 from lp.registry.model.teammembership import TeamMembership
115 from lp.scripts.garbo import (
116@@ -97,7 +96,6 @@ from lp.scripts.garbo import (
117 load_garbo_job_state,
118 LoginTokenPruner,
119 OpenIDConsumerAssociationPruner,
120- PopulateSignedCodeOfConductAffirmed,
121 PopulateSnapBuildStoreRevision,
122 ProductVCSPopulator,
123 save_garbo_job_state,
124@@ -2047,21 +2045,6 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
125 switch_dbuser('testadmin')
126 self.assertEqual(build1._store_upload_revision, 1)
127
128- def test_PopulateSignedCodeOfConductAffirmed(self):
129- switch_dbuser('testadmin')
130- populator = PopulateSignedCodeOfConductAffirmed(log=None)
131- for _ in range(5):
132- person = self.factory.makePerson()
133- SignedCodeOfConduct(owner=person).affirmed = None
134-
135- result_set = populator.findSignedCodeOfConducts()
136- self.assertGreater(result_set.count(), 0)
137-
138- self.runHourly()
139-
140- result_set = populator.findSignedCodeOfConducts()
141- self.assertTrue(result_set.is_empty())
142-
143
144 class TestGarboTasks(TestCaseWithFactory):
145 layer = LaunchpadZopelessLayer

Subscribers

People subscribed via source and target branches

to status/vote changes: