Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit c860fdfd9203dec86c33a4effc47a5dfee6f6601 @taito taito committed Jun 27, 2012
@@ -0,0 +1,9 @@
+*.egg-info
+*.mo
+*.pyc
+*.pyo
+*~
+.DS_Store
+.long-description.html
+collective/behavior/salable/docs/_build/*
+dist
@@ -0,0 +1,6 @@
+Introduction
+============
+
+
+
+This product may contain traces of nuts.
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
@@ -0,0 +1,3 @@
+from zope.i18nmessageid import MessageFactory
+
+_ = MessageFactory('collective.behavior.salable')
@@ -0,0 +1,39 @@
+from collective.behavior.salable.interfaces import ISalable
+from decimal import Decimal
+from plone.directives import form
+from rwproperty import getproperty
+from rwproperty import setproperty
+from zope.interface import alsoProvides
+from zope.interface import implements
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+alsoProvides(ISalable, form.IFormFieldProvider)
+
+
+class Salable(object):
+ """
+ """
+ implements(ISalable)
+
+ def __init__(self, context):
+ self.context = context
+
+ @getproperty
+ def salable(self):
+ return getattr(self.context, 'salable', True)
+
+ @setproperty
+ def salable(self, value):
+ """Set salable as Boolean
+
+ :param value: True or False
+ :type value: bool
+ """
+ if value is not True:
+ if value is not False:
+ raise ValueError('Not Bool')
+ setattr(self.context, 'salable', value)
@@ -0,0 +1,31 @@
+<configure
+ i18n_domain="collective.behavior.salable"
+ xmlns:five="http://namespaces.zope.org/five"
+ xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
+ xmlns:grok="http://namespaces.zope.org/grok"
+ xmlns:i18n="http://namespaces.zope.org/i18n"
+ xmlns:plone="http://namespaces.plone.org/plone"
+ xmlns="http://namespaces.zope.org/zope"
+ >
+
+ <includeDependencies package="." />
+ <grok:grok package="." />
+ <i18n:registerTranslations directory="locales" />
+
+
+ <genericsetup:registerProfile
+ description="Installs the collective.behavior.salable package"
+ directory="profiles/default"
+ name="default"
+ provides="Products.GenericSetup.interfaces.EXTENSION"
+ title="collective.behavior.salable"
+ />
+
+ <plone:behavior
+ description="Adds salable field."
+ factory=".behavior.Salable"
+ provides=".interfaces.ISalable"
+ title="Salable"
+ />
+
+</configure>
@@ -0,0 +1,12 @@
+from collective.behavior.salable import _
+from zope.interface import Interface
+from zope.schema import Bool
+
+
+class ISalable(Interface):
+ """Interface for Salable behavior."""
+
+ salable = Bool(
+ title=_(u"Salable"),
+ description=_(u"Uncheck this if not salable."),
+ default=True)
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<metadata>
+ <version>0</version>
+</metadata>
No changes.
@@ -0,0 +1,45 @@
+"""Base module for unittesting"""
+from plone.app.testing import FunctionalTesting
+from plone.app.testing import IntegrationTesting
+from plone.app.testing import PLONE_FIXTURE
+from plone.app.testing import PloneSandboxLayer
+
+import unittest
+
+
+class BehaviorSalableLayer(PloneSandboxLayer):
+
+ defaultBases = (PLONE_FIXTURE,)
+
+ def setUpZope(self, app, configurationContext):
+ """Set up Zope."""
+ # Load ZCML
+ import collective.behavior.salable
+ self.loadZCML(package=collective.behavior.salable)
+
+ def setUpPloneSite(self, portal):
+ """Set up Plone."""
+ # Install into Plone site using portal_setup
+ self.applyProfile(portal, 'collective.behavior.salable:default')
+
+ def tearDownZope(self, app):
+ """Tear down Zope."""
+
+
+FIXTURE = BehaviorSalableLayer()
+INTEGRATION_TESTING = IntegrationTesting(
+ bases=(FIXTURE,), name="BehaviorSalableLayer:Integration")
+FUNCTIONAL_TESTING = FunctionalTesting(
+ bases=(FIXTURE,), name="BehaviorSalableLayer:Functional")
+
+
+class IntegrationTestCase(unittest.TestCase):
+ """Base class for integration tests."""
+
+ layer = INTEGRATION_TESTING
+
+
+class FunctionalTestCase(unittest.TestCase):
+ """Base class for functional tests."""
+
+ layer = FUNCTIONAL_TESTING
@@ -0,0 +1,36 @@
+import unittest
+
+
+class TestISalable(unittest.TestCase):
+
+ def test_subclass(self):
+ from collective.behavior.salable.interfaces import ISalable
+ from zope.interface import Interface
+ self.assertTrue(issubclass(ISalable, Interface))
+
+ def get_schema(self, name):
+ """Get schema by name.
+
+ :param name: Name of schema.
+ :type name: str
+ """
+ from collective.behavior.salable.interfaces import ISalable
+ return ISalable.get(name)
+
+ def test_salable__instance(self):
+ schema = self.get_schema('salable')
+ from zope.schema import Bool
+ self.assertIsInstance(schema, Bool)
+
+ def test_salable__title(self):
+ schema = self.get_schema('salable')
+ self.assertEqual(schema.title, u'Salable')
+
+ def test_salable__description(self):
+ schema = self.get_schema('salable')
+ self.assertEqual(
+ schema.description, u'Uncheck this if not salable.')
+
+ def test_salable__default(self):
+ schema = self.get_schema('salable')
+ self.assertTrue(schema.default)
@@ -0,0 +1,50 @@
+import mock
+import unittest
+
+
+class TestSalable(unittest.TestCase):
+
+ def test_subclass(self):
+ from collective.behavior.salable.behavior import Salable
+ self.assertTrue(issubclass(Salable, object))
+
+ def create_instance(self, context=mock.Mock()):
+ from collective.behavior.salable.behavior import Salable
+ return Salable(context)
+
+ def test_instance(self):
+ instance = self.create_instance()
+ from collective.behavior.salable.behavior import Salable
+ self.assertIsInstance(instance, Salable)
+
+ def test_instance_provides_ISalable(self):
+ instance = self.create_instance()
+ from collective.behavior.salable.interfaces import ISalable
+ self.assertTrue(ISalable.providedBy(instance))
+
+ def test_instance__verifyObject(self):
+ instance = self.create_instance()
+ from collective.behavior.salable.interfaces import ISalable
+ from zope.interface.verify import verifyObject
+ self.assertTrue(verifyObject(ISalable, instance))
+
+ def test_instance__salable(self):
+ """First time access to salable"""
+ context = object()
+ instance = self.create_instance(context=context)
+ self.assertTrue(instance.salable)
+
+ def test_instance__salable__set(self):
+ context = mock.Mock()
+ instance = self.create_instance(context=context)
+ instance.salable = False
+ self.assertFalse(instance.salable)
+ self.assertFalse(instance.context.salable)
+
+ def set_salable(self, value):
+ context = mock.Mock()
+ instance = self.create_instance(context=context)
+ instance.salable = value
+
+ def test_instance__salable__ValueError(self):
+ self.assertRaises(ValueError, lambda: self.set_salable('AAA'))
@@ -0,0 +1,26 @@
+from Products.CMFCore.utils import getToolByName
+from collective.behavior.salable.tests.base import IntegrationTestCase
+
+
+class TestSetup(IntegrationTestCase):
+
+ def setUp(self):
+ self.portal = self.layer['portal']
+
+ def test_is_collective_behavior_salable_installed(self):
+ installer = getToolByName(self.portal, 'portal_quickinstaller')
+ self.failUnless(
+ installer.isProductInstalled('collective.behavior.salable'))
+
+ def test_metadata__version(self):
+ setup = getToolByName(self.portal, 'portal_setup')
+ self.assertEqual(
+ setup.getVersionForProfile(
+ 'profile-collective.behavior.salable:default'),
+ u'0'
+ )
+
+ def test_uninstall__package(self):
+ installer = getToolByName(self.portal, 'portal_quickinstaller')
+ installer.uninstallProducts(['collective.behavior.salable'])
+ self.failIf(installer.isProductInstalled('collective.behavior.salable'))
@@ -0,0 +1,43 @@
+from setuptools import find_packages
+from setuptools import setup
+
+
+setup(
+ name='collective.behavior.salable',
+ version='0.0',
+ description="Behavior to make content salable.",
+ long_description=open("README.rst").read(),
+ # Get more strings from
+ # http://pypi.python.org/pypi?:action=list_classifiers
+ classifiers=[
+ "Framework :: Plone",
+ "Framework :: Plone :: 4.2",
+ "Framework :: Plone :: 4.3",
+ "License :: OSI Approved :: BSD License",
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 2.7",
+ ],
+ keywords='',
+ author='Taito Horiuchi',
+ author_email='taito.horiuchi@gmail.com',
+ url='https://github.com/collective/collective.behavior.salable/',
+ license='BSD',
+ packages=find_packages(exclude=['ez_setup']),
+ namespace_packages=['collective', 'collective.behavior'],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[
+ 'five.grok',
+ 'hexagonit.testing',
+ 'plone.behavior',
+ 'plone.directives.form',
+ 'rwproperty',
+ 'setuptools',
+ ],
+ entry_points="""
+ # -*- Entry points: -*-
+
+ [z3c.autoinclude.plugin]
+ target = plone
+ """,
+)

0 comments on commit c860fdf

Please sign in to comment.