source: main/kofacustom.pcn/trunk/src/kofacustom/pcn/applicants/tests/test_browser.py @ 12234

Last change on this file since 12234 was 12234, checked in by Henrik Bettermann, 10 years ago

Repair package. Hopefully we'll never need this package.

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1## $Id: test_browser.py 12234 2014-12-14 21:48:41Z henrik $
2##
3## Copyright (C) 2013 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Test the applicant-related UI components.
20"""
21import os
22import datetime
23from zope.component import createObject, getUtility
24from zope.catalog.interfaces import ICatalog
25from zope.intid.interfaces import IIntIds
26from kofacustom.pcn.testing import FunctionalLayer
27from waeup.kofa.schoolgrades import ResultEntry
28from waeup.kofa.utils.utils import KofaUtils
29from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
30from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
31from kofacustom.pcn.applicants.export import CustomApplicantExporter
32from kofacustom.pcn.applicants.batching import CustomApplicantProcessor
33
34class CustomApplicantUITests(ApplicantsFullSetup):
35    # Tests for uploading/browsing the passport image of appplicants
36
37    layer = FunctionalLayer
38
39class ApplicantExporterTest(ApplicantImportExportSetup):
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(ApplicantExporterTest, self).setUp()
45        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
46        self.cat = getUtility(ICatalog, name='applicants_catalog')
47        self.intids = getUtility(IIntIds)
48        return
49
50    def setup_applicant(self, applicant):
51        # set predictable values for `applicant`
52        applicant.reg_number = u'123456'
53        applicant.applicant_id = u'dp2011_654321'
54        applicant.firstname = u'Anna'
55        applicant.lastname = u'Tester'
56        applicant.middlename = u'M.'
57        applicant.date_of_birth = datetime.date(1981, 2, 4)
58        applicant.sex = 'f'
59        applicant.email = 'anna@sample.com'
60        applicant.phone = u'+234-123-12345'
61        applicant.course1 = self.certificate
62        applicant.course2 = self.certificate
63        applicant.course_admitted = self.certificate
64        applicant.notice = u'Some notice\nin lines.'
65        applicant.password = 'any password'
66        result_entry = ResultEntry(
67            KofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
68            KofaUtils.EXAM_GRADES[0][0]
69            )
70        applicant.school_grades = [
71            result_entry]
72        return applicant
73
74    def test_export_reimport_all(self):
75        # we can export all applicants in a portal
76        # set values we can expect in export file
77        self.applicant = self.setup_applicant(self.applicant)
78        exporter = CustomApplicantExporter()
79        exporter.export_all(self.app, self.outfile)
80        result = open(self.outfile, 'rb').read()
81        self.assertTrue(
82            'applicant_id,application_date,application_number,course1,course2,'
83            'course_admitted,date_of_birth,display_fullname,email,firstname,'
84            'history,lastname,locked,middlename,notice,password,phone,'
85            'reg_number,sex,special_application,state,'
86            'student_id,suspended,container_code\r\n'
87            'dp2011_654321,,654321,CERT1,CERT1,CERT1,1981-02-04#,'
88            'Anna M. Tester,anna@sample.com,Anna,'
89            in result)
90        self.assertTrue(
91            'Application initialized by system\'],'
92            'Tester,0,M.,"Some notice\nin lines.",any password,'
93            '+234-123-12345#,123456,f,,initialized,,0,dp2011\r\n'
94            in result)
95        # We can import the same file if we ignore some columns.
96        # Since the applicants_catalog hasn't been notified, the same
97        # record with same reg_number can be imported twice.
98        processor = CustomApplicantProcessor()
99        result = processor.doImport(
100            self.outfile,
101            ['ignore_applicant_id','application_date',
102            'ignore_application_number','course1','course2',
103            'course_admitted','date_of_birth',
104            'ignore_display_fullname','email','firstname',
105            'ignore_history','lastname','locked','middlename',
106            'notice','password','phone',
107            'reg_number','sex','special_application','state',
108            'student_id','suspended','container_code'],
109            mode='create')
110        num_succ, num_fail, finished_path, failed_path = result
111        #content = open(failed_path).read()
112
113        self.assertEqual(num_succ,1)
114        self.assertEqual(num_fail,0)
115        return
Note: See TracBrowser for help on using the repository browser.