← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/launchpad/fix-missing-addseries-link into lp:launchpad

 

Raphaël Victor Badin has proposed merging lp:~rvb/launchpad/fix-missing-addseries-link into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #728515 in Launchpad itself: "A distribution page should have a link to create a series"
  https://bugs.launchpad.net/launchpad/+bug/728515
  Bug #734772 in Launchpad itself: "Distribution tests should be refactored not to use sample data"
  https://bugs.launchpad.net/launchpad/+bug/734772

For more details, see:
https://code.launchpad.net/~rvb/launchpad/fix-missing-addseries-link/+merge/53219

Trivial refactoring of the tests for a distribution:
- removed the use of sampledata
- moved page tests in browser/tests (where they belong)

{{{
./bin/test -cvv test_distribution test_distributionpage_series_list_noadmin
./bin/test -cvv test_distribution test_distributionpage_addseries_link_noadmin
./bin/test -cvv test_distribution test_distributionpage_addseries_link
}}}
-- 
https://code.launchpad.net/~rvb/launchpad/fix-missing-addseries-link/+merge/53219
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/launchpad/fix-missing-addseries-link into lp:launchpad.
=== added file 'lib/lp/registry/browser/tests/test_distribution.py'
--- lib/lp/registry/browser/tests/test_distribution.py	1970-01-01 00:00:00 +0000
+++ lib/lp/registry/browser/tests/test_distribution.py	2011-03-14 11:10:23 +0000
@@ -0,0 +1,93 @@
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for Distribution page."""
+
+__metaclass__ = type
+
+from canonical.launchpad.webapp import canonical_url
+from canonical.testing.layers import DatabaseFunctionalLayer
+
+from lp.registry.interfaces.series import SeriesStatus
+from lp.testing import (
+    login_celebrity,
+    login_person,
+    TestCaseWithFactory,
+    )
+from lp.testing.views import create_initialized_view
+
+from testtools.matchers import MatchesAny
+from testtools.matchers import Not
+
+import soupmatchers
+
+
+class TestDistributionPage(TestCaseWithFactory):
+    """A TestCase for the distribution index page."""
+
+    layer = DatabaseFunctionalLayer
+
+    def setUp(self):
+        super(TestDistributionPage, self).setUp()
+        self.distro = self.factory.makeDistribution(
+            name="distro", displayname=u'distro')
+        self.simple_user = self.factory.makePerson()
+
+    def test_distributionpage_addseries_link(self):
+        """ Verify that an admin sees the +addseries link."""
+        self.admin = login_celebrity('admin')
+        view = create_initialized_view(
+            self.distro, '+index', principal=self.admin)
+        series_matches = soupmatchers.HTMLContains(
+            soupmatchers.Tag(
+                'link to add a series', 'a',
+                attrs={'href':
+                    canonical_url(self.distro, view_name='+addseries')},
+                text='Add series'),
+            soupmatchers.Tag(
+                'Series and milestones widget', 'h2',
+                text='Series and milestones'),
+            )
+        self.assertThat(view.render(), series_matches)
+
+    def test_distributionpage_addseries_link_noadmin(self):
+        """Verify that a non-admin does not see the +addseries link
+        nor the series header (since there is no series yet).
+        """
+        login_person(self.simple_user)
+        view = create_initialized_view(
+            self.distro, '+index', principal=self.simple_user)
+        add_series_match = soupmatchers.HTMLContains(
+            soupmatchers.Tag(
+                'link to add a series', 'a',
+                attrs={'href':
+                    canonical_url(self.distro, view_name='+addseries')},
+                text='Add series'))
+        series_header_match = soupmatchers.HTMLContains(
+            soupmatchers.Tag(
+                'Series and milestones widget', 'h2',
+                text='Series and milestones'))
+        self.assertThat(
+            view.render(),
+            Not(MatchesAny(add_series_match, series_header_match)))
+
+    def test_distributionpage_series_list_noadmin(self):
+        """Verify that a non-admin does see the series list
+        when there is a series.
+        """
+        series = self.factory.makeDistroSeries(distribution=self.distro,
+            status=SeriesStatus.CURRENT)
+        login_person(self.simple_user)
+        view = create_initialized_view(
+            self.distro, '+index', principal=self.simple_user)
+        add_series_match = soupmatchers.HTMLContains(
+            soupmatchers.Tag(
+                'link to add a series', 'a',
+                attrs={'href':
+                    canonical_url(self.distro, view_name='+addseries')},
+                text='Add series'))
+        series_header_match = soupmatchers.HTMLContains(
+            soupmatchers.Tag(
+                'Series and milestones widget', 'h2',
+                text='Series and milestones'))
+        self.assertThat(view.render(), series_header_match)
+        self.assertThat(view.render(), Not(add_series_match))

=== modified file 'lib/lp/registry/tests/test_distribution.py'
--- lib/lp/registry/tests/test_distribution.py	2011-03-03 15:45:58 +0000
+++ lib/lp/registry/tests/test_distribution.py	2011-03-14 11:10:23 +0000
@@ -5,7 +5,6 @@
 
 __metaclass__ = type
 
-from canonical.launchpad.webapp import canonical_url
 from canonical.testing.layers import (
     DatabaseFunctionalLayer,
     LaunchpadFunctionalLayer,
@@ -15,7 +14,6 @@
 
 from lp.registry.errors import NoSuchDistroSeries
 from lp.registry.interfaces.distribution import IDistribution
-from lp.registry.interfaces.person import IPersonSet
 from lp.registry.interfaces.series import SeriesStatus
 from lp.registry.tests.test_distroseries import (
     TestDistroSeriesCurrentSourceReleases,
@@ -25,15 +23,7 @@
     IDistributionSourcePackageRelease,
     )
 from lp.testing import TestCaseWithFactory
-from lp.testing import login_person
-from lp.testing.views import create_initialized_view
-
-from testtools.matchers import MatchesAny
-from testtools.matchers import Not
-
-import soupmatchers
-
-from zope.component import getUtility
+
 from zope.security.proxy import removeSecurityProxy
 
 
@@ -186,77 +176,3 @@
             self.assertFalse(
                 hasattr(snapshot, attribute),
                 "Snapshot should not include %s." % attribute)
-
-
-class TestDistributionPage(TestCaseWithFactory):
-    """A TestCase for the distribution page."""
-
-    layer = DatabaseFunctionalLayer
-
-    def setUp(self):
-        super(TestDistributionPage, self).setUp('foo.bar@xxxxxxxxxxxxx')
-        self.distro = self.factory.makeDistribution(
-            name="distro", displayname=u'distro')
-        self.admin = getUtility(IPersonSet).getByEmail(
-            'admin@xxxxxxxxxxxxx')
-        self.simple_user = self.factory.makePerson()
-
-    def test_distributionpage_addseries_link(self):
-        """ Verify that an admin sees the +addseries link."""
-        login_person(self.admin)
-        view = create_initialized_view(
-            self.distro, '+index', principal=self.admin)
-        series_matches = soupmatchers.HTMLContains(
-            soupmatchers.Tag(
-                'link to add a series', 'a',
-                attrs={'href':
-                    canonical_url(self.distro, view_name='+addseries')},
-                text='Add series'),
-            soupmatchers.Tag(
-                'Series and milestones widget', 'h2',
-                text='Series and milestones'),
-            )
-        self.assertThat(view.render(), series_matches)
-
-    def test_distributionpage_addseries_link_noadmin(self):
-        """Verify that a non-admin does not see the +addseries link
-        nor the series header (since there is no series yet).
-        """
-        login_person(self.simple_user)
-        view = create_initialized_view(
-            self.distro, '+index', principal=self.simple_user)
-        add_series_match = soupmatchers.HTMLContains(
-            soupmatchers.Tag(
-                'link to add a series', 'a',
-                attrs={'href':
-                    canonical_url(self.distro, view_name='+addseries')},
-                text='Add series'))
-        series_header_match = soupmatchers.HTMLContains(
-            soupmatchers.Tag(
-                'Series and milestones widget', 'h2',
-                text='Series and milestones'))
-        self.assertThat(
-            view.render(),
-            Not(MatchesAny(add_series_match, series_header_match)))
-
-    def test_distributionpage_series_list_noadmin(self):
-        """Verify that a non-admin does see the series list
-        when there is a series.
-        """
-        series = self.factory.makeDistroSeries(distribution=self.distro,
-            status=SeriesStatus.CURRENT)
-        login_person(self.simple_user)
-        view = create_initialized_view(
-            self.distro, '+index', principal=self.simple_user)
-        add_series_match = soupmatchers.HTMLContains(
-            soupmatchers.Tag(
-                'link to add a series', 'a',
-                attrs={'href':
-                    canonical_url(self.distro, view_name='+addseries')},
-                text='Add series'))
-        series_header_match = soupmatchers.HTMLContains(
-            soupmatchers.Tag(
-                'Series and milestones widget', 'h2',
-                text='Series and milestones'))
-        self.assertThat(view.render(), series_header_match)
-        self.assertThat(view.render(), Not(add_series_match))