Merge lp:~wgrant/launchpad/bprdc into lp:launchpad/db-devel
- bprdc
- Merge into db-devel
Status: | Merged |
---|---|
Approved by: | Henning Eggers |
Approved revision: | no longer in the source branch. |
Merged at revision: | not available |
Proposed branch: | lp:~wgrant/launchpad/bprdc |
Merge into: | lp:launchpad/db-devel |
Prerequisite: | lp:~wgrant/launchpad/get-bpr-by-filename |
Diff against target: |
343 lines (+204/-7) 7 files modified
database/schema/patch-2207-36-0.sql (+15/-0) database/schema/security.cfg (+1/-0) lib/lp/soyuz/interfaces/archive.py (+14/-0) lib/lp/soyuz/interfaces/binarypackagerelease.py (+23/-4) lib/lp/soyuz/model/archive.py (+15/-0) lib/lp/soyuz/model/binarypackagerelease.py (+33/-2) lib/lp/soyuz/tests/test_archive.py (+103/-1) |
To merge this branch: | bzr merge lp:~wgrant/launchpad/bprdc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Julian Edwards (community) | Approve | ||
Henning Eggers (community) | code | Approve | |
Björn Tillenius (community) | db | Approve | |
Stuart Bishop (community) | db | Approve | |
Review via email: mp+21213@code.launchpad.net |
Commit message
Add the model for PPA download stats. Landed by henninge.
Description of the change
This branch adds the model for PPA binary download stats. BinaryPackageRe
BinaryPackageRe
Björn Tillenius (bjornt) wrote : | # |
On Fri, Mar 12, 2010 at 07:20:53AM -0000, William Grant wrote:
> William Grant has proposed merging lp:~wgrant/launchpad/bprdc into lp:launchpad with lp:~wgrant/launchpad/get-bpr-by-filename as a prerequisite.
>
> Requested reviews:
> Björn Tillenius (bjornt): db
> Stuart Bishop (stub): db
> Canonical Launchpad Engineering (launchpad)
>
>
> This branch adds the model for PPA binary download stats.
> BinaryPackageRe
> Archive.
> #139855 for discussion on the issue -- the only thing with which
> everybody is agreed about collecting is counts for each binary package
> release in each archive.
I think this patch is ok, although I have a few questions (and a comment
on the patch itself further down). I'll be on vacation next week, so I
won't block a landing of the patch, waiting for the replies, as long as
my comments are considered, but I'm marking it as needsinfo so that I
can track the discussion more easily.
vote needsinfo
Can you explain shortly how BinaryPackageRe
series? As I understand it, this is only for PPAs, right, since we can't
track the downloads of other archives? Would it make sense to make the
name a bit more specific in that case? At the very least, comments.sql
should explain this. Or will this be used by other archives than PPA
ones?
I couldn't find where everybody agreed about collecting counts for each
binary package release. Can you point me to the right place?
What other things are we likely to want to track in the future, if any?
> === added file 'database/
> --- database/
> +++ database/
> @@ -0,0 +1,15 @@
> +SET client_
> +
> +CREATE TABLE BinaryPackageRe
> + id serial PRIMARY KEY,
> + archive integer NOT NULL REFERENCES Archive,
> + binary_
> + day date NOT NULL,
> + country integer,
> + count integer NOT NULL
> +);
> +
> +ALTER TABLE BinaryPackageRe
> + UNIQUE (archive, binary_
> +
> +INSERT INTO LaunchpadDataba
Shouldn't country be a foreign key to Country?
And looking at the tests, I didn't see any tests for not specifying the
country. That would be good to have.
--
Björn Tillenius | https:/
William Grant (wgrant) wrote : | # |
On Fri, 2010-03-12 at 09:42 +0000, Björn Tillenius wrote:
> Review: Needs Information
> On Fri, Mar 12, 2010 at 07:20:53AM -0000, William Grant wrote:
> > William Grant has proposed merging lp:~wgrant/launchpad/bprdc into lp:launchpad with lp:~wgrant/launchpad/get-bpr-by-filename as a prerequisite.
> >
> > Requested reviews:
> > Björn Tillenius (bjornt): db
> > Stuart Bishop (stub): db
> > Canonical Launchpad Engineering (launchpad)
> >
> >
> > This branch adds the model for PPA binary download stats.
> > BinaryPackageRe
> > Archive.
> > #139855 for discussion on the issue -- the only thing with which
> > everybody is agreed about collecting is counts for each binary package
> > release in each archive.
>
> I think this patch is ok, although I have a few questions (and a comment
> on the patch itself further down). I'll be on vacation next week, so I
> won't block a landing of the patch, waiting for the replies, as long as
> my comments are considered, but I'm marking it as needsinfo so that I
> can track the discussion more easily.
Thanks.
> vote needsinfo
>
> Can you explain shortly how BinaryPackageRe
> series? As I understand it, this is only for PPAs, right, since we can't
> track the downloads of other archives? Would it make sense to make the
> name a bit more specific in that case? At the very least, comments.sql
> should explain this. Or will this be used by other archives than PPA
> ones?
A BinaryPackageRe
distribution series (linked by BinaryPackagePu
was talk a couple of months ago about a desire to use this for the
partner archive too -- I'm not sure if that's still on the cards, but
this schema works fine for that too, and the subsequent branches would
need only slight extension.
The primarily archive is more impossible, since it is heavily mirrored
across hundreds of hosts.
> I couldn't find where everybody agreed about collecting counts for each
> binary package release. Can you point me to the right place?
>
> What other things are we likely to want to track in the future, if any?
The last few comments all speak of counting binaries and indices, but no
concrete method of usefully counting index downloads has yet been
mentioned, and it's much much harder to get right (it involves lots of
guessing). Binary counting is easy and a good first step.
>
> > === added file 'database/
> > --- database/
> > +++ database/
> > @@ -0,0 +1,15 @@
> > +SET client_
> > +
> > +CREATE TABLE BinaryPackageRe
> > + id serial PRIMARY KEY,
> > + archive integer NOT NULL REFERENCES Archive,
> > + binary_
> > + day date NOT NULL,
> > + country integer,
> > + count integer NOT NULL
> > +);
> > +
> > +ALTER TABLE BinaryPackageRe
Stuart Bishop (stub) wrote : | # |
The FOREIGN KEY reference to Country is correct. Thanks.
Björn Tillenius (bjornt) : | # |
Henning Eggers (henninge) wrote : | # |
All is well. Thank you. ;-)
Julian Edwards (julian-edwards) : | # |
Preview Diff
1 | === added file 'database/schema/patch-2207-36-0.sql' | |||
2 | --- database/schema/patch-2207-36-0.sql 1970-01-01 00:00:00 +0000 | |||
3 | +++ database/schema/patch-2207-36-0.sql 2010-03-15 10:41:18 +0000 | |||
4 | @@ -0,0 +1,15 @@ | |||
5 | 1 | SET client_min_messages=ERROR; | ||
6 | 2 | |||
7 | 3 | CREATE TABLE BinaryPackageReleaseDownloadCount ( | ||
8 | 4 | id serial PRIMARY KEY, | ||
9 | 5 | archive integer NOT NULL REFERENCES Archive, | ||
10 | 6 | binary_package_release integer NOT NULL REFERENCES BinaryPackageRelease, | ||
11 | 7 | day date NOT NULL, | ||
12 | 8 | country integer REFERENCES Country, | ||
13 | 9 | count integer NOT NULL | ||
14 | 10 | ); | ||
15 | 11 | |||
16 | 12 | ALTER TABLE BinaryPackageReleaseDownloadCount ADD CONSTRAINT binarypackagereleasedownloadcount__archive__binary_package_release__day__country__key | ||
17 | 13 | UNIQUE (archive, binary_package_release, day, country); | ||
18 | 14 | |||
19 | 15 | INSERT INTO LaunchpadDatabaseRevision VALUES (2207, 36, 0); | ||
20 | 0 | 16 | ||
21 | === modified file 'database/schema/security.cfg' | |||
22 | --- database/schema/security.cfg 2010-03-15 06:23:18 +0000 | |||
23 | +++ database/schema/security.cfg 2010-03-15 10:41:18 +0000 | |||
24 | @@ -131,6 +131,7 @@ | |||
25 | 131 | public.authtoken = SELECT, INSERT, UPDATE, DELETE | 131 | public.authtoken = SELECT, INSERT, UPDATE, DELETE |
26 | 132 | public.binaryandsourcepackagenameview = SELECT | 132 | public.binaryandsourcepackagenameview = SELECT |
27 | 133 | public.binarypackagepublishinghistory = SELECT | 133 | public.binarypackagepublishinghistory = SELECT |
28 | 134 | public.binarypackagereleasedownloadcount= SELECT, INSERT, UPDATE | ||
29 | 134 | public.bountysubscription = SELECT, INSERT, UPDATE, DELETE | 135 | public.bountysubscription = SELECT, INSERT, UPDATE, DELETE |
30 | 135 | public.branchrevision = SELECT, INSERT, UPDATE, DELETE | 136 | public.branchrevision = SELECT, INSERT, UPDATE, DELETE |
31 | 136 | public.branch = SELECT, INSERT, UPDATE, DELETE | 137 | public.branch = SELECT, INSERT, UPDATE, DELETE |
32 | 137 | 138 | ||
33 | === modified file 'lib/lp/soyuz/interfaces/archive.py' | |||
34 | --- lib/lp/soyuz/interfaces/archive.py 2010-03-12 06:19:52 +0000 | |||
35 | +++ lib/lp/soyuz/interfaces/archive.py 2010-03-15 10:41:18 +0000 | |||
36 | @@ -647,6 +647,20 @@ | |||
37 | 647 | archive. | 647 | archive. |
38 | 648 | """ | 648 | """ |
39 | 649 | 649 | ||
40 | 650 | def updatePackageDownloadCount(bpr, day, country, count): | ||
41 | 651 | """Update the daily download count for a given package. | ||
42 | 652 | |||
43 | 653 | :param bpr: The `IBinaryPackageRelease` to update the count for. | ||
44 | 654 | :param day: The date to update the count for. | ||
45 | 655 | :param country: The `ICountry` to update the count for. | ||
46 | 656 | :param count: The new download count. | ||
47 | 657 | |||
48 | 658 | If there's no matching `IBinaryPackageReleaseDownloadCount` entry, | ||
49 | 659 | we create one with the given count. Otherwise we just increase the | ||
50 | 660 | count of the existing one by the given amount. | ||
51 | 661 | """ | ||
52 | 662 | |||
53 | 663 | |||
54 | 650 | class IArchiveView(IHasBuildRecords): | 664 | class IArchiveView(IHasBuildRecords): |
55 | 651 | """Archive interface for operations restricted by view privilege.""" | 665 | """Archive interface for operations restricted by view privilege.""" |
56 | 652 | 666 | ||
57 | 653 | 667 | ||
58 | === modified file 'lib/lp/soyuz/interfaces/binarypackagerelease.py' | |||
59 | --- lib/lp/soyuz/interfaces/binarypackagerelease.py 2009-06-25 04:06:00 +0000 | |||
60 | +++ lib/lp/soyuz/interfaces/binarypackagerelease.py 2010-03-15 10:41:18 +0000 | |||
61 | @@ -11,17 +11,18 @@ | |||
62 | 11 | 'BinaryPackageFileType', | 11 | 'BinaryPackageFileType', |
63 | 12 | 'BinaryPackageFormat', | 12 | 'BinaryPackageFormat', |
64 | 13 | 'IBinaryPackageRelease', | 13 | 'IBinaryPackageRelease', |
65 | 14 | 'IBinaryPackageReleaseDownloadCount', | ||
66 | 14 | 'IBinaryPackageReleaseSet', | 15 | 'IBinaryPackageReleaseSet', |
67 | 15 | ] | 16 | ] |
68 | 16 | 17 | ||
70 | 17 | from zope.schema import Bool, Int, Text, TextLine, Datetime | 18 | from lazr.enum import DBEnumeratedType, DBItem |
71 | 19 | from lazr.restful.fields import Reference | ||
72 | 20 | from zope.schema import Bool, Choice, Date, Int, Text, TextLine, Datetime | ||
73 | 18 | from zope.interface import Interface, Attribute | 21 | from zope.interface import Interface, Attribute |
74 | 19 | 22 | ||
75 | 20 | from canonical.launchpad import _ | 23 | from canonical.launchpad import _ |
76 | 21 | |||
77 | 22 | from canonical.launchpad.validators.version import valid_debian_version | 24 | from canonical.launchpad.validators.version import valid_debian_version |
80 | 23 | 25 | from lp.soyuz.interfaces.archive import IArchive | |
79 | 24 | from lazr.enum import DBEnumeratedType, DBItem | ||
81 | 25 | 26 | ||
82 | 26 | 27 | ||
83 | 27 | class IBinaryPackageRelease(Interface): | 28 | class IBinaryPackageRelease(Interface): |
84 | @@ -79,6 +80,7 @@ | |||
85 | 79 | argument remains untouched. | 80 | argument remains untouched. |
86 | 80 | """ | 81 | """ |
87 | 81 | 82 | ||
88 | 83 | |||
89 | 82 | class IBinaryPackageReleaseSet(Interface): | 84 | class IBinaryPackageReleaseSet(Interface): |
90 | 83 | """A set of binary packages""" | 85 | """A set of binary packages""" |
91 | 84 | 86 | ||
92 | @@ -91,6 +93,23 @@ | |||
93 | 91 | """Get an BinaryPackageRelease in a DistroSeries by its name""" | 93 | """Get an BinaryPackageRelease in a DistroSeries by its name""" |
94 | 92 | 94 | ||
95 | 93 | 95 | ||
96 | 96 | class IBinaryPackageReleaseDownloadCount(Interface): | ||
97 | 97 | """Daily download count of a binary package release in an archive.""" | ||
98 | 98 | |||
99 | 99 | archive = Reference( | ||
100 | 100 | title=_('The archive'), schema=IArchive, required=True, | ||
101 | 101 | readonly=True) | ||
102 | 102 | binary_package_release = Reference( | ||
103 | 103 | title=_('The binary package release'), schema=IBinaryPackageRelease, | ||
104 | 104 | required=True, readonly=True) | ||
105 | 105 | day = Date( | ||
106 | 106 | title=_('The day of the downloads'), required=True, readonly=True) | ||
107 | 107 | count = Int( | ||
108 | 108 | title=_('The number of downloads'), required=True, readonly=False) | ||
109 | 109 | country = Choice( | ||
110 | 110 | title=_('Country'), required=False, vocabulary='CountryName') | ||
111 | 111 | |||
112 | 112 | |||
113 | 94 | class BinaryPackageFileType(DBEnumeratedType): | 113 | class BinaryPackageFileType(DBEnumeratedType): |
114 | 95 | """Binary Package File Type | 114 | """Binary Package File Type |
115 | 96 | 115 | ||
116 | 97 | 116 | ||
117 | === modified file 'lib/lp/soyuz/model/archive.py' | |||
118 | --- lib/lp/soyuz/model/archive.py 2010-03-12 06:19:52 +0000 | |||
119 | +++ lib/lp/soyuz/model/archive.py 2010-03-15 10:41:18 +0000 | |||
120 | @@ -39,6 +39,8 @@ | |||
121 | 39 | from lp.soyuz.model.archivedependency import ArchiveDependency | 39 | from lp.soyuz.model.archivedependency import ArchiveDependency |
122 | 40 | from lp.soyuz.model.archiveauthtoken import ArchiveAuthToken | 40 | from lp.soyuz.model.archiveauthtoken import ArchiveAuthToken |
123 | 41 | from lp.soyuz.model.archivesubscriber import ArchiveSubscriber | 41 | from lp.soyuz.model.archivesubscriber import ArchiveSubscriber |
124 | 42 | from lp.soyuz.model.binarypackagerelease import ( | ||
125 | 43 | BinaryPackageReleaseDownloadCount) | ||
126 | 42 | from lp.soyuz.model.build import Build | 44 | from lp.soyuz.model.build import Build |
127 | 43 | from lp.soyuz.model.distributionsourcepackagecache import ( | 45 | from lp.soyuz.model.distributionsourcepackagecache import ( |
128 | 44 | DistributionSourcePackageCache) | 46 | DistributionSourcePackageCache) |
129 | @@ -1327,6 +1329,19 @@ | |||
130 | 1327 | result_set.config(distinct=True).order_by(SourcePackageRelease.id) | 1329 | result_set.config(distinct=True).order_by(SourcePackageRelease.id) |
131 | 1328 | return result_set | 1330 | return result_set |
132 | 1329 | 1331 | ||
133 | 1332 | def updatePackageDownloadCount(self, bpr, day, country, count): | ||
134 | 1333 | """See `IArchive`.""" | ||
135 | 1334 | store = Store.of(self) | ||
136 | 1335 | entry = store.find( | ||
137 | 1336 | BinaryPackageReleaseDownloadCount, archive=self, | ||
138 | 1337 | binary_package_release=bpr, day=day, country=country).one() | ||
139 | 1338 | if entry is None: | ||
140 | 1339 | entry = BinaryPackageReleaseDownloadCount( | ||
141 | 1340 | archive=self, binary_package_release=bpr, day=day, | ||
142 | 1341 | country=country, count=count) | ||
143 | 1342 | else: | ||
144 | 1343 | entry.count += count | ||
145 | 1344 | |||
146 | 1330 | def _setBuildStatuses(self, status): | 1345 | def _setBuildStatuses(self, status): |
147 | 1331 | """Update the pending Build Jobs' status for this archive.""" | 1346 | """Update the pending Build Jobs' status for this archive.""" |
148 | 1332 | 1347 | ||
149 | 1333 | 1348 | ||
150 | === modified file 'lib/lp/soyuz/model/binarypackagerelease.py' | |||
151 | --- lib/lp/soyuz/model/binarypackagerelease.py 2009-06-25 04:06:00 +0000 | |||
152 | +++ lib/lp/soyuz/model/binarypackagerelease.py 2010-03-15 10:41:18 +0000 | |||
153 | @@ -4,18 +4,23 @@ | |||
154 | 4 | # pylint: disable-msg=E0611,W0212 | 4 | # pylint: disable-msg=E0611,W0212 |
155 | 5 | 5 | ||
156 | 6 | __metaclass__ = type | 6 | __metaclass__ = type |
158 | 7 | __all__ = ['BinaryPackageRelease', 'BinaryPackageReleaseSet'] | 7 | __all__ = [ |
159 | 8 | 'BinaryPackageRelease', | ||
160 | 9 | 'BinaryPackageReleaseDownloadCount', | ||
161 | 10 | 'BinaryPackageReleaseSet' | ||
162 | 11 | ] | ||
163 | 8 | 12 | ||
164 | 9 | 13 | ||
165 | 10 | from zope.interface import implements | 14 | from zope.interface import implements |
166 | 11 | 15 | ||
167 | 12 | from sqlobject import StringCol, ForeignKey, IntCol, SQLMultipleJoin, BoolCol | 16 | from sqlobject import StringCol, ForeignKey, IntCol, SQLMultipleJoin, BoolCol |
168 | 17 | from storm.locals import Date, Int, Reference, Storm | ||
169 | 13 | 18 | ||
170 | 14 | from canonical.database.sqlbase import SQLBase, quote, sqlvalues, quote_like | 19 | from canonical.database.sqlbase import SQLBase, quote, sqlvalues, quote_like |
171 | 15 | 20 | ||
172 | 16 | from lp.soyuz.interfaces.binarypackagerelease import ( | 21 | from lp.soyuz.interfaces.binarypackagerelease import ( |
173 | 17 | BinaryPackageFileType, BinaryPackageFormat, IBinaryPackageRelease, | 22 | BinaryPackageFileType, BinaryPackageFormat, IBinaryPackageRelease, |
175 | 18 | IBinaryPackageReleaseSet) | 23 | IBinaryPackageReleaseDownloadCount, IBinaryPackageReleaseSet) |
176 | 19 | from lp.soyuz.interfaces.publishing import ( | 24 | from lp.soyuz.interfaces.publishing import ( |
177 | 20 | PackagePublishingPriority, PackagePublishingStatus) | 25 | PackagePublishingPriority, PackagePublishingStatus) |
178 | 21 | from canonical.database.enumcol import EnumCol | 26 | from canonical.database.enumcol import EnumCol |
179 | @@ -199,3 +204,29 @@ | |||
180 | 199 | 204 | ||
181 | 200 | return query, clauseTables | 205 | return query, clauseTables |
182 | 201 | 206 | ||
183 | 207 | |||
184 | 208 | class BinaryPackageReleaseDownloadCount(Storm): | ||
185 | 209 | """See `IBinaryPackageReleaseDownloadCount`.""" | ||
186 | 210 | |||
187 | 211 | implements(IBinaryPackageReleaseDownloadCount) | ||
188 | 212 | __storm_table__ = 'BinaryPackageReleaseDownloadCount' | ||
189 | 213 | |||
190 | 214 | id = Int(primary=True) | ||
191 | 215 | archive_id = Int(name='archive', allow_none=False) | ||
192 | 216 | archive = Reference(archive_id, 'Archive.id') | ||
193 | 217 | binary_package_release_id = Int( | ||
194 | 218 | name='binary_package_release', allow_none=False) | ||
195 | 219 | binary_package_release = Reference( | ||
196 | 220 | binary_package_release_id, 'BinaryPackageRelease.id') | ||
197 | 221 | day = Date(allow_none=False) | ||
198 | 222 | country_id = Int(name='country', allow_none=True) | ||
199 | 223 | country = Reference(country_id, 'Country.id') | ||
200 | 224 | count = Int(allow_none=False) | ||
201 | 225 | |||
202 | 226 | def __init__(self, archive, binary_package_release, day, country, count): | ||
203 | 227 | super(BinaryPackageReleaseDownloadCount, self).__init__() | ||
204 | 228 | self.archive = archive | ||
205 | 229 | self.binary_package_release = binary_package_release | ||
206 | 230 | self.day = day | ||
207 | 231 | self.country = country | ||
208 | 232 | self.count = count | ||
209 | 202 | 233 | ||
210 | === modified file 'lib/lp/soyuz/tests/test_archive.py' | |||
211 | --- lib/lp/soyuz/tests/test_archive.py 2010-03-12 06:19:52 +0000 | |||
212 | +++ lib/lp/soyuz/tests/test_archive.py 2010-03-15 10:41:18 +0000 | |||
213 | @@ -3,7 +3,7 @@ | |||
214 | 3 | 3 | ||
215 | 4 | """Test Archive features.""" | 4 | """Test Archive features.""" |
216 | 5 | 5 | ||
218 | 6 | from datetime import datetime, timedelta | 6 | from datetime import date, datetime, timedelta |
219 | 7 | import pytz | 7 | import pytz |
220 | 8 | import unittest | 8 | import unittest |
221 | 9 | 9 | ||
222 | @@ -19,6 +19,7 @@ | |||
223 | 19 | from lp.registry.interfaces.distribution import IDistributionSet | 19 | from lp.registry.interfaces.distribution import IDistributionSet |
224 | 20 | from lp.registry.interfaces.person import IPersonSet | 20 | from lp.registry.interfaces.person import IPersonSet |
225 | 21 | from lp.services.job.interfaces.job import JobStatus | 21 | from lp.services.job.interfaces.job import JobStatus |
226 | 22 | from lp.services.worlddata.interfaces.country import ICountrySet | ||
227 | 22 | from lp.soyuz.interfaces.archive import ( | 23 | from lp.soyuz.interfaces.archive import ( |
228 | 23 | IArchiveSet, ArchivePurpose, CannotSwitchPrivacy) | 24 | IArchiveSet, ArchivePurpose, CannotSwitchPrivacy) |
229 | 24 | from lp.soyuz.interfaces.archivearch import IArchiveArchSet | 25 | from lp.soyuz.interfaces.archivearch import IArchiveArchSet |
230 | @@ -26,6 +27,8 @@ | |||
231 | 26 | from lp.soyuz.interfaces.processor import IProcessorFamilySet | 27 | from lp.soyuz.interfaces.processor import IProcessorFamilySet |
232 | 27 | from lp.soyuz.interfaces.publishing import PackagePublishingStatus | 28 | from lp.soyuz.interfaces.publishing import PackagePublishingStatus |
233 | 28 | from lp.soyuz.model.build import Build | 29 | from lp.soyuz.model.build import Build |
234 | 30 | from lp.soyuz.model.binarypackagerelease import ( | ||
235 | 31 | BinaryPackageReleaseDownloadCount) | ||
236 | 29 | from lp.soyuz.tests.test_publishing import SoyuzTestPublisher | 32 | from lp.soyuz.tests.test_publishing import SoyuzTestPublisher |
237 | 30 | from lp.testing import TestCaseWithFactory | 33 | from lp.testing import TestCaseWithFactory |
238 | 31 | 34 | ||
239 | @@ -562,6 +565,105 @@ | |||
240 | 562 | self.assertEqual('0.5.11~ppa1', pubs[0].source_package_version) | 565 | self.assertEqual('0.5.11~ppa1', pubs[0].source_package_version) |
241 | 563 | 566 | ||
242 | 564 | 567 | ||
243 | 568 | class TestUpdatePackageDownloadCount(TestCaseWithFactory): | ||
244 | 569 | """Ensure that updatePackageDownloadCount works as expected.""" | ||
245 | 570 | |||
246 | 571 | layer = LaunchpadZopelessLayer | ||
247 | 572 | |||
248 | 573 | def setUp(self): | ||
249 | 574 | super(TestUpdatePackageDownloadCount, self).setUp() | ||
250 | 575 | self.publisher = SoyuzTestPublisher() | ||
251 | 576 | self.publisher.prepareBreezyAutotest() | ||
252 | 577 | |||
253 | 578 | self.store = getUtility(IStoreSelector).get( | ||
254 | 579 | MAIN_STORE, DEFAULT_FLAVOR) | ||
255 | 580 | |||
256 | 581 | self.archive = self.factory.makeArchive() | ||
257 | 582 | self.bpr_1 = self.publisher.getPubBinaries( | ||
258 | 583 | archive=self.archive)[0].binarypackagerelease | ||
259 | 584 | self.bpr_2 = self.publisher.getPubBinaries( | ||
260 | 585 | archive=self.archive)[0].binarypackagerelease | ||
261 | 586 | |||
262 | 587 | country_set = getUtility(ICountrySet) | ||
263 | 588 | self.australia = country_set['AU'] | ||
264 | 589 | self.new_zealand = country_set['NZ'] | ||
265 | 590 | |||
266 | 591 | def assertCount(self, count, archive, bpr, day, country): | ||
267 | 592 | self.assertEqual(count, self.store.find( | ||
268 | 593 | BinaryPackageReleaseDownloadCount, | ||
269 | 594 | archive=archive, binary_package_release=bpr, | ||
270 | 595 | day=day, country=country).one().count) | ||
271 | 596 | |||
272 | 597 | def test_creates_new_entry(self): | ||
273 | 598 | # The first update for a particular archive, package, day and | ||
274 | 599 | # country will create a new BinaryPackageReleaseDownloadCount | ||
275 | 600 | # entry. | ||
276 | 601 | day = date(2010, 2, 20) | ||
277 | 602 | self.assertIs(None, self.store.find( | ||
278 | 603 | BinaryPackageReleaseDownloadCount, | ||
279 | 604 | archive=self.archive, binary_package_release=self.bpr_1, | ||
280 | 605 | day=day, country=self.australia).one()) | ||
281 | 606 | self.archive.updatePackageDownloadCount( | ||
282 | 607 | self.bpr_1, day, self.australia, 10) | ||
283 | 608 | self.assertCount(10, self.archive, self.bpr_1, day, self.australia) | ||
284 | 609 | |||
285 | 610 | def test_reuses_existing_entry(self): | ||
286 | 611 | # A second update will simply add to the count on the existing | ||
287 | 612 | # BPRDC. | ||
288 | 613 | day = date(2010, 2, 20) | ||
289 | 614 | self.archive.updatePackageDownloadCount( | ||
290 | 615 | self.bpr_1, day, self.australia, 10) | ||
291 | 616 | self.archive.updatePackageDownloadCount( | ||
292 | 617 | self.bpr_1, day, self.australia, 3) | ||
293 | 618 | self.assertCount(13, self.archive, self.bpr_1, day, self.australia) | ||
294 | 619 | |||
295 | 620 | def test_differentiates_between_countries(self): | ||
296 | 621 | # A different country will cause a new entry to be created. | ||
297 | 622 | day = date(2010, 2, 20) | ||
298 | 623 | self.archive.updatePackageDownloadCount( | ||
299 | 624 | self.bpr_1, day, self.australia, 10) | ||
300 | 625 | self.archive.updatePackageDownloadCount( | ||
301 | 626 | self.bpr_1, day, self.new_zealand, 3) | ||
302 | 627 | |||
303 | 628 | self.assertCount(10, self.archive, self.bpr_1, day, self.australia) | ||
304 | 629 | self.assertCount(3, self.archive, self.bpr_1, day, self.new_zealand) | ||
305 | 630 | |||
306 | 631 | def test_country_can_be_none(self): | ||
307 | 632 | # The country can be None, indicating that it is unknown. | ||
308 | 633 | day = date(2010, 2, 20) | ||
309 | 634 | self.archive.updatePackageDownloadCount( | ||
310 | 635 | self.bpr_1, day, self.australia, 10) | ||
311 | 636 | self.archive.updatePackageDownloadCount( | ||
312 | 637 | self.bpr_1, day, None, 3) | ||
313 | 638 | |||
314 | 639 | self.assertCount(10, self.archive, self.bpr_1, day, self.australia) | ||
315 | 640 | self.assertCount(3, self.archive, self.bpr_1, day, None) | ||
316 | 641 | |||
317 | 642 | def test_differentiates_between_days(self): | ||
318 | 643 | # A different date will also cause a new entry to be created. | ||
319 | 644 | day = date(2010, 2, 20) | ||
320 | 645 | another_day = date(2010, 2, 21) | ||
321 | 646 | self.archive.updatePackageDownloadCount( | ||
322 | 647 | self.bpr_1, day, self.australia, 10) | ||
323 | 648 | self.archive.updatePackageDownloadCount( | ||
324 | 649 | self.bpr_1, another_day, self.australia, 3) | ||
325 | 650 | |||
326 | 651 | self.assertCount(10, self.archive, self.bpr_1, day, self.australia) | ||
327 | 652 | self.assertCount( | ||
328 | 653 | 3, self.archive, self.bpr_1, another_day, self.australia) | ||
329 | 654 | |||
330 | 655 | def test_differentiates_between_bprs(self): | ||
331 | 656 | # And even a different package will create a new entry. | ||
332 | 657 | day = date(2010, 2, 20) | ||
333 | 658 | self.archive.updatePackageDownloadCount( | ||
334 | 659 | self.bpr_1, day, self.australia, 10) | ||
335 | 660 | self.archive.updatePackageDownloadCount( | ||
336 | 661 | self.bpr_2, day, self.australia, 3) | ||
337 | 662 | |||
338 | 663 | self.assertCount(10, self.archive, self.bpr_1, day, self.australia) | ||
339 | 664 | self.assertCount(3, self.archive, self.bpr_2, day, self.australia) | ||
340 | 665 | |||
341 | 666 | |||
342 | 565 | class TestARMBuildsAllowed(TestCaseWithFactory): | 667 | class TestARMBuildsAllowed(TestCaseWithFactory): |
343 | 566 | """Ensure that ARM builds can be allowed and disallowed correctly.""" | 668 | """Ensure that ARM builds can be allowed and disallowed correctly.""" |
344 | 567 | 669 |
Looks good. DB patch approved by me as patch-2207- 36-0.sql.
We might need an extra index or three depending on what reports we generate from this information. I think the reports I think we will generate will be fine with the index from the UNIQUE constraint so no worries for now.