~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/tests/test_processaccepted.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-04-28 09:48:32 UTC
  • mfrom: (12936.1.4 bug-761439)
  • Revision ID: launchpad@pqm.canonical.com-20110428094832-ftw68grkd7f3ff7z
[r=stevenk][bug=761439] process-accepted now commits after processing
        each upload.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from cStringIO import StringIO
7
7
 
8
8
from debian.deb822 import Changes
 
9
from testtools.matchers import LessThan
9
10
 
10
11
from canonical.config import config
11
12
from canonical.launchpad.webapp.errorlog import ErrorReportingUtility
15
16
from lp.soyuz.enums import (
16
17
    ArchivePurpose,
17
18
    PackagePublishingStatus,
 
19
    PackageUploadStatus,
18
20
    )
19
21
from lp.soyuz.scripts.processaccepted import (
20
22
    get_bugs_from_changes_file,
131
133
            published_copy.status, PackagePublishingStatus.PENDING)
132
134
        self.assertEqual(copy_source, published_copy.sourcepackagerelease)
133
135
 
 
136
    def test_commits_after_each_item(self):
 
137
        # Test that the script commits after each item, not just at the end.
 
138
        uploads = [
 
139
            self.createWaitingAcceptancePackage(
 
140
                distroseries=
 
141
                    self.factory.makeDistroSeries(distribution=self.distro),
 
142
                sourcename='source%d' % i)
 
143
            for i in range(3)]
 
144
 
 
145
        class UploadCheckingSynchronizer:
 
146
 
 
147
            commit_count = 0
 
148
 
 
149
            def beforeCompletion(inner_self, txn):
 
150
                pass
 
151
 
 
152
            def afterCompletion(inner_self, txn):
 
153
                if txn.status != 'Committed':
 
154
                    return
 
155
                inner_self.commit_count += 1
 
156
                done_count = len([
 
157
                    upload for upload in uploads
 
158
                    if upload.package_upload.status ==
 
159
                        PackageUploadStatus.DONE])
 
160
                self.assertEqual(
 
161
                    min(len(uploads), inner_self.commit_count),
 
162
                    done_count)
 
163
 
 
164
        script = self.getScript([])
 
165
        self.layer.txn.commit()
 
166
        self.layer.switchDbUser(self.dbuser)
 
167
        synch = UploadCheckingSynchronizer()
 
168
        script.txn.registerSynch(synch)
 
169
        script.main()
 
170
        self.assertThat(len(uploads), LessThan(synch.commit_count))
 
171
 
134
172
 
135
173
class TestBugsFromChangesFile(TestCaseWithFactory):
136
174
    """Test get_bugs_from_changes_file."""