Merge lp:~jamalta/launchpad/bug-127489 into lp:launchpad
- bug-127489
- Merge into devel
Status: | Superseded |
---|---|
Proposed branch: | lp:~jamalta/launchpad/bug-127489 |
Merge into: | lp:launchpad |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~jamalta/launchpad/bug-127489 |
Related bugs: |
This proposal supersedes a proposal from 2009-08-03.
This proposal has been superseded by a proposal from 2009-08-26.
Commit message
Description of the change
Stuart Bishop (stub) wrote : Posted in a previous version of this proposal | # |
Gavin Panella (allenap) wrote : Posted in a previous version of this proposal | # |
Hi Jamal,
Thank you for working on this bug!
As Stuart commented, this will need a pagetest. In fact, there is
already one that is probably broken by this change. Have a look at the
end of lib/lp/
Did you have a mentor for this branch, or a pre-implementation
discussion? Perhaps that might have spotted the need to update the
pagetest. Have a look at https:/
you haven't already. It's the same process as all the Launchpad devs
from Canonical use.
I have a comment about the code, because the cmp argument to sorted()
is deprecated (and I think it's gone entirely in Python 3).
Thanks again!
Gavin.
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -2517,7 +2517,10 @@
> categories = set()
> for contrib in self.contributions:
> categories.
> - return sorted(categories, key=attrgetter(
> + sort = {'code': 0, 'bugs': 1, 'blueprints': 2, 'translations': 3,
> + 'answers': 4, 'specs': 5, 'soyuz': 6}
> + return sorted(categories, key=attrgetter(
> + cmp=lambda x,y: cmp(sort[x], sort[y]))
Because cmp is deprecated, I think this would be better as:
return sorted(categories, key=lambda category: sort[category.
>
> @cachedproperty
> def context_
Jamal Fanaian (jamalta) wrote : Posted in a previous version of this proposal | # |
Hi Gavin,
Thanks for your input regarding this bug. I have actually been working on a test for this. I did not have a mentor when I started working on this issue, but went on #launchpad-dev to get some help. Salgado had recommended that I write a unittest to call the view, and make sure the data was returned in the right order, using a LaunchpadObject
> Hi Jamal,
>
> Thank you for working on this bug!
>
> As Stuart commented, this will need a pagetest. In fact, there is
> already one that is probably broken by this change. Have a look at the
> end of lib/lp/
>
> Did you have a mentor for this branch, or a pre-implementation
> discussion? Perhaps that might have spotted the need to update the
> pagetest. Have a look at https:/
> you haven't already. It's the same process as all the Launchpad devs
> from Canonical use.
>
> I have a comment about the code, because the cmp argument to sorted()
> is deprecated (and I think it's gone entirely in Python 3).
>
> Thanks again!
>
> Gavin.
>
>
> > === modified file 'lib/lp/
> > --- lib/lp/
> > +++ lib/lp/
> > @@ -2517,7 +2517,10 @@
> > categories = set()
> > for contrib in self.contributions:
> > categories.
> contrib[
> > - return sorted(categories, key=attrgetter(
> > + sort = {'code': 0, 'bugs': 1, 'blueprints': 2, 'translations': 3,
> > + 'answers': 4, 'specs': 5, 'soyuz': 6}
> > + return sorted(categories, key=attrgetter(
> > + cmp=lambda x,y: cmp(sort[x], sort[y]))
>
> Because cmp is deprecated, I think this would be better as:
>
> return sorted(categories, key=lambda category: sort[category.
>
> >
> > @cachedproperty
> > def context_
Jamal Fanaian (jamalta) wrote : Posted in a previous version of this proposal | # |
I went through the pagetest you referenced, and it will actually not fail. It is also not possible to test my changes with this because there is not enough data. The problem is that the only two icons displayed are bugs and translations. Sorted alphabetically, bugs will obviously always be first, which is the case with the replacement sort.
To test this I need to be able to add a third entry, say, Answers for example. I have this in my local environment (which I should really revert since it's going to break tests in the future), but I don't know how to properly write a pagetest for it because of this limitation. I think this is the reason salgado recommended writing a unittest.
Let me give the unittests another try to see if I can get them done. Thanks for your help so far!
> Hi Gavin,
>
> Thanks for your input regarding this bug. I have actually been working on a
> test for this. I did not have a mentor when I started working on this issue,
> but went on #launchpad-dev to get some help. Salgado had recommended that I
> write a unittest to call the view, and make sure the data was returned in the
> right order, using a LaunchpadObject
> figure out how to do that exactly, and haven't gotten back to it in a few days
> now. I will take a look at the test you mentioned and make sure I fix it.
> Also, I appreciate your comment regarding the depracated cmp() function. I am
> fairly new to Python and was not aware of this. I will fix that shortly as
> well, using your recommendation.
>
> > Hi Jamal,
> >
> > Thank you for working on this bug!
> >
> > As Stuart commented, this will need a pagetest. In fact, there is
> > already one that is probably broken by this change. Have a look at the
> > end of lib/lp/
> >
> > Did you have a mentor for this branch, or a pre-implementation
> > discussion? Perhaps that might have spotted the need to update the
> > pagetest. Have a look at https:/
> > you haven't already. It's the same process as all the Launchpad devs
> > from Canonical use.
> >
> > I have a comment about the code, because the cmp argument to sorted()
> > is deprecated (and I think it's gone entirely in Python 3).
> >
> > Thanks again!
> >
> > Gavin.
> >
> >
> > > === modified file 'lib/lp/
> > > --- lib/lp/
> > > +++ lib/lp/
> > > @@ -2517,7 +2517,10 @@
> > > categories = set()
> > > for contrib in self.contributions:
> > > categories.
> > contrib[
> > > - return sorted(categories, key=attrgetter(
> > > + sort = {'code': 0, 'bugs': 1, 'blueprints': 2, 'translations': 3,
> > > + 'answers': 4, 'specs': 5, 'soyuz': 6}
> > > + return sorted(categories, key=attrgetter(
> > > + cmp=lambda x,y: cmp(sort[x], sort[y]))
> >
> > Because cmp is deprecated, I think this would be better as:
> >
> > return sorted(categories, key=lambda category: sort[categ...
Gavin Panella (allenap) wrote : Posted in a previous version of this proposal | # |
Have a look at using lp.testing.
Guilherme Salgado (salgado) wrote : Posted in a previous version of this proposal | # |
On Fri, 2009-08-07 at 09:19 +0000, Gavin Panella wrote:
> Have a look at using lp.testing.
I don't think so. That list of categories is generated based on the kind
of karma the person has on the KarmaCache table, and that table is
populated by a script. Even though the person would get karma when
factory.
table until we ran the script. We could run the script in the test, but
that'd make the test *a lot* slower.
That's why I suggested a new method on LPObjectFactory to create the
KarmaCache entries directly.
Jamal, I remember you were able to write the new factory method, so you
should be quite close to getting a test for your fix. If you need any
help, just drop by #launchpad-
Cheers,
--
Guilherme Salgado <email address hidden>
Jamal Fanaian (jamalta) wrote : Posted in a previous version of this proposal | # |
I have added a test that makes sure the categories returned by PersonView.
I may not be doing this the best way, so I am requesting a review and hopefully I can chat with someone about it come Monday to figure out what needs to be improved or changed.
Thanks again for all your help and sorry this took so long!
> On Fri, 2009-08-07 at 09:19 +0000, Gavin Panella wrote:
> > Have a look at using lp.testing.
> this to quickly create, say, branches, so that there are code artifacts for
> your user. That will probably be enough to test this code.
>
> I don't think so. That list of categories is generated based on the kind
> of karma the person has on the KarmaCache table, and that table is
> populated by a script. Even though the person would get karma when
> factory.
> table until we ran the script. We could run the script in the test, but
> that'd make the test *a lot* slower.
>
> That's why I suggested a new method on LPObjectFactory to create the
> KarmaCache entries directly.
>
> Jamal, I remember you were able to write the new factory method, so you
> should be quite close to getting a test for your fix. If you need any
> help, just drop by #launchpad-
>
> Cheers,
>
> --
> Guilherme Salgado <email address hidden>
Jamal Fanaian (jamalta) wrote : Posted in a previous version of this proposal | # |
Sorry forgot to mention this on my last comment. I will try to ping someone in #launchpad-reviews come Monday to go over my branch, that way we don't have to go back and forth over email.
Thanks!
> I have added a test that makes sure the categories returned by
> PersonView.
> script to update Karma I am using the test factories and creating the
> KarmaCache records based on how the Karma update script does it.
>
> I may not be doing this the best way, so I am requesting a review and
> hopefully I can chat with someone about it come Monday to figure out what
> needs to be improved or changed.
>
> Thanks again for all your help and sorry this took so long!
>
> > On Fri, 2009-08-07 at 09:19 +0000, Gavin Panella wrote:
> > > Have a look at using lp.testing.
> use
> > this to quickly create, say, branches, so that there are code artifacts for
> > your user. That will probably be enough to test this code.
> >
> > I don't think so. That list of categories is generated based on the kind
> > of karma the person has on the KarmaCache table, and that table is
> > populated by a script. Even though the person would get karma when
> > factory.
> > table until we ran the script. We could run the script in the test, but
> > that'd make the test *a lot* slower.
> >
> > That's why I suggested a new method on LPObjectFactory to create the
> > KarmaCache entries directly.
> >
> > Jamal, I remember you were able to write the new factory method, so you
> > should be quite close to getting a test for your fix. If you need any
> > help, just drop by #launchpad-
> >
> > Cheers,
> >
> > --
> > Guilherme Salgado <email address hidden>
- 9023. By Jamal Fanaian <jamal@jfvm1>
-
Simplified the karma test by only creating totals of the specified products
- 9024. By Jamal Fanaian <jamal@jfvm1>
-
Cleaned up the code to match the style guide. Modified makeKarmaCache to take category and product objects instead of their ids. Switching back to the launchpad db user after making changes to karma. Removed the raw sql query and replaced it with calls to the karma cache manager.a
- 9025. By Jamal Fanaian <jamal@jfvm1>
-
Person is no longer an instance variable. makeKarmaCache now requires a product be passed. Organized imports and a few other things according to the style guidelines and recommendations from the merge proposal.
- 9026. By Jamal Fanaian <jamal@jfvm1>
-
Removed the statement to switch DB user back to launchpad in makeKarmaCache. Renamed to _makeKarmaCache as it is more of an internal call. Added function docs to explain that the DB user will be switched.
- 9027. By Jamal Fanaian <jamal@jfvm1>
-
replaced the 'blueprints' category with it's correct name 'specs'
Unmerged revisions
- 9027. By Jamal Fanaian <jamal@jfvm1>
-
replaced the 'blueprints' category with it's correct name 'specs'
Preview Diff
1 | === modified file 'lib/lp/registry/browser/person.py' |
2 | --- lib/lp/registry/browser/person.py 2009-07-29 15:34:46 +0000 |
3 | +++ lib/lp/registry/browser/person.py 2009-07-31 21:12:09 +0000 |
4 | @@ -2517,7 +2517,10 @@ |
5 | categories = set() |
6 | for contrib in self.contributions: |
7 | categories.update(category for category in contrib['categories']) |
8 | - return sorted(categories, key=attrgetter('title')) |
9 | + sort = {'code': 0, 'bugs': 1, 'blueprints': 2, 'translations': 3, |
10 | + 'answers': 4, 'specs': 5, 'soyuz': 6} |
11 | + return sorted(categories, key=attrgetter('name'), |
12 | + cmp=lambda x,y: cmp(sort[x], sort[y])) |
13 | |
14 | @cachedproperty |
15 | def context_is_probably_a_team(self): |
This is going to need a page test to catch future regressions.