Stub will comment on these, if needed. Look ok to me. ;)
> === modified file 'lib/canonical/launchpad/security.py'
> --- lib/canonical/launchpad/security.py 2011-04-14 15:26:55 +0000
> +++ lib/canonical/launchpad/security.py 2011-04-15 16:31:45 +0000
> @@ -113,6 +113,7 @@
> IDistributionSourcePackage,
> )
> from lp.registry.interfaces.distroseries import IDistroSeries
> +from lp.registry.interfaces.distroseriesparent import IDistroSeriesParent
> from lp.registry.interfaces.distroseriesdifference import (
> IDistroSeriesDifferenceEdit,
> )
> @@ -1014,6 +1015,16 @@
> usedfor = IDistroSeries
>
>
> +class EditDistroSeriesParent(AuthorizationBase):
> + """DistroSeriesParent can be edited by the same people who can edit
> + the derived_distroseries."""
> + permission = "launchpad.Edit"
> + usedfor = IDistroSeriesParent
> +
> + def checkAuthenticated(self, user):
> + return check_permission(self.permission, self.obj.derived_series)
Using check_permission in security adapters is flawed and needs to be stopped.
Please see bug 764406 as to why. You can fix this by referencing
EditDistroSeriesByReleaseManagerOrDistroOwnersOrAdmins directly or leave it in
to be fixed when that bug is fixed. ;)
Hm, why not let makeDistroSeriesParent create the series? Just pick them from
the dsp object you get from the factory.
> + results = getUtility(IDistroSeriesParentSet).getByDerivedSeries(
> + derived_series)
> + self.assertEqual(1, results.count())
> + self.assertEqual(parent_series, results[0].parent_series)
> +
> + # Making a second parent should add it to the results.
Uh-oh, two-stage test. I would prefer this in two tests.
> + results = getUtility(IDistroSeriesParentSet).getByParentSeries(
> + parent_series)
> + self.assertEqual(1, results.count())
> + self.assertEqual(derived_series, results[0].derived_series)
> +
> + # Making a second child should add it to the results.
In case you didn't notice, I don't think using setUp for sample data creation
is a good idea. In this case, self.person is only used in two tests, why not
just create them there? And the series could be created by
makeDistroSeriesParent, just like mentioned in the previous test case. Please
remove setUp from this test case.
Thanks for adding the factory to go with this new class.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Julian,
thanks for adding this linking table. You indeed almost had me bored but I did
find a few of my pet issues in your branch ... ;-)
I'd really like to see the tests cleaned up before I approve this.
review needs-fixing
Cheers,
Henning
Am 15.04.2011 18:17, schrieb Julian Edwards: schema/ comments. sql' schema/ patch-2208- 99-0.sql' schema/ security. cfg'
> === modified file 'database/
> === added file 'database/
> === modified file 'database/
Stub will comment on these, if needed. Look ok to me. ;)
> === modified file 'lib/canonical/ launchpad/ security. py' launchpad/ security. py 2011-04-14 15:26:55 +0000 launchpad/ security. py 2011-04-15 16:31:45 +0000 urcePackage, interfaces. distroseries import IDistroSeries interfaces. distroseriespar ent import IDistroSeriesParent interfaces. distroseriesdif ference import ( fferenceEdit, sParent( AuthorizationBa se): Parent can be edited by the same people who can edit distroseries. """ ted(self, user): n(self. permission, self.obj. derived_ series)
> --- lib/canonical/
> +++ lib/canonical/
> @@ -113,6 +113,7 @@
> IDistributionSo
> )
> from lp.registry.
> +from lp.registry.
> from lp.registry.
> IDistroSeriesDi
> )
> @@ -1014,6 +1015,16 @@
> usedfor = IDistroSeries
>
>
> +class EditDistroSerie
> + """DistroSeries
> + the derived_
> + permission = "launchpad.Edit"
> + usedfor = IDistroSeriesParent
> +
> + def checkAuthentica
> + return check_permissio
Using check_permission in security adapters is flawed and needs to be stopped. sByReleaseManag erOrDistroOwner sOrAdmins directly or leave it in
Please see bug 764406 as to why. You can fix this by referencing
EditDistroSerie
to be fixed when that bug is fixed. ;)
> + AnonymousAuthor ization) : registry/ configure. zcml' registry/ interfaces/ distroseriespar ent.py' registry/ model/distroser iesparent. py'
> +
> class ViewCountry(
> """Anyone can view a Country."""
> usedfor = ICountry
>
> === modified file 'lib/lp/
> === added file 'lib/lp/
> === added file 'lib/lp/
Yeah, this is the boring bit ... ;) Thanks for a solid implementation.
> === added file 'lib/lp/ registry/ tests/test_ distroseriespar ent.py' registry/ tests/test_ distroseriespar ent.py 1970-01-01 00:00:00 +0000 registry/ tests/test_ distroseriespar ent.py 2011-04-15 16:31:45 +0000 verify import verifyObject interfaces import Unauthorized launchpad. ftests import login testing. layers import ( nalLayer, eLayer, interfaces. distroseriespar ent import ( rent, rentSet, tory, sampledata import LAUNCHPAD_ADMIN sParent( TestCaseWithFac tory): rent` model.""" eLayer tory.setUp( self) makeDistributio n(name= 'conftest' )
> --- lib/lp/
> +++ lib/lp/
> @@ -0,0 +1,145 @@
> +# Copyright 2011 Canonical Ltd. This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +"""Tests for DistroSeriesParent model class."""
> +
> +__metaclass__ = type
> +
> +from testtools.matchers import (
> + Equals,
> + MatchesStructure,
> + )
> +
> +from zope.component import getUtility
> +from zope.interface.
> +from zope.security.
> +
> +from canonical.
> +from canonical.
> + DatabaseFunctio
> + ZopelessDatabas
> + )
> +from lp.registry.
> + IDistroSeriesPa
> + IDistroSeriesPa
> + )
> +from lp.testing import (
> + person_logged_in,
> + TestCaseWithFac
> + )
> +from lp.testing.
> +
> +
> +class TestDistroSerie
> + """Test the `DistroSeriesPa
> + layer = ZopelessDatabas
> +
> + def setUp(self):
> + TestCaseWithFac
> + #self.distribution = self.factory.
Oh, an unused setUp!
> + interface( self): makeDistroSerie sParent( ) IDistroSeriesPa rent, dsp) (verified) (self): makeDistroSerie s() makeDistroSerie s() makeDistroSerie sParent( series= derived_ series, series= parent_ series, series= Equals( derived_ series) , series= Equals( parent_ series) , Equals( True) edSeries( self): makeDistroSerie s() makeDistroSerie s() makeDistroSerie sParent(
> + def test_verify_
> + # Test the interface for the model.
> + dsp = self.factory.
> + verified = verifyObject(
> + self.assertTrue
> +
> + def test_properties
> + # Test the model properties.
> + parent_series = self.factory.
> + derived_series = self.factory.
> + dsp = self.factory.
> + derived_
> + parent_
> + initialized=True
> + )
> +
> + self.assertThat(
> + dsp,
> + MatchesStructure(
> + derived_
> + parent_
> + initialized=
> + ))
> +
> + def test_getByDeriv
> + parent_series = self.factory.
> + derived_series = self.factory.
> + self.factory.
> + derived_series, parent_series)
Hm, why not let makeDistroSerie sParent create the series? Just pick them from
the dsp object you get from the factory.
> + results = getUtility( IDistroSeriesPa rentSet) .getByDerivedSe ries( l(parent_ series, results[ 0].parent_ series)
> + derived_series)
> + self.assertEqual(1, results.count())
> + self.assertEqua
> +
> + # Making a second parent should add it to the results.
Uh-oh, two-stage test. I would prefer this in two tests.
> + self.factory. makeDistroSerie sParent( makeDistroSerie s()) IDistroSeriesPa rentSet) .getByDerivedSe ries( tSeries( self): makeDistroSerie s() makeDistroSerie s() makeDistroSerie sParent(
> + derived_series, self.factory.
> + results = getUtility(
> + derived_series)
> + self.assertEqual(2, results.count())
> +
> + def test_getByParen
> + parent_series = self.factory.
> + derived_series = self.factory.
> + dsp = self.factory.
> + derived_series, parent_series)
Same comment about the factory method here.
> + results = getUtility( IDistroSeriesPa rentSet) .getByParentSer ies( l(derived_ series, results[ 0].derived_ series)
> + parent_series)
> + self.assertEqual(1, results.count())
> + self.assertEqua
> +
> + # Making a second child should add it to the results.
And here about splitting the test. ;-)
> + self.factory. makeDistroSerie sParent( makeDistroSerie s(), parent_series) IDistroSeriesPa rentSet) .getByParentSer ies( sParentSecurity (TestCaseWithFa ctory): nalLayer oSeriesParentSe curity, self).setUp() makeDistroSerie s() makeDistroSerie s() makePerson( )
> + self.factory.
> + results = getUtility(
> + parent_series)
> + self.assertEqual(2, results.count())
> +
> +
> +class TestDistroSerie
> +
> + layer = DatabaseFunctio
> +
> + def setUp(self):
> + super(TestDistr
> + self.parent_series = self.factory.
> + self.derived_series = self.factory.
> + self.person = self.factory.
In case you didn't notice, I don't think using setUp for sample data creation sParent, just like mentioned in the previous test case. Please
is a good idea. In this case, self.person is only used in two tests, why not
just create them there? And the series could be created by
makeDistroSerie
remove setUp from this test case.
> + person_ is_unauthorized (self): IDistroSeriesPa rentSet) new(self. derived_ series, self.parent_series, False) logged_ in(self. person) : self): IDistroSeriesPa rentSet) series, self.parent_series, False) series= Equals( self.derived_ series) , series= Equals( self.parent_ series) , Equals( False) drivers_ can_edit( self): _ADMIN) series. distribution. driver = self.person logged_ in(self. person) : dit() can_edit( self): _ADMIN) dit() owners_ can_edit( self): _ADMIN) series. distribution. owner = self.person logged_ in(self. person) : dit() testing/ factory. py'
> + def test_random_
> + dsp_set = getUtility(
> + dsp = dsp_set.
> + with person_
> + self.assertRaises(
> + Unauthorized,
> + setattr, dsp, "derived_series", self.parent_series)
> +
> + def assertCanEdit(
> + dsp_set = getUtility(
> + dsp = dsp_set.new(
> + self.derived_
> + self.assertThat(
> + dsp,
> + MatchesStructure(
> + derived_
> + parent_
> + initialized=
> + ))
> +
> + def test_distro_
> + # Test that distro drivers can edit the data.
> + login(LAUNCHPAD
> + self.derived_
> + with person_
> + self.assertCanE
> +
> + def test_admins_
> + login(LAUNCHPAD
> + self.assertCanE
> +
> + def test_distro_
> + login(LAUNCHPAD
> + self.derived_
> + with person_
> + self.assertCanE
>
> === modified file 'lib/lp/
Thanks for adding the factory to go with this new class. enigmail. mozdev. org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAk2 sEG8ACgkQBT3oW1 L17ijtCACeIwR8e f+KxGpz/ UWHJ5e7+ x5W xcrbmTfLtVASIv5 YJ
gdYAnjY6RX5u2Hy
=+P/s
-----END PGP SIGNATURE-----