diff --git a/src/collective/weather/browser/controlpanel.py b/src/collective/weather/browser/controlpanel.py
index 98d04a7..bf75c28 100644
--- a/src/collective/weather/browser/controlpanel.py
+++ b/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))
diff --git a/src/collective/weather/browser/interfaces.py b/src/collective/weather/browser/interfaces.py
index 325a4e4..f14c709 100644
--- a/src/collective/weather/browser/interfaces.py
+++ b/src/collective/weather/browser/interfaces.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
from zope.interface import Interface
from zope import schema
@@ -15,24 +17,26 @@
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,
@@ -40,22 +44,24 @@ class IGoogleWeatherSchema(form.Schema):
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,
@@ -63,18 +69,20 @@ class IYahooWeatherSchema(form.Schema):
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
"""
-
\ No newline at end of file
diff --git a/src/collective/weather/profiles/default/registry.xml b/src/collective/weather/profiles/default/registry.xml
index 9583ce9..abc7aed 100644
--- a/src/collective/weather/profiles/default/registry.xml
+++ b/src/collective/weather/profiles/default/registry.xml
@@ -3,4 +3,4 @@
-
\ No newline at end of file
+
diff --git a/src/collective/weather/profiles/uninstall/registry.xml b/src/collective/weather/profiles/uninstall/registry.xml
index 240f188..f80defd 100644
--- a/src/collective/weather/profiles/uninstall/registry.xml
+++ b/src/collective/weather/profiles/uninstall/registry.xml
@@ -1,3 +1,12 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/collective/weather/tests/test_controlpanel.py b/src/collective/weather/tests/test_controlpanel.py
new file mode 100644
index 0000000..80c9f1e
--- /dev/null
+++ b/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')
diff --git a/src/collective/weather/utility.py b/src/collective/weather/utility.py
index a0bc511..cc344c3 100644
--- a/src/collective/weather/utility.py
+++ b/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'))