Changeset 9200 for main/waeup.kofa


Ignore:
Timestamp:
19 Sep 2012, 05:33:38 (12 years ago)
Author:
Henrik Bettermann
Message:

Add tests for exporters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r9197 r9200  
    3737from waeup.kofa.hostels.container import HostelsContainer
    3838from waeup.kofa.hostels.hostel import Hostel, Bed
     39from waeup.kofa.hostels.export import BedExporter, HostelExporter
    3940from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase)
    4041from waeup.kofa.students.student import Student
     
    143144        # Create a bed
    144145        bed = Bed()
    145         bed.bed_id = u'xyz'
     146        bed.bed_id = u'hall_block_room_bed'
    146147        bed.bed_number = 1
    147         bed.bed_type = u'abc'
     148        bed.bed_type = u'a_b_c'
    148149        self.app['hostels'][hostel.hostel_id][bed.bed_id] = bed
    149150
     
    175176        # We can find a certain bed
    176177        cat = queryUtility(ICatalog, name='beds_catalog')
    177         results = cat.searchResults(bed_type=(u'abc', u'abc'))
     178        results = cat.searchResults(bed_type=(u'a_b_c', u'a_b_c'))
    178179        results = [x for x in results] # Turn results generator into list
    179180        assert len(results) == 1
    180         assert results[0] is self.app['hostels']['hall-x']['xyz']
     181        assert results[0] is self.app['hostels']['hall-x']['hall_block_room_bed']
    181182
    182183    def test_search_by_owner(self):
    183184        # We can find a certain bed
    184         myobj = self.app['hostels']['hall-x']['xyz']
     185        myobj = self.app['hostels']['hall-x']['hall_block_room_bed']
    185186        myobj.owner = u'abc'
    186187        notify(grok.ObjectModifiedEvent(myobj))
     
    189190        results = [x for x in results] # Turn results generator into list
    190191        assert len(results) == 1
    191         assert results[0] is self.app['hostels']['hall-x']['xyz']
     192        assert results[0] is self.app['hostels']['hall-x']['hall_block_room_bed']
    192193
    193194class HostelsUITests(HostelsFullSetup):
     
    387388        self.assertTrue('zope.mgr - hostels.browser.HostelsContainerManagePage'
    388389                        ' - hostels - all hostels cleared' in logcontent)
     390
     391class ExportTests(HostelsFullSetup):
     392
     393    layer = FunctionalLayer
     394
     395    def setUp(self):
     396        super(ExportTests, self).setUp()
     397        self.workdir = tempfile.mkdtemp()
     398        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     399        return
     400
     401    def test_export_hostels(self):
     402        exporter = HostelExporter()
     403        exporter.export_all(self.app, self.outfile)
     404        result = open(self.outfile, 'rb').read()
     405        self.assertEqual(
     406            result,
     407            'beds_for_all,beds_for_final,beds_for_fresh,beds_for_pre,'
     408            'beds_for_returning,beds_reserved,blocks_for_female,'
     409            'blocks_for_male,floors_per_block,hostel_id,hostel_name,'
     410            'rooms_per_floor,sort_id,special_handling\r\n,,,,,[],,,1,'
     411            'hall-x,Hall 1,2,10,regular\r\n'
     412            )
     413        return
     414
     415    def test_export_beds(self):
     416        exporter = BedExporter()
     417        exporter.export_all(self.app, self.outfile)
     418        result = open(self.outfile, 'rb').read()
     419        self.assertEqual(
     420            result,
     421            'bed_id,bed_number,bed_type,owner,hall,block,room,bed,'
     422            'special_handling,sex,bt\r\nhall_block_room_bed,1,a_b_c,,'
     423            'hall,block,room,bed,a,b,c\r\n'
     424            )
     425        return
Note: See TracChangeset for help on using the changeset viewer.