Merge lp:~james-w/launchpad/archive-collection into lp:launchpad
| Status: | Work in progress |
|---|---|
| Proposed branch: | lp:~james-w/launchpad/archive-collection |
| Merge into: | lp:launchpad |
| Diff against target: |
611 lines (+421/-70) 7 files modified
lib/lp/services/database/collection.py (+3/-3) lib/lp/soyuz/configure.zcml (+13/-0) lib/lp/soyuz/interfaces/archivecollection.py (+70/-0) lib/lp/soyuz/model/archive.py (+17/-64) lib/lp/soyuz/model/archivecollection.py (+86/-0) lib/lp/soyuz/tests/test_archivecollection.py (+220/-0) lib/lp/testing/factory.py (+12/-3) |
| To merge this branch: | bzr merge lp:~james-w/launchpad/archive-collection |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Launchpad code reviewers | 2010-08-02 | Pending | |
|
Review via email:
|
|||
Description of the Change
Hi,
Here's a branch to add an ArchiveCollection based
on the new generic Collection.
It's fairly standalone right now, though I ported a
few easy queries in ArchiveSet methods over to it.
Hopefully once it is available it will see more use.
Thanks,
James
| Jonathan Lange (jml) wrote : | # |
| James Westby (james-w) wrote : | # |
On Mon, 02 Aug 2010 15:58:40 -0000, Jonathan Lange <email address hidden> wrote:
> What's the reason for this change? Where are the corresponding tests?
Sorry, I forgot to mention it in the cover letter.
When you register a Collection as a utility it is instantiated by the
zcml.
However, as the store is queried in the constructor this can fail if
there is not a utility registered for the store yet.
How this manifested was that as soon as I added the utility I could no
longer run any tests as there was an exception during zcml processing.
I'm not sure how I would test this directly? A test that created a
Collection and tested that .store was None?
It does make me realise that I should probably add a test that the
utility returns something sensible?
> In IBranchCollection, we have a *args method for something similar. Do
> you think that would be nicer here?
The implementation is *purposes, so the interface needs correcting.
> Maybe it's my crappy email client, but the indentation on this looks messed up.
It's non-standard as it was copy-paste code, I will fix.
> > + # FIXME: Include private PPA's if user is an uploader
> > + return self.refine(
> > + Or(public_archive, Archive.
> >
>
> Are you going to fix this in this branch? Won't this be buggy if
> someone uses it?
This is copy-paste code, so we apparently have survived this far without
needing it.
I can look at fixing it though.
> These tests are good, thanks.
>
> One thing I've done with similar tests is have a setUp() that removes
> all of the data in question (e.g. removing all branches). That way you
> can do actual equality testing rather than testing to if if objects
> are members in tests.
>
> You don't have to though.
That's a good idea, I'll look for your code to learn from it.
Thanks,
James
Unmerged revisions
- 11270. By James Westby on 2010-07-31
-
Port a few more easy queries to ArchiveCollection.
- 11269. By James Westby on 2010-07-31
-
Move the first method over to the new code.
- 11268. By James Westby on 2010-07-31
-
Add the Interfaces and register a utility for all archives.
Registering a utility means that the zcml processor tries to instantiate
our class, which fails given that the IStoreSelector utility isn't
registered yet. Therefore we lazily get the store in the base Collection
if it isn't in the kwargs in the constructor. - 11267. By James Westby on 2010-07-31
-
Implement visibleByUser.
- 11266. By James Westby on 2010-07-31
-
Basic ArchiveCollection implementation.

On Mon, Aug 2, 2010 at 1:41 AM, James Westby <email address hidden> wrote: reviewers)
> James Westby has proposed merging lp:~james-w/launchpad/archive-collection into lp:launchpad/devel.
>
> Requested reviews:
> Launchpad code reviewers (launchpad-
>
>
> Hi,
>
> Here's a branch to add an ArchiveCollection based
> on the new generic Collection.
>
> It's fairly standalone right now, though I ported a
> few easy queries in ArchiveSet methods over to it.
> Hopefully once it is available it will see more use.
>
>
Thanks for doing this. It's important to have new code actually be used.
> === modified file 'lib/lp/ services/ database/ collection. py' services/ database/ collection. py 2010-07-16 14:10:18 +0000 services/ database/ collection. py 2010-08-02 00:41:06 +0000 IStoreSelector) .get( IStoreSelector) .get(
> --- lib/lp/
> +++ lib/lp/
> @@ -68,9 +68,6 @@
> base_tables = list(base.tables)
>
> self.store = kwargs.get('store')
> - if self.store is None:
> - self.store = getUtility(
> - MAIN_STORE, DEFAULT_FLAVOR)
>
> self.tables = (
> starting_tables + base_tables +
> @@ -118,6 +115,9 @@
> If no values are requested, this selects the type of object that
> the Collection is a collection of.
> """
> + if self.store is None:
> + self.store = getUtility(
> + MAIN_STORE, DEFAULT_FLAVOR)
> if len(self.tables) == 0:
> source = self.store
> else:
>
What's the reason for this change? Where are the corresponding tests?
> === added file 'lib/lp/ soyuz/interface s/archivecollec tion.py' soyuz/interface s/archivecollec tion.py 1970-01-01 00:00:00 +0000 soyuz/interface s/archivecollec tion.py 2010-08-02 00:41:06 +0000 purposes) :
> --- lib/lp/
> +++ lib/lp/
> @@ -0,0 +1,70 @@
> +# Copyright 2010 Canonical Ltd. This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +"""A collection of archives.
> +
...
> +
> + def withPurposes(
> + """Restrict the archives to one of the given purposes."""
In IBranchCollection, we have a *args method for something similar. Do
you think that would be nicer here?
> === added file 'lib/lp/ soyuz/model/ archivecollecti on.py' soyuz/model/ archivecollecti on.py 1970-01-01 00:00:00 +0000 soyuz/model/ archivecollecti on.py 2010-08-02 00:41:06 +0000
> --- lib/lp/
> +++ lib/lp/
> @@ -0,0 +1,86 @@
> +# Copyright 2010 Canonical Ltd. This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +__metaclass__ = type
> +
...
> +
> + def visibleByUser(self, user):
> + public_archive = And(Archive.private == False,
> + Archive._enabled == True)
Maybe it's my crappy email client, but the indentation on this looks messed up.
> + if user is None: public_ archive) ILaunchpadCeleb rities) celebs. admin):
> + # Anonymous user; filter to include only public archives in
> + # the results.
> + return self.refine(
> + celebs = getUtility(
> + if user.inTeam(
> + # Admi...