Changeset 6550 for main/waeup.sirp


Ignore:
Timestamp:
23 Jul 2011, 15:12:52 (13 years ago)
Author:
uli
Message:

Add tests for search function of accesscodes catalog. Test coverage
for the catalog module should now go at least near to 100%.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_catalog.py

    r6548 r6550  
    3535    AccessCode, AccessCodeBatch, invalidate_accesscode, disable_accesscode)
    3636from waeup.sirp.accesscodes.workflow import INITIALIZED, USED, DISABLED
    37 from waeup.sirp.accesscodes.catalog import AccessCodeQueryResultItem
     37from waeup.sirp.accesscodes.catalog import AccessCodeQueryResultItem, search
    3838
    3939class CatalogTestSetup(FunctionalTestCase):
     
    172172class FakeView(object):
    173173    # A view we can use in tests. Provides only the neccessary methods.
     174    flashed = []
    174175    def url(self, context):
    175176        pass
     177    def flash(self, msg):
     178        self.flashed.append(msg)
    176179
    177180class AccessCodeQueryResultItemTests(CatalogTestSetup):
     
    190193        return
    191194
     195class SearchTests(CatalogTestSetup):
     196    # Tests for the search() function
     197
     198    layer = FunctionalLayer
     199
     200    def setUp(self):
     201        super(SearchTests, self).setUp()
     202        self.view = FakeView()
     203        return
     204
     205    def test_search_none(self):
     206        # if we search none we will get it. Also a warning is displayed.
     207        result = search(view=self.view)
     208        self.assertTrue(result is None)
     209        self.assertEqual(self.view.flashed, ['Empty search string.'])
     210        return
     211
     212    def test_search_history(self):
     213        # we can search for history entries
     214        result = search(
     215            query='initialized', # A word that appears in all items' hist
     216            searchtype='history', view=self.view)
     217        self.assertEqual(len(result), 3)
     218        return
     219
     220    def test_search_batch_serial(self):
     221        # we can search for batch serials
     222        result = search(
     223            query=2,
     224            searchtype='batch_serial', view=self.view)
     225        self.assertEqual(len(result), 1)
     226        self.assertEqual(result[0].code, 'APP-1-33333333')
     227        return
     228
     229    def test_search_freestyle(self):
     230        # we can even search for arbitrary fields
     231        result = search(
     232            query='APP-1-11111111',
     233            searchtype='code', view=self.view)
     234        self.assertEqual(len(result), 1)
     235        self.assertEqual(result[0].code, 'APP-1-11111111')
     236        return
Note: See TracChangeset for help on using the changeset viewer.