Modify

Opened 12 years ago

Closed 11 years ago

#10283 closed defect (worksforme)

Tests fail on Trac 1.0-beta1

Reported by: ejucovy Owned by: osimons
Priority: normal Component: CustomFieldAdminPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description

Running customfieldadmin's setup.py test against Trac 1.0-beta1 results in several test failures. They seem to be caused by a change in the return value of Trac's TicketSystem.get_custom_fields() API. The dicts returned by that method now include a key "custom": True for custom fields, which is not expected by the tests in CustomFieldApiTestCase.

The attached patch causes the tests to pass by adding "custom": True to the expected return value in those tests.

Attachments (0)

Change History (4)

comment:1 Changed 12 years ago by ejucovy

Hmm, attaching a patch doesn't seem to work -- here's the contents of the patch, produced by svn diff:

  • customfieldadmin/tests/api.py

     
    3838            self.cf_api.create_custom_field(cfield)
    3939        self.assertEquals(self.cf_api.get_custom_fields(),
    4040                    [{'name': u'one', 'format': 'plain', 'value': '',
    41                       'label': u'One', 'type': u'text', 'order': 1},
     41                      'label': u'One', 'type': u'text', 'order': 1,
     42                      'custom': True},
    4243                     {'name': u'two', 'format': 'plain', 'value': '',
    43                       'label': u'Two', 'type': u'text', 'order': 2},
     44                      'label': u'Two', 'type': u'text', 'order': 2,
     45                      'custom': True},
    4446                     {'name': u'three', 'format': 'plain', 'value': '',
    45                       'label': u'Three', 'type': u'text', 'order': 3}])
     47                      'label': u'Three', 'type': u'text', 'order': 3,
     48                      'custom': True}])
    4649
    4750    def test_update(self):
    4851        cfield = {'name': 'foo', 'type': 'text'}
    4952        self.cf_api.create_custom_field(cfield)
    50         self.assertEquals(cfield, {'name': u'foo', 'format': 'plain',
     53        self.assertEquals(cfield, {'name': u'foo', 'format': 'plain', 'custom': True,
    5154                'value': '', 'label': u'Foo', 'type': u'text', 'order': 1})
    5255        cfield['label'] = 'Answer'
    5356        cfield['value'] = '42'
    5457        self.cf_api.update_custom_field(cfield=cfield)
    55         self.assertEquals(cfield, {'name': u'foo', 'format': 'plain',
     58        self.assertEquals(cfield, {'name': u'foo', 'format': 'plain', 'custom': True,
    5659                'value': '42', 'label': u'Answer', 'type': u'text', 'order': 1})
    5760
    5861    def test_update_non_existing(self):
     
    8487        # Note: Should also reorder higher-ordered items
    8588        self.assertEquals(self.cf_api.get_custom_fields(),
    8689                    [{'name': u'one', 'format': 'plain', 'value': '',
    87                       'label': u'One', 'type': u'text', 'order': 1},
     90                      'label': u'One', 'type': u'text', 'order': 1,
     91                      'custom': True},
    8892                     {'name': u'three', 'format': 'plain', 'value': '',
    89                       'label': u'Three', 'type': u'text', 'order': 2}])
     93                      'label': u'Three', 'type': u'text', 'order': 2,
     94                      'custom': True}])
    9095        self.assertEquals(None,
    9196                self.cf_api.get_custom_fields(cfield={'name': 'two'}))

comment:2 Changed 12 years ago by osimons

Huh.

Why we have changed TicketSystem(self.env).get_custom_fields() to include the truly useless 'custom': True information I don't know. It makes no sense and just adds overhead IMHO - the API call already requests the custom fields, and I cannot see the point of adding some sort of additional marker saying the field is a custom field??

Ideally I'd like to see this fixed in Trac, but if not I can also strip it at the receiving end so that the new working patch would look something like this:

  • 0.11/customfieldadmin/api.py

    a b class CustomFields(Component): 
    7373        """ Returns the custom fields from TicketSystem component.
    7474        Use a cfdict with 'name' key set to find a specific custom field only.
    7575        """
     76        def _get_custom_fields():
     77            for item in TicketSystem(self.env).get_custom_fields():
     78                # Remove the superfluous `'custom': True` item from field dict
     79                item.pop('custom', None)
     80                yield item
    7681        if not cfield:    # return full list
    77             return TicketSystem(self.env).get_custom_fields()
     82            return list(_get_custom_fields())
    7883        else:                  # only return specific item with cfname
    79             for item in TicketSystem(self.env).get_custom_fields():
     84            for item in _get_custom_fields():
    8085                if item['name'] == cfield['name']:
    8186                    return item
    8287            return None        # item not found

comment:3 Changed 12 years ago by Ryan J Ollos

It looks like the change was made in [t 11330], moving the dictionary key from the fields method to the custom_fields method.

comment:4 Changed 11 years ago by Steffen Hoffmann

Resolution: worksforme
Status: newclosed

This is the test result running Trac 1.0.1 backed by SQLite (PostgreSQL8.4 and PostgreSQL9.1 successfully tested as well):

(trac-1.0_pg)hasienda@debian6.0:th_devel/customfieldadminplugin_build$ python ./setup.py test
running test
running egg_info
creating TracCustomFieldAdmin.egg-info
writing requirements to TracCustomFieldAdmin.egg-info/requires.txt
writing TracCustomFieldAdmin.egg-info/PKG-INFO
writing top-level names to TracCustomFieldAdmin.egg-info/top_level.txt
writing dependency_links to TracCustomFieldAdmin.egg-info/dependency_links.txt
writing entry points to TracCustomFieldAdmin.egg-info/entry_points.txt
writing manifest file 'TracCustomFieldAdmin.egg-info/SOURCES.txt'
reading manifest file 'TracCustomFieldAdmin.egg-info/SOURCES.txt'
writing manifest file 'TracCustomFieldAdmin.egg-info/SOURCES.txt'
running build_ext
test_create (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_delete (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_delete_unknown_options (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_not_delete_unknown_options_for_modify (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_systeminfo (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_update (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_update_non_existing (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_update_non_existing_no_name (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_update_textarea (customfieldadmin.tests.api.CustomFieldApiTestCase) ... ok
test_translation_function (customfieldadmin.tests.api.CustomFieldL10NTestCase) ... ok
test_translation_function_tag (customfieldadmin.tests.api.CustomFieldL10NTestCase) ... ok
test_add_optional_select (customfieldadmin.tests.admin.CustomFieldAdminPageTestCase) ... ok
test_apply_optional_select (customfieldadmin.tests.admin.CustomFieldAdminPageTestCase) ... ok
test_create (customfieldadmin.tests.admin.CustomFieldAdminPageTestCase) ... ok

----------------------------------------------------------------------
Ran 14 tests in 0.301s

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain osimons.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.