Couple of nitpicks, but otherwise okay. Marking it needs fixing because
of the over-long test (see below) but if we can't split that up I'm
happy for it to land as-is.
> === modified file 'lib/lp/bugs/tests/test_bugtask.py'
> --- lib/lp/bugs/tests/test_bugtask.py 2010-07-14 14:11:15 +0000
> +++ lib/lp/bugs/tests/test_bugtask.py 2010-08-17 09:41:19 +0000
> @@ -792,6 +796,28 @@
> result = target.searchTasks(None, modified_since=date)
> self.assertEqual([task2], list(result))
>
> + def test_private_bug_view_permissions_cached(self):
> + """private bugs from a search know the user can see the bugs."""
Captialise at the start of the sentence ;).
> + target = self.makeBugTarget()
> + person = self.login()
> + self.factory.makeBug(product=target, private=True, owner=person)
> + self.factory.makeBug(product=target, private=True, owner=person)
> + # Search style and parameters taken from the milestone index view where
> + # the issue was discovered.
> + login_person(person)
> + tasks =target.searchTasks(BugTaskSearchParams(person, omit_dupes=True,
The test should have a comment at the start of it to save me having to
parse the method name.
> + product = self.factory.makeProduct()
> + login_person(product.owner)
> + milestone = self.factory.makeMilestone(
> + productseries=product.development_focus)
> + bug1 = self.factory.makeBug(product=product, private=True,
> + owner=product.owner)
> + bug1.bugtasks[0].transitionToMilestone(milestone, product.owner)
> + # We look at the page as someone who is a member of a team and the team
> + # is subscribed to the bugs, so that we don't get trivial shortcuts
> + # avoiding queries : test the worst case.
> + subscribed_team = self.factory.makeTeam()
> + viewer = self.factory.makePerson(password="test")
> + with person_logged_in(subscribed_team.teamowner):
> + subscribed_team.addMember(viewer, subscribed_team.teamowner)
> + bug1.subscribe(subscribed_team, product.owner)
> + bug1_url = canonical_url(bug1)
> + milestone_url = canonical_url(milestone)
> + browser = self.getUserBrowser(user=viewer)
> + # Seed the cookie cache and any other cross-request state we may gain
> + # in future. See canonical.launchpad.webapp.serssion: _get_secret.
> + browser.open(milestone_url)
> + collector = QueryCollector()
> + collector.register()
> + self.addCleanup(collector.unregister)
> + # This page is rather high in queries : 46 as a baseline. 20100817
> + page_query_limit = 46
> + browser.open(milestone_url)
> + # Check that the test found the bug
> + self.assertTrue(bug1_url in browser.contents)
> + self.assertThat(collector, HasQueryCount(LessThan(page_query_limit)))
> + with_1_private_bug = collector.count
> + with_1_queries = ["%s: %s" % (pos, stmt[3]) for (pos, stmt) in
> + enumerate(collector.queries)]
> + login_person(product.owner)
> + bug2 = self.factory.makeBug(product=product, private=True,
> + owner=product.owner)
> + bug2.bugtasks[0].transitionToMilestone(milestone, product.owner)
> + bug2.subscribe(subscribed_team, product.owner)
> + bug2_url = canonical_url(bug2)
> + bug3 = self.factory.makeBug(product=product, private=True,
> + owner=product.owner)
> + bug3.bugtasks[0].transitionToMilestone(milestone, product.owner)
> + bug3.subscribe(subscribed_team, product.owner)
> + logout()
> + browser.open(milestone_url)
> + self.assertTrue(bug2_url in browser.contents)
> + self.assertThat(collector, HasQueryCount(LessThan(page_query_limit)))
> + with_3_private_bugs = collector.count
> + with_3_queries = ["%s: %s" % (pos, stmt[3]) for (pos, stmt) in
> + enumerate(collector.queries)]
> + self.assertEqual(with_1_private_bug, with_3_private_bugs,
> + "different query count: \n%s\n******************\n%s\n" % (
> + '\n'.join(with_1_queries), '\n'.join(with_3_queries)))
At 54 lines this test's a bit on the long side, but I'm struggling to
come up with a way of making it shorter that isn't just dividing it into
two around the "# Check that the test found the bug" line. Any ideas?
I'm not sure it's worth worrying about in this case.
Hi Rob,
Couple of nitpicks, but otherwise okay. Marking it needs fixing because
of the over-long test (see below) but if we can't split that up I'm
happy for it to land as-is.
> === modified file 'lib/lp/ bugs/tests/ test_bugtask. py' bugs/tests/ test_bugtask. py 2010-07-14 14:11:15 +0000 bugs/tests/ test_bugtask. py 2010-08-17 09:41:19 +0000 searchTasks( None, modified_ since=date) l([task2] , list(result)) bug_view_ permissions_ cached( self):
> --- lib/lp/
> +++ lib/lp/
> @@ -792,6 +796,28 @@
> result = target.
> self.assertEqua
>
> + def test_private_
> + """private bugs from a search know the user can see the bugs."""
Captialise at the start of the sentence ;).
> + target = self.makeBugTar get() makeBug( product= target, private=True, owner=person) makeBug( product= target, private=True, owner=person) person) searchTasks( BugTaskSearchPa rams(person, omit_dupes=True,
> + person = self.login()
> + self.factory.
> + self.factory.
> + # Search style and parameters taken from the milestone index view where
> + # the issue was discovered.
> + login_person(
> + tasks =target.
Needs a space after the =.
> + orderby=['status', '-importance', 'id']))
> === modified file 'lib/lp/ registry/ browser/ tests/test_ milestone. py' registry/ browser/ tests/test_ milestone. py 2010-08-16 18:39:11 +0000 registry/ browser/ tests/test_ milestone. py 2010-08-17 09:41:19 +0000 development_ focus.all_ bugtasks. count() ) TestLoader( ).loadTestsFrom Name(__ name__) dex(TestCaseWit hFactory) : nalLayer private_ bugs_query_ count_is_ constant( self):
> --- lib/lp/
> +++ lib/lp/
> @@ -105,5 +116,61 @@
> self.assertEqual(0, product.
>
>
> -def test_suite():
> - return unittest.
> +class TestMilestoneIn
> +
> + layer = DatabaseFunctio
> +
> + def test_more_
The test should have a comment at the start of it to save me having to
parse the method name.
> + product = self.factory. makeProduct( ) product. owner) makeMilestone( product. development_ focus) makeBug( product= product, private=True, owner) 0].transitionTo Milestone( milestone, product.owner) makeTeam( ) makePerson( password= "test") logged_ in(subscribed_ team.teamowner) : team.addMember( viewer, subscribed_ team.teamowner) subscribed_ team, product.owner) url(milestone) wser(user= viewer) launchpad. webapp. serssion: _get_secret. open(milestone_ url) register( ) (collector. unregister) open(milestone_ url) (collector, HasQueryCount( LessThan( page_query_ limit)) ) collector. queries) ] product. owner) makeBug( product= product, private=True, owner) 0].transitionTo Milestone( milestone, product.owner) subscribed_ team, product.owner) makeBug( product= product, private=True, owner) 0].transitionTo Milestone( milestone, product.owner) subscribed_ team, product.owner) open(milestone_ url) (collector, HasQueryCount( LessThan( page_query_ limit)) ) collector. queries) ] l(with_ 1_private_ bug, with_3_ private_ bugs, ******* ******* ***\n%s\ n" % ( with_1_ queries) , '\n'.join( with_3_ queries) ))
> + login_person(
> + milestone = self.factory.
> + productseries=
> + bug1 = self.factory.
> + owner=product.
> + bug1.bugtasks[
> + # We look at the page as someone who is a member of a team and the team
> + # is subscribed to the bugs, so that we don't get trivial shortcuts
> + # avoiding queries : test the worst case.
> + subscribed_team = self.factory.
> + viewer = self.factory.
> + with person_
> + subscribed_
> + bug1.subscribe(
> + bug1_url = canonical_url(bug1)
> + milestone_url = canonical_
> + browser = self.getUserBro
> + # Seed the cookie cache and any other cross-request state we may gain
> + # in future. See canonical.
> + browser.
> + collector = QueryCollector()
> + collector.
> + self.addCleanup
> + # This page is rather high in queries : 46 as a baseline. 20100817
> + page_query_limit = 46
> + browser.
> + # Check that the test found the bug
> + self.assertTrue(bug1_url in browser.contents)
> + self.assertThat
> + with_1_private_bug = collector.count
> + with_1_queries = ["%s: %s" % (pos, stmt[3]) for (pos, stmt) in
> + enumerate(
> + login_person(
> + bug2 = self.factory.
> + owner=product.
> + bug2.bugtasks[
> + bug2.subscribe(
> + bug2_url = canonical_url(bug2)
> + bug3 = self.factory.
> + owner=product.
> + bug3.bugtasks[
> + bug3.subscribe(
> + logout()
> + browser.
> + self.assertTrue(bug2_url in browser.contents)
> + self.assertThat
> + with_3_private_bugs = collector.count
> + with_3_queries = ["%s: %s" % (pos, stmt[3]) for (pos, stmt) in
> + enumerate(
> + self.assertEqua
> + "different query count: \n%s\n*
> + '\n'.join(
At 54 lines this test's a bit on the long side, but I'm struggling to
come up with a way of making it shorter that isn't just dividing it into
two around the "# Check that the test found the bug" line. Any ideas?
I'm not sure it's worth worrying about in this case.