Ignore:
Timestamp:
3 Dec 2012, 16:30:10 (12 years ago)
Author:
uli
Message:

Make the student specific parts of StudentsExportFilter? class attributes and provide an implementation for filtered students.

File:
1 edited

Legend:

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

    r9761 r9763  
    4242    def test_get_students_by_session(self):
    4343        # we can filter out students of a certain session
    44         my_filter1 = StudentsExportFilter(session=2012)
     44        my_filter1 = StudentsExportFilter(current_session=2012)
    4545        result = get_students(self.app, stud_filter=my_filter1)
    4646        self.assertEqual(len(list(result)), 1)
    4747
    48         my_filter2 = StudentsExportFilter(session=1964)
     48        my_filter2 = StudentsExportFilter(current_session=1964)
    4949        result = get_students(self.app, stud_filter=my_filter2)
    5050        self.assertEqual(len(list(result)), 0)
     
    5353    def test_get_students_by_level(self):
    5454        # we can filter out students of a certain level
    55         my_filter1 = StudentsExportFilter(level=200)
     55        my_filter1 = StudentsExportFilter(current_level=200)
    5656        result = get_students(self.app, stud_filter=my_filter1)
    5757        self.assertEqual(len(list(result)), 1)
    5858
    59         my_filter2 = StudentsExportFilter(level=300)
     59        my_filter2 = StudentsExportFilter(current_level=300)
    6060        result = get_students(self.app, stud_filter=my_filter2)
    6161        self.assertEqual(len(list(result)), 0)
    6262        return
    6363
     64    def test_get_students_by_deptcode(self):
     65        # we can filter out students of a certain dept.
     66        my_filter1 = StudentsExportFilter(depcode='NA')
     67        result = get_students(self.app, stud_filter=my_filter1)
     68        self.assertEqual(len(list(result)), 1)
     69
     70        my_filter2 = StudentsExportFilter(depcode='NOTEXISTING')
     71        result = get_students(self.app, stud_filter=my_filter2)
     72        self.assertEqual(len(list(result)), 0)
     73        return
     74
     75    def test_get_students_by_faccode(self):
     76        # we can filter out students of a certain faculty.
     77        my_filter1 = StudentsExportFilter(faccode='NA')
     78        result = get_students(self.app, stud_filter=my_filter1)
     79        self.assertEqual(len(list(result)), 1)
     80
     81        my_filter2 = StudentsExportFilter(faccode='NOTEXISTING')
     82        result = get_students(self.app, stud_filter=my_filter2)
     83        self.assertEqual(len(list(result)), 0)
     84        return
     85
     86
    6487class StudentsExporterTest(StudentImportExportSetup):
    6588
    6689    layer = FunctionalLayer
     90
     91    std_csv_entry = (
     92        'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
     93        'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,'
     94        '+234-123-12345#,123,f,A111111,0,,,created'
     95        )
    6796
    6897    def setUp(self):
     
    144173            in result
    145174            )
     175        return
     176
     177    def test_export_filtered(self):
     178        # we can export a filtered set of students (filtered by session/level)
     179        self.setup_student(self.student)
     180        self.app['students'].addStudent(self.student)
     181        notify(grok.ObjectModifiedEvent(self.student))
     182        exporter = StudentsExporter()
     183
     184        exporter.export_filtered(self.app, None, None, filepath=self.outfile)
     185        result1 = open(self.outfile, 'rb').read()
     186        exporter.export_filtered(self.app, 2012, None, filepath=self.outfile)
     187        result2 = open(self.outfile, 'rb').read()
     188        exporter.export_filtered(self.app, None, 200, filepath=self.outfile)
     189        result3 = open(self.outfile, 'rb').read()
     190        exporter.export_filtered(self.app, 2011, None, filepath=self.outfile)
     191        result4 = open(self.outfile, 'rb').read()
     192        exporter.export_filtered(self.app, None, 100, filepath=self.outfile)
     193        result5 = open(self.outfile, 'rb').read()
     194        self.assertTrue(self.std_csv_entry in result1)
     195        self.assertTrue(self.std_csv_entry in result2)
     196        self.assertTrue(self.std_csv_entry in result3)
     197        self.assertTrue(self.std_csv_entry not in result4)
     198        self.assertTrue(self.std_csv_entry not in result5)
     199        return
     200
     201    def test_export_filtered_by_dept(self):
     202        # we can export a set of students filtered by department
     203        self.setup_student(self.student)
     204        self.app['students'].addStudent(self.student)
     205        notify(grok.ObjectModifiedEvent(self.student))
     206        exporter = StudentsExporter()
     207
     208        exporter.export_filtered(self.app, 2012, 200, depcode='NA',
     209                                 filepath=self.outfile)
     210        result1 = open(self.outfile, 'rb').read()
     211        exporter.export_filtered(self.app, 2012, 200, depcode='NODEPT',
     212                                 filepath=self.outfile)
     213        result2 = open(self.outfile, 'rb').read()
     214        self.assertTrue(self.std_csv_entry in result1)
     215        self.assertTrue(self.std_csv_entry not in result2)
     216        return
     217
     218    def test_export_filtered_by_faculty(self):
     219        # we can export a set of students filtered by faculty
     220        self.setup_student(self.student)
     221        self.app['students'].addStudent(self.student)
     222        notify(grok.ObjectModifiedEvent(self.student))
     223        exporter = StudentsExporter()
     224
     225        exporter.export_filtered(
     226            self.app, 2012, 200, faccode='NA', filepath=self.outfile)
     227        result1 = open(self.outfile, 'rb').read()
     228        exporter.export_filtered(self.app, 2012, 200, faccode='NOFAC',
     229                                 filepath=self.outfile)
     230        result2 = open(self.outfile, 'rb').read()
     231        self.assertTrue(self.std_csv_entry in result1)
     232        self.assertTrue(self.std_csv_entry not in result2)
    146233        return
    147234
Note: See TracChangeset for help on using the changeset viewer.