Conjunto de mudanças 6467 no repositório publico


Ignorar:
Timestamp:
09/06/2012 00:28:48 (9 anos atrás)
Autor:
mazza
Mensagem:

teste e refatoracao do armazenamento generico de schemas (boxes)

Localização:
PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis
Arquivos:
4 editados

Legenda:

Não Modificado
Adicionado
Removido
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/browser/boxes.py

    r6465 r6467  
    1818def _build_box(box_schema, number):
    1919
    20     key = _box_key(box_schema, number)
    2120    form_label = getattr(box_schema, 'form_label', None) \
    2221      or u'Edite os valore desta caixa'
     
    2726    class BoxEditForm(form.EditForm, grok.View):
    2827        grok.context(IFolderish)
    29         grok.name('box_%s' % key)
     28        grok.name(_box_name_for_url(box_schema, number))
    3029        label = form_label
    3130        fields = field.Fields(box_schema)
     
    3433            return box_content(self.context, box_schema, number)
    3534       
    36     globals()['BoxEditForm_%s' % key] = BoxEditForm
     35    globals()['BoxEditForm_%s' % _box_key(box_schema, number)] = BoxEditForm
    3736    return BoxEditForm
    3837
     
    5150    return '%s_%s' % (box_schema.__name__, number)
    5251
    53 def _build_n_boxes(box_schema, max_number):
     52def _box_name_for_url(box_schema, number):
     53    return 'box_%s' % _box_key(box_schema, number)
     54
     55def build_n_boxes(box_schema, max_number):
    5456    for number in range(1, max_number+1):
    5557        _build_box(box_schema, number)
    5658
    57 ################################################################
     59################################################################       
    5860from interfaces import ISimpleBox
    59 
     61   
    6062for box_schema in [ISimpleBox]:
    61     _build_n_boxes(box_schema, 10)
     63    build_n_boxes(box_schema, 2)
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/browser/interfaces.py

    r6465 r6467  
    3131
    3232class ISimpleBox(Interface):
    33     title = schema.TextLine(title=u"title", required=True)
    34     subtitle = schema.TextLine(title=u"subtitle", required=True)
    35     text = schema.TextLine(title=u"text", required=True)
     33    title = schema.TextLine(title=u"Título", required=True)
     34    subtitle = schema.TextLine(title=u"Subtítulo", required=True)
     35    text = schema.TextLine(title=u"Texto", required=True)
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/tests/fixtures.py

    r6439 r6467  
    1 from plone.app.testing import PLONE_FIXTURE
    2 from plone.app.testing import PloneSandboxLayer
    3 from plone.app.testing import IntegrationTesting
    4 from plone.app.testing import FunctionalTesting
    5 from plone.app.testing import applyProfile
     1# -*- coding: utf-8 -*-
     2from persistent.dict import PersistentDict
     3from plone.app.testing import PLONE_FIXTURE, PloneSandboxLayer, IntegrationTesting, applyProfile
     4from z3c.form import datamanager
     5from z3c.form.interfaces import IDataManager
     6from zope.component import adapts, provideAdapter
     7from zope.configuration import xmlconfig
     8from zope.interface import implements
     9from zope.schema.interfaces import IField
    610
    7 from zope.configuration import xmlconfig
    811
    912class IlPortalinterlegis(PloneSandboxLayer):
     
    3437                       context=configurationContext)
    3538
     39        #TODO: (fazer essa POG do jeito certo, que não sei qual é)
     40        # tive de repetir isso aqui pois não sei como esse mesmo trecho
     41        # (de browser.boxes) é ativado normalmente, e como reproduzir isso no ambiente de teste
     42        class PersistentDictionaryField(datamanager.DictionaryField):
     43            adapts(PersistentDict, IField)
     44            implements(IDataManager)
     45        provideAdapter(PersistentDictionaryField)
     46        # fim da POG
    3647
    3748    def setUpPloneSite(self, portal):
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/tests/tests.py

    r6440 r6467  
    11# -*- coding: utf-8 -*-
    22import unittest2 as unittest
    3 
    43from Products.CMFCore.utils import getToolByName
    54
    65from fixtures import IL_PORTALINTERLEGIS_INTEGRATION_TESTING
     6from il.portalinterlegis.browser.boxes import _box_name_for_url, box_content
    77from il.portalinterlegis.browser.interfaces import \
    8      IComunidadeLegislativa, IInformacao, ICapacitacao, ITecnologia, IComunicacao
     8     IComunidadeLegislativa, IInformacao, ICapacitacao, ITecnologia, IComunicacao, \
     9     ISimpleBox
    910from splinterbrowser import SplinterBrowser
     11from plone.testing.z2 import Browser
    1012
    11 class TestExample(unittest.TestCase):
     13class TestIntegracao(unittest.TestCase):
    1214
    1315    layer = IL_PORTALINTERLEGIS_INTEGRATION_TESTING
    14    
    1516    def setUp(self):
    1617        self.app = self.layer['app']
     
    3334        # https://github.com/cobrateam/splinter/pull/152
    3435        # for aceito no Splinter
    35         print [li.find_by_tag('a').first.text
    36                 for li in browser.find_by_css('#portal-globalnav li')]
    3736        self.assertEqual([u'O Interlegis',
    3837                          u'Comunidade Legislativa',
     
    5554            self.assertEqual('home', obj.getLayout())
    5655
     56    def browser(self, url=None):
     57        browser = Browser(self.app)
     58        browser.handleErrors = False
     59        if url:
     60            browser.open(url)
     61        return browser
     62
     63    def test_box_content_is_empty_before_visiting_form(self):
     64        self.assertEqual({}, box_content(self.portal, ISimpleBox, 1))
     65
     66    def test_using_box_form_creates_box_content(self):
     67        box_schema = ISimpleBox
     68        num = 1
     69        context = self.portal
     70
     71        url = context.absolute_url() + '/' + _box_name_for_url(box_schema, num)
     72        browser = self.browser(url)
     73        browser.getControl(name='form.widgets.title').value = 'TIT'
     74        browser.getControl(name='form.widgets.subtitle').value = 'SUBTIT'
     75        browser.getControl(name='form.widgets.text').value = 'MY TEXT'
     76        browser.getControl(name='form.buttons.apply').click()
     77       
     78        self.assertEqual({'text': u'MY TEXT', 'subtitle': u'SUBTIT', 'title': u'TIT'},
     79                         box_content(context, box_schema, num))
Note: Veja TracChangeset para ajuda no uso do visualizador de conjunto de mudanças.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.