Ignore:
Timestamp:
3 Mar 2012, 03:50:29 (13 years ago)
Author:
uli
Message:

Add exporter for certcourses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_export.py

    r7753 r7756  
    1212from waeup.sirp.university.export import (
    1313    FacultyExporter, DepartmentExporter, CourseExporter,
    14     CertificateExporter,
     14    CertificateExporter, CertificateCourseExporter,
    1515    )
    1616
     
    391391            )
    392392        return
     393
     394class CertificateCourseExporterTest(unittest.TestCase):
     395    # Tests for CertificateCourseExporter
     396
     397    layer = SIRPUnitTestLayer
     398
     399    def setUp(self):
     400        self.workdir = tempfile.mkdtemp()
     401        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     402        # create some departments and courses in a fake site
     403        container = FacultiesContainer()
     404        self.site = {'faculties':container}
     405        self.fac = Faculty('Faculty of Cheese', 'faculty', 'F1')
     406        container.addFaculty(self.fac)
     407        self.dept1 = Department('Department of Cheddar', 'department', 'D1')
     408        self.dept2 = Department('Institue of Gouda', 'institute', 'D2')
     409        self.fac.addDepartment(self.dept1)
     410        self.fac.addDepartment(self.dept2)
     411        self.course1 = Course('Cheese Basics', 'C1')
     412        self.course2 = Course('Advanced Cheese Making', 'C2')
     413        self.course3 = Course('Selling Cheese', 'C3')
     414        self.dept1.courses.addCourse(self.course1)
     415        self.dept1.courses.addCourse(self.course2)
     416        self.dept2.courses.addCourse(self.course3)
     417        self.cert1 = Certificate(
     418            'CERT1', 'Master of Cheese', study_mode=u'ct_ft', start_level=100,
     419            end_level=300, application_category='basic')
     420        self.cert2 = Certificate(
     421            'CERT2', 'Master of Cheddar', study_mode='ct_ft', start_level=400,
     422            end_level=700, application_category='cest')
     423        self.cert3 = Certificate(
     424            'CERT3', 'Cert. of Rubbish', study_mode='dp_pt', start_level=100,
     425            end_level=200, application_category='no')
     426        self.dept1.certificates.addCertificate(self.cert1)
     427        self.dept1.certificates.addCertificate(self.cert2)
     428        self.dept2.certificates.addCertificate(self.cert3)
     429        self.cert1.addCourseRef(self.course1, 100, True)
     430        self.cert1.addCourseRef(self.course2, 400, False)
     431        self.cert3.addCourseRef(self.course3, 100, False)
     432        self.certcourse1 = self.cert1['C1_100']
     433        self.certcourse2 = self.cert1['C2_400']
     434        self.certcourse3 = self.cert3['C3_100']
     435        return
     436
     437    def tearDown(self):
     438        shutil.rmtree(self.workdir)
     439        return
     440
     441    def test_ifaces(self):
     442        # make sure we fullfill interface contracts
     443        obj = CertificateCourseExporter()
     444        verifyObject(ICSVExporter, obj)
     445        verifyClass(ICSVExporter, CertificateCourseExporter)
     446        return
     447
     448    def test_get_as_utility(self):
     449        # we can get a certificate exporter as utility
     450        result = queryUtility(ICSVExporter, name="certificate_courses")
     451        self.assertTrue(result is not None)
     452        return
     453
     454    def test_export(self):
     455        # we can export an iterable of certificates
     456        exporter = CertificateCourseExporter()
     457        exporter.export([self.certcourse1], self.outfile)
     458        result = open(self.outfile, 'rb').read()
     459        self.assertEqual(
     460            result,
     461            'course,faculty_code,department_code,certificate_code,level,mandatory\r\n'
     462            'C1,F1,D1,CERT1,100,1\r\n'
     463            )
     464        return
     465
     466    def test_export_to_string(self):
     467        # we can export an iterable of certificates to a string.
     468        exporter = CertificateCourseExporter()
     469        result = exporter.export(
     470            [self.certcourse1, self.certcourse2], filepath=None)
     471        self.assertEqual(
     472            result,
     473            'course,faculty_code,department_code,certificate_code,level,mandatory\r\n'
     474            'C1,F1,D1,CERT1,100,1\r\n'
     475            'C2,F1,D1,CERT1,400,0\r\n'
     476            )
     477        return
     478
     479    def test_export_all(self):
     480        # we can export all certificates in a site
     481        exporter = CertificateCourseExporter()
     482        exporter.export_all(self.site, self.outfile)
     483        result = open(self.outfile, 'rb').read()
     484        self.assertEqual(
     485            result,
     486            'course,faculty_code,department_code,certificate_code,level,mandatory\r\n'
     487            'C1,F1,D1,CERT1,100,1\r\n'
     488            'C2,F1,D1,CERT1,400,0\r\n'
     489            'C3,F1,D2,CERT3,100,0\r\n'
     490            )
     491        return
     492
     493    def test_export_all_to_string(self):
     494        # we can export all certificates in a site to a string
     495        exporter = CertificateCourseExporter()
     496        result = exporter.export_all(self.site, filepath=None)
     497        self.assertEqual(
     498            result,
     499            'course,faculty_code,department_code,certificate_code,level,mandatory\r\n'
     500            'C1,F1,D1,CERT1,100,1\r\n'
     501            'C2,F1,D1,CERT1,400,0\r\n'
     502            'C3,F1,D2,CERT3,100,0\r\n'
     503            )
     504        return
Note: See TracChangeset for help on using the changeset viewer.