示例#1
0
 def afterSetUp(self):
     self.field = ListField("test_field")
     self.widget = self.field.widget
     self.createCategories()
     self.tic()
示例#2
0
class TestListField(ERP5TypeTestCase):
    """Tests List field
  """

    def getTitle(self):
        return "List Field"

    def getBusinessTemplateList(self):
        """
    Tuple of Business Templates we need to install
    """
        return ("erp5_core_proxy_field_legacy", "erp5_base")

    def afterSetUp(self):
        self.field = ListField("test_field")
        self.widget = self.field.widget
        self.createCategories()
        self.tic()

    def createCategories(self):
        """Create some categories into gender
    """
        category_tool = self.portal.portal_categories
        if len(category_tool.gender.contentValues()) == 0:
            category_tool.gender.newContent(portal_type="Category", id="male", title="Male", int_index=1)
            category_tool.gender.newContent(portal_type="Category", id="female", title="Female", int_index=2)

    def test_render_odt(self):
        items = [("My first Line", "1"), ("My Second Line", "2")]
        self.field.values["items"] = items
        self.field.values["default"] = "2"
        element = self.field.render_odt(as_string=False)
        self.assertEqual("{%(text)s}p" % NSMAP, element.tag)
        self.assertEqual("My Second Line", element.text)

        # values not in items are displayed with ???
        self.field.values["default"] = "3"
        element = self.field.render_odt(as_string=False)
        self.assertEqual("??? (3)", element.text)

    def test_listField_value_order(self):
        """This test check the list field value order
    """
        # create a form with a list_field that use gender category
        portal_skins = self.getSkinsTool()
        skin_folder = portal_skins._getOb("custom")
        skin_folder.manage_addProduct["ERP5Form"].addERP5Form("Base_viewTestFieldValueOrder", "View")
        form = skin_folder._getOb("Base_viewTestFieldValueOrder", None)

        # The field is a proxyfield on Base_viewFieldLibrary.my_category that
        # category should be sort on int_index and translated_id
        form.manage_addField("my_gender", "Test List Field", "ProxyField")
        field = getattr(form, "my_gender")
        field.manage_edit_xmlrpc(dict(form_id="Base_viewFieldLibrary", field_id="my_category"))

        category_item_list = field.get_value("items")
        self.assertEqual(category_item_list, [["", ""], ["Male", "male"], ["Female", "female"]])

        # try on a person to select on gender and check if the result is the same
        person_module = self.portal.getDefaultModule("Person")
        person = person_module.newContent(portal_type="Person")
        person.setGender("female")
        self.assertEqual(person.getGender(), "female")
        self.assertEqual(
            person.Person_view.my_gender.get_value("items"), [["", ""], ["Male", "male"], ["Female", "female"]]
        )
示例#3
0
文件: testFields.py 项目: poses/erp5
class TestListField(ERP5TypeTestCase):
  """Tests List field
  """

  def getTitle(self):
    return "List Field"

  def getBusinessTemplateList(self):
    """
    Tuple of Business Templates we need to install
    """
    return (
      'erp5_core_proxy_field_legacy',
      'erp5_base',
    )

  def afterSetUp(self):
    self.field = ListField('test_field')
    self.widget = self.field.widget
    self.createCategories()
    self.tic()

  def createCategories(self):
    """Create some categories into gender
    """
    category_tool = self.portal.portal_categories
    if len(category_tool.gender.contentValues()) == 0 :
      category_tool.gender.newContent(portal_type='Category',
                                      id='male',
                                      title='Male',
                                      int_index=1)
      category_tool.gender.newContent(portal_type='Category',
                                      id='female',
                                      title='Female',
                                      int_index=2)

  def test_render_odt(self):
    items = [('My first Line', '1'), ('My Second Line', '2')]
    self.field.values['items'] = items
    self.field.values['default'] = '2'
    element = self.field.render_odt(as_string=False)
    self.assertEquals('{%(text)s}p' % NSMAP, element.tag)
    self.assertEquals('My Second Line', element.text)

    # values not in items are displayed with ???
    self.field.values['default'] = '3'
    element = self.field.render_odt(as_string=False)
    self.assertEquals('??? (3)', element.text)


  def test_listField_value_order(self):
    '''This test check the list field value order
    '''
    # create a form with a list_field that use gender category
    portal_skins = self.getSkinsTool()
    skin_folder = portal_skins._getOb('custom')
    skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
        'Base_viewTestFieldValueOrder',
        'View')
    form = skin_folder._getOb('Base_viewTestFieldValueOrder', None)

    # The field is a proxyfield on Base_viewFieldLibrary.my_category that
    # category should be sort on int_index and translated_id
    form.manage_addField('my_gender', 'Test List Field',
        'ProxyField')
    field = getattr(form, 'my_gender')
    field.manage_edit_xmlrpc(dict(
    form_id='Base_viewFieldLibrary', field_id='my_category'))

    category_item_list = field.get_value('items')
    self.assertEquals(category_item_list,
        [['', ''], ['Male', 'male'], ['Female', 'female']])

    # try on a person to select on gender and check if the result is the same
    person_module = self.portal.getDefaultModule('Person')
    person = person_module.newContent(portal_type='Person')
    person.setGender('female')
    self.assertEquals(person.getGender(), 'female')
    self.assertEquals(person.Person_view.my_gender.get_value('items'),
        [['', ''], ['Male', 'male'], ['Female', 'female']])
示例#4
0
 def afterSetUp(self):
     self.field = ListField('test_field')
     self.widget = self.field.widget
     self.createCategories()
     self.tic()
示例#5
0
class TestListField(ERP5TypeTestCase):
    """Tests List field
  """
    def getTitle(self):
        return "List Field"

    def getBusinessTemplateList(self):
        """
    Tuple of Business Templates we need to install
    """
        return (
            'erp5_core_proxy_field_legacy',
            'erp5_base',
        )

    def afterSetUp(self):
        self.field = ListField('test_field')
        self.widget = self.field.widget
        self.createCategories()
        self.tic()

    def createCategories(self):
        """Create some categories into gender
    """
        category_tool = self.portal.portal_categories
        if len(category_tool.gender.contentValues()) == 0:
            category_tool.gender.newContent(portal_type='Category',
                                            id='male',
                                            title='Male',
                                            int_index=1)
            category_tool.gender.newContent(portal_type='Category',
                                            id='female',
                                            title='Female',
                                            int_index=2)

    def test_render_odt(self):
        items = [('My first Line', '1'), ('My Second Line', '2')]
        self.field.values['items'] = items
        self.field.values['default'] = '2'
        element = self.field.render_odt(as_string=False)
        self.assertEqual('{%(text)s}p' % NSMAP, element.tag)
        self.assertEqual('My Second Line', element.text)

        # values not in items are displayed with ???
        self.field.values['default'] = '3'
        element = self.field.render_odt(as_string=False)
        self.assertEqual('??? (3)', element.text)

    def test_listField_value_order(self):
        '''This test check the list field value order
    '''
        # create a form with a list_field that use gender category
        portal_skins = self.getSkinsTool()
        skin_folder = portal_skins._getOb('custom')
        skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
            'Base_viewTestFieldValueOrder', 'View')
        form = skin_folder._getOb('Base_viewTestFieldValueOrder', None)

        # The field is a proxyfield on Base_viewFieldLibrary.my_category that
        # category should be sort on int_index and translated_id
        form.manage_addField('my_gender', 'Test List Field', 'ProxyField')
        field = getattr(form, 'my_gender')
        field.manage_edit_xmlrpc(
            dict(form_id='Base_viewFieldLibrary', field_id='my_category'))

        category_item_list = field.get_value('items')
        self.assertEqual(category_item_list,
                         [['', ''], ['Male', 'male'], ['Female', 'female']])

        # try on a person to select on gender and check if the result is the same
        person_module = self.portal.getDefaultModule('Person')
        person = person_module.newContent(portal_type='Person')
        person.setGender('female')
        self.assertEqual(person.getGender(), 'female')
        self.assertEqual(person.Person_view.my_gender.get_value('items'),
                         [['', ''], ['Male', 'male'], ['Female', 'female']])
示例#6
0
 def afterSetUp(self):
   self.field = ListField('test_field')
   self.widget = self.field.widget
   self.createCategories()
   transaction.commit()
   self.tic()