Skip to content
Browse files

registry records were renamed; added tests for the control panel and …

…registry
  • Loading branch information...
1 parent 4017a42 commit c26ff8aef4d100067be06d95fcf5e9ae20f00d55 @hvelarde hvelarde committed Jul 23, 2012
View
16 src/collective/weather/browser/controlpanel.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
from zope.component import getUtility
from zope.interface import alsoProvides
@@ -35,7 +37,7 @@ class NoaaGroup(group.Group):
class WeatherControlPanelEditForm(controlpanel.RegistryEditForm):
schema = IWeatherSchema
- label = _("Weather setup")
+ label = _("Weather Setup")
description = _("""Lets you configure several weather locations""")
fields = IGoogleWeatherSchema
@@ -47,12 +49,12 @@ def getContent(self):
# def updateFields(self):
# super(WeatherControlPanelEditForm, self).updateFields()
- # self.fields['g_locations_id'].widgetFactory = EnhancedTextLinesFieldWidget
- # self.groups[0].fields['y_locations_id'].widgetFactory = EnhancedTextLinesFieldWidget
- # self.groups[1].fields['n_locations_id'].widgetFactory = EnhancedTextLinesFieldWidget
+ # self.fields['google_location_ids'].widgetFactory = EnhancedTextLinesFieldWidget
+ # self.groups[0].fields['yahoo_location_ids'].widgetFactory = EnhancedTextLinesFieldWidget
+ # self.groups[1].fields['noaa_location_ids'].widgetFactory = EnhancedTextLinesFieldWidget
# def updateWidgets(self):
- # super(NITFSettingsEditForm, self).updateWidgets()
+ # super(WeatherControlPanelEditForm, self).updateWidgets()
# self.widgets['available_sections'].rows = 8
# self.widgets['available_sections'].style = u'width: 30%;'
@@ -100,5 +102,5 @@ def __repr__(self):
def _get_proxy(self, interface):
proxies = self.__proxies__
return proxies.get(interface) or \
- proxies.setdefault(interface, self.__registry__.\
- forInterface(interface))
+ proxies.setdefault(interface,
+ self.__registry__.forInterface(interface))
View
48 src/collective/weather/browser/interfaces.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
from zope.interface import Interface
from zope import schema
@@ -15,66 +17,72 @@
class IGoogleWeatherSchema(form.Schema):
- """
- Configurations for getting weather information from Google
+ """
+ Configurations for getting weather information from Google
"""
- use_google = schema.Bool(title=_(u"Use Google weather service"))
+ use_google = schema.Bool(title=_(u"Use Google weather service"),
+ default=False,
+ )
- form.widget(g_locations_id="collective.z3cform.widgets.enhancedtextlines.EnhancedTextLinesFieldWidget")
- g_locations_id = schema.List(title=_(u"Available options"),
+ form.widget(google_location_ids="collective.z3cform.widgets.enhancedtextlines.EnhancedTextLinesFieldWidget")
+ google_location_ids = schema.List(title=_(u"Available options"),
description=_(u"Enter here all available locations that will be shown in the locations drop down."),
- value_type= schema.TextLine(),
+ value_type=schema.TextLine(),
default=[],
required=False)
- g_hl = schema.TextLine(title=_(u"Language"),
+ google_language = schema.TextLine(title=_(u"Language"),
description=_(u"Enter the language code to show the content."),
required=False)
- g_units = schema.Choice(title=_(u'Units'),
+ google_units = schema.Choice(title=_(u'Units'),
description=_(u"Units to show the results."),
default='metric',
required=False,
source=units_vocab)
class IYahooWeatherSchema(form.Schema):
- """
+ """
Configurations for getting weather information from Yahoo
"""
- use_yahoo = schema.Bool(title=_(u"Use Yahoo weather service"))
+ use_yahoo = schema.Bool(title=_(u"Use Yahoo weather service"),
+ default=False,
+ )
- form.widget(y_locations_id="collective.z3cform.widgets.enhancedtextlines.EnhancedTextLinesFieldWidget")
- y_locations_id = schema.List(title=_(u"Available options"),
+ form.widget(yahoo_location_ids="collective.z3cform.widgets.enhancedtextlines.EnhancedTextLinesFieldWidget")
+ yahoo_location_ids = schema.List(title=_(u"Available options"),
description=_(u"Enter here all available locations that "
"will be shown in the locations drop down."
"Check http://code.google.com/p/python-weather-api/#Yahoo!_Weather for further information."),
- value_type= schema.TextLine(),
+ value_type=schema.TextLine(),
default=[],
required=False)
- y_units = schema.Choice(title=_(u'Units'),
+ yahoo_units = schema.Choice(title=_(u'Units'),
description=_(u"Units to show the results."),
default='metric',
required=False,
source=units_vocab)
class INoaaWeatherSchema(form.Schema):
- """
+ """
Configurations for getting weather information from NOAA
"""
- use_noaa = schema.Bool(title=_(u"Use NOAA weather service"))
+ use_noaa = schema.Bool(title=_(u"Use NOAA weather service"),
+ default=False,
+ )
- form.widget(n_locations_id="collective.z3cform.widgets.enhancedtextlines.EnhancedTextLinesFieldWidget")
- n_locations_id = schema.List(title=_(u"Available options"),
+ form.widget(noaa_location_ids="collective.z3cform.widgets.enhancedtextlines.EnhancedTextLinesFieldWidget")
+ noaa_location_ids = schema.List(title=_(u"Available options"),
description=_(u"Enter here all available locations that "
"will be shown in the locations drop down. "
"Check http://code.google.com/p/python-weather-api/#NOAA for further information."),
- value_type= schema.TextLine(),
+ value_type=schema.TextLine(),
default=[],
required=False)
@@ -83,8 +91,8 @@ class IWeatherSchema(IGoogleWeatherSchema, IYahooWeatherSchema, INoaaWeatherSche
"""
"""
+
class IWeatherControlPanelForm(Interface):
"""
Control panel used to manage weather configurations
"""
-
View
2 src/collective/weather/profiles/default/registry.xml
@@ -3,4 +3,4 @@
<records interface="collective.weather.browser.interfaces.IGoogleWeatherSchema" />
<records interface="collective.weather.browser.interfaces.IYahooWeatherSchema" />
<records interface="collective.weather.browser.interfaces.INoaaWeatherSchema" />
-</registry>
+</registry>
View
9 src/collective/weather/profiles/uninstall/registry.xml
@@ -1,3 +1,12 @@
<?xml version="1.0"?>
<registry>
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.use_google" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.google_location_ids" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.google_language" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.google_units" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.use_yahoo" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.yahoo_location_ids" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.yahoo_units" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.use_noaa" delete="true" />
+ <record name="collective.weather.browser.interfaces.IGoogleWeatherSchema.noaa_location_ids" delete="true" />
</registry>
View
168 src/collective/weather/tests/test_controlpanel.py
@@ -0,0 +1,168 @@
+# -*- coding: utf-8 -*-
+
+import unittest2 as unittest
+
+from zope.component import getMultiAdapter
+from zope.component import getUtility
+
+from plone.app.testing import TEST_USER_ID
+from plone.app.testing import logout
+from plone.app.testing import setRoles
+from plone.registry.interfaces import IRegistry
+
+from collective.weather.config import PROJECTNAME
+from collective.weather.browser.interfaces import IGoogleWeatherSchema
+from collective.weather.browser.interfaces import INoaaWeatherSchema
+from collective.weather.browser.interfaces import IYahooWeatherSchema
+from collective.weather.testing import INTEGRATION_TESTING
+
+
+class ControlPanelTestCase(unittest.TestCase):
+
+ layer = INTEGRATION_TESTING
+
+ def setUp(self):
+ self.portal = self.layer['portal']
+ self.controlpanel = self.portal['portal_controlpanel']
+ setRoles(self.portal, TEST_USER_ID, ['Manager'])
+
+ def test_controlpanel_has_view(self):
+ view = getMultiAdapter((self.portal, self.portal.REQUEST),
+ name='weather-controlpanel')
+ view = view.__of__(self.portal)
+ self.assertTrue(view())
+
+ def test_controlpanel_view_is_protected(self):
+ from AccessControl import Unauthorized
+ logout()
+ self.assertRaises(Unauthorized,
+ self.portal.restrictedTraverse,
+ '@@weather-controlpanel')
+
+ def test_controlpanel_installed(self):
+ actions = [a.getAction(self)['id']
+ for a in self.controlpanel.listActions()]
+ self.assertTrue('WeatherSettings' in actions,
+ 'control panel was not installed')
+
+ def test_controlpanel_removed_on_uninstall(self):
+ qi = self.portal['portal_quickinstaller']
+ qi.uninstallProducts(products=[PROJECTNAME])
+ actions = [a.getAction(self)['id']
+ for a in self.controlpanel.listActions()]
+ self.assertTrue('WeatherSettings' not in actions,
+ 'control panel was not removed')
+
+
+class GoogleRegistryTestCase(unittest.TestCase):
+
+ layer = INTEGRATION_TESTING
+
+ def setUp(self):
+ self.portal = self.layer['portal']
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(IGoogleWeatherSchema)
+ setRoles(self.portal, TEST_USER_ID, ['Manager'])
+
+ def test_use_google_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'use_google'))
+ self.assertEqual(self.settings.use_google, False)
+
+ def test_google_location_ids_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'google_location_ids'))
+ self.assertEqual(self.settings.google_location_ids, [])
+
+ def test_google_language_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'google_language'))
+ self.assertEqual(self.settings.google_language, None)
+
+ def test_google_units_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'google_units'))
+ self.assertEqual(self.settings.google_units, u'metric')
+
+ def get_record(self, record):
+ """ Helper function; it raises KeyError if the record is not in the
+ registry.
+ """
+ prefix = 'collective.weather.browser.interfaces.IGoogleWeatherSchema.'
+ return self.registry[prefix + record]
+
+ def test_records_removed_on_uninstall(self):
+ # XXX: I haven't found a better way to test this; anyone?
+ qi = self.portal['portal_quickinstaller']
+ qi.uninstallProducts(products=[PROJECTNAME])
+ self.assertRaises(KeyError, self.get_record, 'use_google')
+ self.assertRaises(KeyError, self.get_record, 'google_location_ids')
+ self.assertRaises(KeyError, self.get_record, 'google_language')
+ self.assertRaises(KeyError, self.get_record, 'google_units')
+
+
+class YahooRegistryTestCase(unittest.TestCase):
+
+ layer = INTEGRATION_TESTING
+
+ def setUp(self):
+ self.portal = self.layer['portal']
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(IYahooWeatherSchema)
+ setRoles(self.portal, TEST_USER_ID, ['Manager'])
+
+ def test_use_yahoo_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'use_yahoo'))
+ self.assertEqual(self.settings.use_yahoo, False)
+
+ def test_yahoo_location_ids_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'yahoo_location_ids'))
+ self.assertEqual(self.settings.yahoo_location_ids, [])
+
+ def test_yahoo_units_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'yahoo_units'))
+ self.assertEqual(self.settings.yahoo_units, u'metric')
+
+ def get_record(self, record):
+ """ Helper function; it raises KeyError if the record is not in the
+ registry.
+ """
+ prefix = 'collective.weather.browser.interfaces.IYahooWeatherSchema.'
+ return self.registry[prefix + record]
+
+ def test_records_removed_on_uninstall(self):
+ # XXX: I haven't found a better way to test this; anyone?
+ qi = self.portal['portal_quickinstaller']
+ qi.uninstallProducts(products=[PROJECTNAME])
+ self.assertRaises(KeyError, self.get_record, 'use_yahoo')
+ self.assertRaises(KeyError, self.get_record, 'yahoo_location_ids')
+ self.assertRaises(KeyError, self.get_record, 'yahoo_units')
+
+
+class NoaaRegistryTestCase(unittest.TestCase):
+
+ layer = INTEGRATION_TESTING
+
+ def setUp(self):
+ self.portal = self.layer['portal']
+ self.registry = getUtility(IRegistry)
+ self.settings = self.registry.forInterface(INoaaWeatherSchema)
+ setRoles(self.portal, TEST_USER_ID, ['Manager'])
+
+ def test_use_noaa_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'use_noaa'))
+ self.assertEqual(self.settings.use_noaa, False)
+
+ def test_noaa_location_ids_record_in_registry(self):
+ self.assertTrue(hasattr(self.settings, 'noaa_location_ids'))
+ self.assertEqual(self.settings.noaa_location_ids, [])
+
+ def get_record(self, record):
+ """ Helper function; it raises KeyError if the record is not in the
+ registry.
+ """
+ prefix = 'collective.weather.browser.interfaces.INoaaWeatherSchema.'
+ return self.registry[prefix + record]
+
+ def test_records_removed_on_uninstall(self):
+ # XXX: I haven't found a better way to test this; anyone?
+ qi = self.portal['portal_quickinstaller']
+ qi.uninstallProducts(products=[PROJECTNAME])
+ self.assertRaises(KeyError, self.get_record, 'use_noaa')
+ self.assertRaises(KeyError, self.get_record, 'noaa_location_ids')
View
22 src/collective/weather/utility.py
@@ -1,8 +1,6 @@
from AccessControl import ClassSecurityInfo
-from zope.component import getUtility
-
from zope.interface import classProvides
from zope.interface import implements
@@ -29,14 +27,12 @@ class Weather(SimpleItem):
security = ClassSecurityInfo()
- use_google = FieldProperty(IGoogleWeatherSchema("use_google"))
- g_locations_id = FieldProperty(IGoogleWeatherSchema("g_locations_id"))
- g_hl = FieldProperty(IGoogleWeatherSchema("g_hl"))
- g_units = FieldProperty(IGoogleWeatherSchema("g_units"))
- use_yahoo = FieldProperty(IYahooWeatherSchema("use_yahoo"))
- y_locations_id = FieldProperty(IYahooWeatherSchema("y_locations_id"))
- y_units = FieldProperty(IYahooWeatherSchema("y_units"))
- use_noaa = FieldProperty(INoaaWeatherSchema("use_noaa"))
- n_locations_id = FieldProperty(INoaaWeatherSchema("n_locations_id"))
-
-
+ use_google = FieldProperty(IGoogleWeatherSchema('use_google'))
+ google_location_ids = FieldProperty(IGoogleWeatherSchema('google_location_ids'))
+ google_language = FieldProperty(IGoogleWeatherSchema('google_language'))
+ google_units = FieldProperty(IGoogleWeatherSchema('google_units'))
+ use_yahoo = FieldProperty(IYahooWeatherSchema('use_yahoo'))
+ yahoo_location_ids = FieldProperty(IYahooWeatherSchema('yahoo_location_ids'))
+ yahoo_units = FieldProperty(IYahooWeatherSchema('yahoo_units'))
+ use_noaa = FieldProperty(INoaaWeatherSchema('use_noaa'))
+ noaa_location_ids = FieldProperty(INoaaWeatherSchema('noaa_location_ids'))

0 comments on commit c26ff8a

Please sign in to comment.
Something went wrong with that request. Please try again.