Ignore:
Timestamp:
25 Nov 2014, 18:44:01 (10 years ago)
Author:
uli
Message:

Merge changes from uli-payments back into trunk.

Location:
main/waeup.ikoba/trunk
Files:
1 deleted
8 edited
8 copied

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk

  • main/waeup.ikoba/trunk/src/waeup/ikoba

  • main/waeup.ikoba/trunk/src/waeup/ikoba/ftesting.zcml

    r11949 r12060  
    1414  <ikoba:datacenter
    1515      path="../../../parts/test/datacenter" />
     16
     17  <!-- Where can the Paypal config be found? -->
     18  <ikoba:paypalconf
     19      path="../../../etc/paypal-testing.conf" />
    1620
    1721  <!-- Typical functional testing security setup -->
  • main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py

    r12032 r12060  
    11371137        )
    11381138
     1139
     1140class IPayPalConfig(Interface):
     1141    path = Path(
     1142        title = u'Path',
     1143        description = u"Path to config file for PayPal REST API.",
     1144        required = True,
     1145        )
     1146
     1147
    11391148#
    11401149# Asynchronous job handling and related
  • main/waeup.ikoba/trunk/src/waeup/ikoba/meta.zcml

    r11949 r12060  
    1717      />
    1818
     19  <meta:directive
     20      namespace="http://namespaces.waeup.org/ikoba"
     21      name="paypalconf"
     22      schema=".zcml.IPayPalConfig"
     23      handler=".zcml.paypal_conf"
     24      />
    1925
    2026</configure>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/tests/test_utils.py

    r11997 r12060  
    2929
    3030    def setUp(self):
    31         self.max_pmem = psutil.phymem_usage().total
    3231        self.max_vmem = psutil.virtual_memory().total
    3332        self.max_smem = psutil.swap_memory().total
     
    124123        utils.SYSTEM_MAX_LOAD['virt-mem'] = -(sys.maxint)  # negative int
    125124        assert utils.expensive_actions_allowed() == False
    126 
    127     def test_expensive_actions_allowed_physmem_none(self):
    128         # unset physmem maximum values make KofUtils ignore physmem values
    129         utils = self.get_cleared_util()
    130         utils.SYSTEM_MAX_LOAD['phys-mem'] = None
    131         assert utils.expensive_actions_allowed() == True
    132         # even not-set values won't block us
    133         del utils.SYSTEM_MAX_LOAD['phys-mem']
    134         assert utils.expensive_actions_allowed() == True
    135 
    136     @unittest.skipIf(
    137         psutil.phymem_usage().percent >= 99.99,
    138         reason="System physmem use over 99%. Cannot set higher allowed value.")
    139     def test_expensive_actions_allowed_physmem_ok(self):
    140         # We can react to high physmem values
    141         max_mem = psutil.phymem_usage().total
    142         utils = self.get_cleared_util()
    143         utils.SYSTEM_MAX_LOAD['phys-mem'] = 99.99          # positive float
    144         assert utils.expensive_actions_allowed() == True
    145         utils.SYSTEM_MAX_LOAD['phys-mem'] = -0.01          # negative float
    146         assert utils.expensive_actions_allowed() == True
    147         utils.SYSTEM_MAX_LOAD['phys-mem'] = max_mem        # positive int
    148         assert utils.expensive_actions_allowed() == True
    149         utils.SYSTEM_MAX_LOAD['phys-mem'] = -1             # negative int
    150         assert utils.expensive_actions_allowed() == True
    151 
    152     @unittest.skipIf(
    153         not psutil.phymem_usage().percent,
    154         reason="Can test physmem behavior only if actually using some")
    155     def test_expensive_actions_allowed_physmem_too_much(self):
    156         # We can react if too much physmem is used
    157         max_mem = psutil.phymem_usage().total
    158         utils = self.get_cleared_util()
    159         utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0            # positive float
    160         assert utils.expensive_actions_allowed() == False
    161         utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0         # negative float
    162         assert utils.expensive_actions_allowed() == False
    163         utils.SYSTEM_MAX_LOAD['phys-mem'] = 0              # positive int
    164         assert utils.expensive_actions_allowed() == False
    165         utils.SYSTEM_MAX_LOAD['phys-mem'] = -(max_mem)     # negative int
    166         assert utils.expensive_actions_allowed() == False
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/utils.py

    r12053 r12060  
    125125    #: value. `cpu-load`, of course, accepts float values only.
    126126    #: `swap-mem` = Swap Memory, `virt-mem` = Virtual Memory,
    127     #: `phys-mem` = Physical Memory, `cpu-load` = CPU load in percent.
     127    #: `cpu-load` = CPU load in percent.
    128128    SYSTEM_MAX_LOAD = {
    129129        'swap-mem': None,
    130130        'virt-mem': None,
    131         'phys-mem': None,
    132131        'cpu-load': 100.0,
    133132        }
     
    247246            ('swap-mem', psutil.swap_memory),
    248247            ('virt-mem', psutil.virtual_memory),
    249             ('phys-mem', psutil.phymem_usage),
    250248            ):
    251249            max_val = max_values.get(key, None)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/zcml.py

    r11949 r12060  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import os
    1819from zope.component.zcml import handler
    19 from waeup.ikoba.interfaces import IDataCenterConfig
     20from zope.configuration.exceptions import ConfigurationError
     21from waeup.ikoba.interfaces import IDataCenterConfig, IPayPalConfig
     22from waeup.ikoba.payments.paypal import configure_sdk
     23
    2024
    2125def data_center_conf(context, path):
     
    4448    """
    4549    context.action(
    46         discriminator = ('utility', IDataCenterConfig, ''),
    47         callable = handler,
    48         args = ('registerUtility',
    49                 {'path':path}, IDataCenterConfig, '')
     50        discriminator=('utility', IDataCenterConfig, ''),
     51        callable=handler,
     52        args=('registerUtility',
     53              {'path': path}, IDataCenterConfig, '')
    5054        )
     55
     56
     57def paypal_handler(path):
     58    """ZCML handler that registers paypal configuration.
     59
     60    We expect paypal credentials written down in a config file. The
     61    path to this config file can be set with the ZCML `paypalconf`
     62    directive, which is handled here and looks like this::
     63
     64      <ikoba:paypalconf path='/some/path/to/paypal.conf' />
     65
     66    This handler requires the given path to exist and to be a file.
     67
     68    If the file exists and is readable, a dict with ``path`` and other
     69    values read from the configuration file is registered as a global
     70    unnamed utility for the `IPayPalConfig` interface.
     71
     72    See :func:`waeup.ikoba.payments.paypal.configure_sdk for details
     73    of the set dict.
     74    """
     75    if not os.path.exists(path):
     76        raise ConfigurationError("No such file: %s" % path)
     77    if not os.path.isfile(path):
     78        raise ConfigurationError("Not a regular file: %s" % path)
     79    config_dict = configure_sdk(path)
     80    return handler(
     81        'registerUtility', config_dict, IPayPalConfig, '')
     82
     83
     84def paypal_conf(context, path):
     85    """Handler for ZCML paypalconf directive.
     86
     87    This handler registers the `paypal_handler` above to perform the
     88    real configuration action.
     89    """
     90    context.action(
     91        discriminator=('utility', IPayPalConfig, ''),
     92        callable=paypal_handler,
     93        args=(path, )
     94        )
Note: See TracChangeset for help on using the changeset viewer.