> > + def test_import_target_sourcepackage(self):
> > + # If the entry has a DistroSeries and a SourcePackageName, the
> > + # import_target is the corresponding SourcePackage.
> > + series = self.factory.makeDistroSeries()
> > + packagename = self.factory.makeSourcePackageName()
> > + package = SourcePackage(packagename, series)
>
> package = self.factory.makeSourcePackage(packagename, series)
>
> Works just as well ... ;-)
Oh, nice! Saves me an import.
> > + # No translatable series.
> > + series_text = view.product_translatable_series
> > + self.assertEqual("Project has no translatable series.",
> series_text)
> > +
> > + # One translatable series.
> > + extra_series = self.factory.makeProductSeries(product=product)
> > + self.factory.makePOTemplate(productseries=extra_series)
> > + series_text = view.product_translatable_series
> > + self.assertIn("Project has translatable series:", series_text)
> > + # A link follows, and the sentence ends in a period.
> > + self.assertEqual('</a>.', series_text[-5:])
>
> I am not all too happy about this testing style and wonder if doing this
> in a unit test rather than a doctest is the Right Thing. But I guess
> it's not a big deal, so you can leave it for now.
The unit test should go through the corner cases. It's ugly, but I
don't see any other way without bloating the code, writing helpers to
get helpful failure messages etc. The pagetest does the "happy path."
This particular test does have doctest feel to it. In this case I
thought a "story" setup made sense because of the close juxtaposition of
the 0, 1, n, and n > 3 cases as extensions that share both setup and
assertions.
> > === added file translations/ browser/ tests/test_ translationimpo rtqueueentry. py' translations/ browser/ tests/test_ translationimpo rtqueueentry. py translations/ browser/ tests/test_ translationimpo rtqueueentry. py onalLayer launchpad. layers import TranslationsLayer, setFirstLayer launchpad. webapp import canonical_url launchpad. webapp. servers import LaunchpadTestRe quest model.sourcepac kage import SourcePackage .model. translationimpo rtqueue import ( rtQueue)
> 'lib/lp/
> > --- lib/lp/
> 1970-01-01 00:00:00 +0000
> > +++ lib/lp/
> 2010-02-10 13:06:21 +0000
> > @@ -0,0 +1,165 @@
> > +# Copyright 2010 Canonical Ltd. This software is licensed under the
> > +# GNU Affero General Public License version 3 (see the file LICENSE).
> > +
> > +"""Unit tests for translation import queue views."""
> > +
> > +from datetime import datetime
> > +from pytz import timezone
> > +from unittest import TestLoader
> > +
> > +from zope.component import getMultiAdapter
> > +from zope.security.proxy import removeSecurityProxy
> > +
> > +from canonical.testing import LaunchpadFuncti
> > +
> > +from canonical.
> > +from canonical.
> > +from canonical.
> > +from lp.registry.
> > +from lp.testing import TestCaseWithFactory
> > +from lp.translations
> > + TranslationImpo
>
> Don't you get an warnings about this? Should test code be importing from
> model code? I thought I remember that rule (and it makes sense if we
> profess to test against Interfaces).
No warnings, but now that you mention it, I'm not sure this is allowed.
Changed.
> > +class TestTranslation ImportQueueEntr yView(TestCaseW ithFactory) : onalLayer lationImportQue ueEntryView, self).setUp( rtQueue( ) ITranslationImp ortQueue)
> > + """Tests for the queue entry review form."""
> > +
> > + layer = LaunchpadFuncti
> > +
> > + def setUp(self):
> > + super(TestTrans
> > + '<email address hidden>')
> > + self.queue = TranslationImpo
>
> I think this should really be:
> self.queue = getUtility(
Done.
> > + def test_import_ target_ sourcepackage( self): makeDistroSerie s() makeSourcePacka geName( ) packagename, series) makeSourcePacka ge(packagename, series)
> > + # If the entry has a DistroSeries and a SourcePackageName, the
> > + # import_target is the corresponding SourcePackage.
> > + series = self.factory.
> > + packagename = self.factory.
> > + package = SourcePackage(
>
> package = self.factory.
>
> Works just as well ... ;-)
Oh, nice! Saves me an import.
> > + # No translatable series. translatable_ series l("Project has no translatable series.", makeProductSeri es(product= product) makePOTemplate( productseries= extra_series) translatable_ series "Project has translatable series:", series_text) l('</a> .', series_text[-5:])
> > + series_text = view.product_
> > + self.assertEqua
> series_text)
> > +
> > + # One translatable series.
> > + extra_series = self.factory.
> > + self.factory.
> > + series_text = view.product_
> > + self.assertIn(
> > + # A link follows, and the sentence ends in a period.
> > + self.assertEqua
>
> I am not all too happy about this testing style and wonder if doing this
> in a unit test rather than a doctest is the Right Thing. But I guess
> it's not a big deal, so you can leave it for now.
The unit test should go through the corner cases. It's ugly, but I
don't see any other way without bloating the code, writing helpers to
get helpful failure messages etc. The pagetest does the "happy path."
This particular test does have doctest feel to it. In this case I
thought a "story" setup made sense because of the close juxtaposition of
the 0, 1, n, and n > 3 cases as extensions that share both setup and
assertions.
> > === modified file 'lib/lp/ translations/ browser/ translationimpo rtqueue. py' translations/ browser/ translationimpo rtqueue. py 2010-01-13 translations/ browser/ translationimpo rtqueue. py 2010-02-10
> > --- lib/lp/
> 04:46:11 +0000
> > +++ lib/lp/
> > @@ -129,6 +133,84 @@ target( self): productseries distroseries sourcepackagena me ISourcePackageF actory) new(sourcepacka gename, distroseries)
> > return None
> >
> > @property
> > + def import_
> > + """The entry's `ProductSeries` or `SourcePackage`."""
> > + productseries = self.context.
> > + distroseries = self.context.
> > + sourcepackagename = self.context.
> > + if distroseries is None:
> > + return productseries
> > + else:
> > + factory = getUtility(
> > + return factory.
>
> Is this a "getOrMake" factory? Then this makes sense.
There is no distinction in this case. SourcePackage is immutable.
Stateless, not ORM-backed. Comparisons are on value, not identity:
assert SourcePackage(x, y) is not SourcePackage(x, y)
assert SourcePackage(x, y) == SourcePackage(x, y)
> > + @property templates_ link(self) : productseries is not None, ( productseries. potemplate_ count productseries, rootsite= 'translations' ) productseries, 'translations' ,
> > + def productseries_
> > + """Return link to `ProductSeries`' templates.
> > +
> > + Use this only if the entry is attached to a `ProductSeries`.
> > + """
> > + assert self.context.
> > + "Entry is not attached to a ProductSeries.")
> > +
> > + template_count = self.context.
> > + if template_count == 0:
> > + return "no templates"
> > + else:
> > + link = "%s/+templates" % canonical_url(
> > + self.context.
>
> I think this works, too:
> link = canonical_url(
> self.context.
> rootsite=
> view="+templates")
Alas, it does not!
Jeroen