launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12984
[Merge] lp:~abentley/launchpad/product-from-project-info-type into lp:launchpad
Aaron Bentley has proposed merging lp:~abentley/launchpad/product-from-project-info-type into lp:launchpad.
Commit message:
Allow selecting information type when creating via Project Group.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~abentley/launchpad/product-from-project-info-type/+merge/128147
= Summary =
Allow selecting information type when creating via Project Group.
== Proposed fix ==
Remove the IProductSet.providedBy checks that caused the field to be hidden.
== Pre-implementation notes ==
None
== LOC Rationale ==
Part of Private products
== Implementation details ==
converted makeForm into a funtion so that it could be used in other test cases.
== Tests ==
bin/test -t test_information_type_saved -t test_information_type -t TestProductAddView
== Demo and Q/A ==
Enable the feature flag "disclosure.private_projects.enabled".
>From a Project Group (on which you have Launchpad.Edit), click "Register a project in...". You should be able to select the information type. The type you choose should be respected.
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/registry/browser/product.py
lib/lp/registry/browser/tests/test_product.py
lib/lp/registry/browser/tests/test_projectgroup.py
lib/lp/registry/browser/project.py
--
https://code.launchpad.net/~abentley/launchpad/product-from-project-info-type/+merge/128147
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~abentley/launchpad/product-from-project-info-type into lp:launchpad.
=== modified file 'lib/lp/registry/browser/product.py'
--- lib/lp/registry/browser/product.py 2012-10-04 15:54:06 +0000
+++ lib/lp/registry/browser/product.py 2012-10-05 01:28:24 +0000
@@ -1942,10 +1942,9 @@
# The JSON cache must be populated before the super call, since
# the form is rendered during LaunchpadFormView's initialize()
# when an action is invoked.
- if IProductSet.providedBy(self.context):
- cache = IJSONRequestCache(self.request)
- json_dump_information_types(cache,
- PUBLIC_PROPRIETARY_INFORMATION_TYPES)
+ cache = IJSONRequestCache(self.request)
+ json_dump_information_types(cache,
+ PUBLIC_PROPRIETARY_INFORMATION_TYPES)
super(ProjectAddStepTwo, self).initialize()
@property
@@ -1989,7 +1988,7 @@
hidden_fields = self.form_fields.select(*hidden_names)
private_projects = bool(getFeatureFlag(PRIVATE_PROJECTS_FLAG))
- if not private_projects or not IProductSet.providedBy(self.context):
+ if not private_projects:
hidden_names.extend([
'information_type', 'bug_supervisor', 'driver'])
=== modified file 'lib/lp/registry/browser/project.py'
--- lib/lp/registry/browser/project.py 2012-07-24 06:39:54 +0000
+++ lib/lp/registry/browser/project.py 2012-10-05 01:28:24 +0000
@@ -522,6 +522,7 @@
displayname=data['displayname'],
licenses=data['licenses'],
license_info=data['license_info'],
+ information_type=data['information_type'],
project=self.context,
)
=== modified file 'lib/lp/registry/browser/tests/test_product.py'
--- lib/lp/registry/browser/tests/test_product.py 2012-10-04 17:37:33 +0000
+++ lib/lp/registry/browser/tests/test_product.py 2012-10-05 01:28:24 +0000
@@ -1,10 +1,12 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for product views."""
__metaclass__ = type
+__all__ = ['make_product_form']
+
from lazr.restful.interfaces import IJSONRequestCache
from soupmatchers import (
HTMLContains,
@@ -102,6 +104,49 @@
self.assertThat(browser.contents, Not(HTMLContains(self.lp_tag)))
+def make_product_form(person=None, action=1, proprietary=False):
+ """Return form data for product creation.
+
+ :param person: A person to associate with the product. Mandatory for
+ proprietary.
+ :param action: 1 means submit step 1. 2 means submit step 2 (completion)
+ :param proprietary: If true, create a PROPRIETARY product.
+ """
+ if action == 1:
+ return {
+ 'field.actions.continue': 'Continue',
+ 'field.__visited_steps__': ProjectAddStepOne.step_name,
+ 'field.displayname': 'Fnord',
+ 'field.name': 'fnord',
+ 'field.title': 'fnord',
+ 'field.summary': 'fnord summary',
+ }
+ else:
+ form = {
+ 'field.actions.continue': 'Continue',
+ 'field.__visited_steps__': '%s|%s' % (
+ ProjectAddStepOne.step_name, ProjectAddStepTwo.step_name),
+ 'field.displayname': 'Fnord',
+ 'field.name': 'fnord',
+ 'field.title': 'fnord',
+ 'field.summary': 'fnord summary',
+ 'field.disclaim_maintainer': 'off',
+ }
+ if proprietary:
+ form['field.information_type'] = 'PROPRIETARY'
+ form['field.owner'] = person.name
+ form['field.driver'] = person.name
+ form['field.bug_supervisor'] = person.name
+ form['field.licenses'] = License.OTHER_PROPRIETARY.title
+ form['field.license_info'] = 'Commercial Subscription'
+ else:
+ form['field.information_type'] = 0
+ form['field.owner'] = ''
+ form['field.licenses'] = ['MIT']
+ form['field.license_info'] = ''
+ return form
+
+
class TestProductAddView(TestCaseWithFactory):
"""Tests the configuration links and helpers."""
@@ -111,32 +156,6 @@
super(TestProductAddView, self).setUp()
self.product_set = getUtility(IProductSet)
- def makeForm(self, action):
- if action == 1:
- return {
- 'field.actions.continue': 'Continue',
- 'field.__visited_steps__': ProjectAddStepOne.step_name,
- 'field.displayname': 'Fnord',
- 'field.name': 'fnord',
- 'field.title': 'fnord',
- 'field.summary': 'fnord summary',
- }
- else:
- return {
- 'field.actions.continue': 'Continue',
- 'field.__visited_steps__': '%s|%s' % (
- ProjectAddStepOne.step_name, ProjectAddStepTwo.step_name),
- 'field.displayname': 'Fnord',
- 'field.name': 'fnord',
- 'field.title': 'fnord',
- 'field.summary': 'fnord summary',
- 'field.owner': '',
- 'field.licenses': ['MIT'],
- 'field.license_info': '',
- 'field.disclaim_maintainer': 'off',
- 'field.information_type': 0,
- }
-
def test_view_data_model(self):
# The view's json request cache contains the expected data.
view = create_initialized_view(self.product_set, '+new')
@@ -167,7 +186,7 @@
registrant = self.factory.makePerson(name='pting')
transaction.commit()
login_person(registrant)
- form = self.makeForm(action=1)
+ form = make_product_form(action=1)
view = create_initialized_view(self.product_set, '+new', form=form)
owner_widget = view.view.widgets['owner']
self.assertEqual('pting', view.view.initial_values['owner'])
@@ -195,7 +214,7 @@
membership_policy=TeamMembershipPolicy.RESTRICTED)
transaction.commit()
login_person(registrant)
- form = self.makeForm(action=2)
+ form = make_product_form(action=2)
form['field.owner'] = team.name
view = create_initialized_view(self.product_set, '+new', form=form)
self.assertEqual(0, len(view.view.errors))
@@ -207,7 +226,7 @@
# and the registry team is made the maintainer.
registrant = self.factory.makePerson()
login_person(registrant)
- form = self.makeForm(action=2)
+ form = make_product_form(action=2)
form['field.owner'] = registrant.name
form['field.disclaim_maintainer'] = 'on'
view = create_initialized_view(self.product_set, '+new', form=form)
@@ -220,7 +239,7 @@
# not selected.
registrant = self.factory.makePerson()
login_person(registrant)
- form = self.makeForm(action=2)
+ form = make_product_form(action=2)
form['field.owner'] = ''
del form['field.disclaim_maintainer']
view = create_initialized_view(self.product_set, '+new', form=form)
@@ -232,7 +251,7 @@
# selected.
registrant = self.factory.makePerson()
login_person(registrant)
- form = self.makeForm(action=2)
+ form = make_product_form(action=2)
form['field.owner'] = ''
form['field.disclaim_maintainer'] = 'on'
view = create_initialized_view(self.product_set, '+new', form=form)
@@ -245,9 +264,7 @@
# if the private projects feature flag is not enabled.
registrant = self.factory.makePerson()
login_person(registrant)
- form = self.makeForm(action=2)
- form['field.information_type'] = 'PROPRIETARY'
- form['field.owner'] = registrant.name
+ form = make_product_form(registrant, action=2, proprietary=True)
view = create_initialized_view(self.product_set, '+new', form=form)
self.assertEqual(0, len(view.view.errors))
product = self.product_set.getByName('fnord')
@@ -259,14 +276,8 @@
with FeatureFixture({u'disclosure.private_projects.enabled': u'on'}):
registrant = self.factory.makePerson()
login_person(registrant)
- form = self.makeForm(action=2)
- form['field.information_type'] = 'PROPRIETARY'
- form['field.owner'] = registrant.name
- form['field.driver'] = registrant.name
+ form = make_product_form(registrant, action=2, proprietary=True)
form['field.maintainer'] = registrant.name
- form['field.bug_supervisor'] = registrant.name
- form['field.licenses'] = License.OTHER_PROPRIETARY.title
- form['field.license_info'] = 'Commericial Subscription'
view = create_initialized_view(
self.product_set, '+new', form=form)
self.assertEqual(0, len(view.view.errors))
=== modified file 'lib/lp/registry/browser/tests/test_projectgroup.py'
--- lib/lp/registry/browser/tests/test_projectgroup.py 2012-08-14 23:27:07 +0000
+++ lib/lp/registry/browser/tests/test_projectgroup.py 2012-10-05 01:28:24 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for project group views."""
@@ -13,8 +13,12 @@
from zope.security.interfaces import Unauthorized
from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
+from lp.app.enums import InformationType
+from lp.registry.browser.tests.test_product import make_product_form
from lp.registry.enums import EXCLUSIVE_TEAM_POLICY
from lp.registry.interfaces.person import IPersonSet
+from lp.registry.interfaces.product import IProductSet
+from lp.services.features.testing import FeatureFixture
from lp.services.webapp import canonical_url
from lp.services.webapp.interfaces import ILaunchBag
from lp.testing import (
@@ -111,3 +115,33 @@
browser.open(canonical_url(self.project_group, view_name='+edit'))
url = canonical_url(self.project_group, view_name='+review')
self.assertRaises(Unauthorized, browser.open, url)
+
+
+class TestProjectGroupAddProductViews(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_information_type(self):
+ # Information type controls are provided when creating a project via a
+ # project group.
+ self.useFixture(
+ FeatureFixture({u'disclosure.private_projects.enabled': u'on'}))
+ form = make_product_form(action=1)
+ project = self.factory.makeProject()
+ with person_logged_in(project.owner):
+ view = create_initialized_view(project, '+newproduct', form=form)
+ self.assertIn('information_type_data',
+ IJSONRequestCache(view.request).objects)
+ self.assertIsNot(None, view.view.form_fields.get('information_type'))
+
+ def test_information_type_saved(self):
+ # Setting information_type to PROPRIETARY via form actually works.
+ self.useFixture(
+ FeatureFixture({u'disclosure.private_projects.enabled': u'on'}))
+ project = self.factory.makeProject()
+ form = make_product_form(project.owner, action=2, proprietary=True)
+ with person_logged_in(project.owner):
+ view = create_initialized_view(project, '+newproduct', form=form)
+ self.assertEqual(0, len(view.view.errors))
+ product = getUtility(IProductSet).getByName(form['field.name'])
+ self.assertEqual(InformationType.PROPRIETARY, product.information_type)
Follow ups