Beispiel #1
0
class TestStringField(ERP5TypeTestCase):
  """Tests string field
  """

  def getTitle(self):
    return "String Field"

  def afterSetUp(self):
    self.field = StringField('test_field')
    self.widget = self.field.widget

  def test_escape_html(self):
    self.field.values['editable'] = 0
    self.assertEquals('&lt;script&gt;', self.field.render("<script>"))

  def test_render_odt(self):
    self.field.values['default'] = 'Hello World! <&> &lt;&mp;&gt;'
    self.assertEquals('Hello World! <&> &lt;&mp;&gt;', self.field.render_odt(as_string=False).text)
    self.assertEquals('Hello World!', self.field.render_odt(value='Hello World!', as_string=False).text)

  def test_render_odg(self):
    self.field.values['default'] = 'Hello World! <&> &lt;&mp;&gt;'
    test_value = self.field.render_odg(as_string=False)\
      .xpath('%s/text()' % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP)[0]
    self.assertEquals('Hello World! <&> &lt;&mp;&gt;', test_value)
    test_value = self.field.render_odg(value='Hello World!', as_string=False)\
      .xpath('%s/text()' % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP)[0]
    self.assertEquals('Hello World!', test_value)

  def test_render_odt_variable(self):
    self.field.values['default'] = 'Hello World! <&> &lt;&mp;&gt;'
    node = self.field.render_odt_variable(as_string=False)
    self.assertEquals(node.get('{%s}value-type' % NSMAP['office']), 'string')
    self.assertEquals(node.text, 'Hello World! <&> &lt;&mp;&gt;')
Beispiel #2
0
class TestStringField(ERP5TypeTestCase):
  """Tests string field
  """

  def getTitle(self):
    return "String Field"

  def afterSetUp(self):
    self.field = StringField('test_field')
    self.widget = self.field.widget

  def test_escape_html(self):
    self.field.values['editable'] = 0
    self.assertEqual('&lt;script&gt;', self.field.render("<script>"))

  def test_render_odt(self):
    self.field.values['default'] = 'Hello World! <&> &lt;&mp;&gt;'
    self.assertEqual('Hello World! <&> &lt;&mp;&gt;', self.field.render_odt(as_string=False).text)
    self.assertEqual('Hello World!', self.field.render_odt(value='Hello World!', as_string=False).text)

  def test_render_odg(self):
    self.field.values['default'] = 'Hello World! <&> &lt;&mp;&gt;'
    test_value = self.field.render_odg(as_string=False)\
      .xpath('%s/text()' % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP)[0]
    self.assertEqual('Hello World! <&> &lt;&mp;&gt;', test_value)
    test_value = self.field.render_odg(value='Hello World!', as_string=False)\
      .xpath('%s/text()' % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP)[0]
    self.assertEqual('Hello World!', test_value)

  def test_render_odt_variable(self):
    self.field.values['default'] = 'Hello World! <&> &lt;&mp;&gt;'
    node = self.field.render_odt_variable(as_string=False)
    self.assertEqual(node.get('{%s}value-type' % NSMAP['office']), 'string')
    self.assertEqual(node.text, 'Hello World! <&> &lt;&mp;&gt;')
Beispiel #3
0
    def afterSetUp(self):
        self.root = self.portal
        self.root.form = ERP5Form('form', 'Form')
        self.root.getProperty = lambda key, d=None: \
          dict(on_memory_field='123').get(key, d)

        form = self.root.form

        def addField(field):
            form._setObject(field.id, field, set_owner=0, suppress_events=1)

        addField(StringField('field'))
        form.field._p_oid = makeDummyOid()
        # method field
        form.field.values['external_validator'] = Method('this_is_a_method')
        # on-memory field (not in zodb)
        addField(StringField('my_on_memory_field'))
        form.my_on_memory_field._p_oid = None
        addField(StringField('my_on_memory_tales_field'))
        form.my_on_memory_tales_field.manage_tales_xmlrpc(
            {'default': 'python: repr(here)'})
        form.my_on_memory_field._p_oid = None
        # proxy field
        addField(ProxyField.ProxyField('proxy_field'))
        form.proxy_field._p_oid = makeDummyOid()
        form.proxy_field.values['form_id'] = 'form'
        form.proxy_field.values['field_id'] = 'field'
        # proxy field with tales
        addField(ProxyField.ProxyField('proxy_field_tales'))
        form.proxy_field_tales._p_oid = makeDummyOid()
        form.proxy_field_tales.tales['form_id'] = TALESMethod('string:form')
        form.proxy_field_tales.tales['field_id'] = TALESMethod('string:field')
        # datetime field (input style is list)
        addField(DateTimeField('datetime_field'))
        form.datetime_field._p_oid = makeDummyOid()
        form.datetime_field._edit(dict(input_style='list'))
        for i in form.datetime_field._get_sub_form().fields.values():
            i._p_oid = makeDummyOid()
Beispiel #4
0
class TestStringField(ERP5TypeTestCase):
    """Tests string field
  """

    def getTitle(self):
        return "String Field"

    def afterSetUp(self):
        self.field = StringField("test_field")
        self.widget = self.field.widget

    def test_escape_html(self):
        self.field.values["editable"] = 0
        self.assertEqual("&lt;script&gt;", self.field.render("<script>"))

    def test_render_odt(self):
        self.field.values["default"] = "Hello World! <&> &lt;&mp;&gt;"
        self.assertEqual("Hello World! <&> &lt;&mp;&gt;", self.field.render_odt(as_string=False).text)
        self.assertEqual("Hello World!", self.field.render_odt(value="Hello World!", as_string=False).text)

    def test_render_odg(self):
        self.field.values["default"] = "Hello World! <&> &lt;&mp;&gt;"
        test_value = self.field.render_odg(as_string=False).xpath(
            "%s/text()" % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP
        )[0]
        self.assertEqual("Hello World! <&> &lt;&mp;&gt;", test_value)
        test_value = self.field.render_odg(value="Hello World!", as_string=False).xpath(
            "%s/text()" % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP
        )[0]
        self.assertEqual("Hello World!", test_value)

    def test_render_odt_variable(self):
        self.field.values["default"] = "Hello World! <&> &lt;&mp;&gt;"
        node = self.field.render_odt_variable(as_string=False)
        self.assertEqual(node.get("{%s}value-type" % NSMAP["office"]), "string")
        self.assertEqual(node.text, "Hello World! <&> &lt;&mp;&gt;")
Beispiel #5
0
 def afterSetUp(self):
     self.field = StringField("test_field")
     self.widget = self.field.widget
Beispiel #6
0
 def afterSetUp(self):
     self.field = StringField('test_field')
     self.widget = self.field.widget