Changeset 7731 for main/waeup.sirp/trunk/src
- Timestamp:
- 29 Feb 2012, 18:33:41 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_export.py
r7727 r7731 7 7 from waeup.sirp.interfaces import ICSVExporter 8 8 from waeup.sirp.testing import SIRPUnitTestLayer 9 from waeup.sirp.university import FacultiesContainer, Faculty 10 from waeup.sirp.university.export import FacultyExporter 9 from waeup.sirp.university import FacultiesContainer, Faculty, Department 10 from waeup.sirp.university.export import FacultyExporter, DepartmentExporter 11 11 12 12 class FacultyExporterTest(unittest.TestCase): … … 32 32 def test_get_as_utility(self): 33 33 # we can get a faculty exporter as utility 34 result = queryUtility(ICSVExporter, name=" Faculty Exporter")34 result = queryUtility(ICSVExporter, name="faculties") 35 35 self.assertTrue(result is not None) 36 36 return 37 37 38 38 def test_export(self): 39 # we can export single faculties (for what it's worth)39 # we can export a set of faculties 40 40 fac = Faculty('Faculty of Cheese', 'faculty', 'F1') 41 41 exporter = FacultyExporter() 42 exporter.export( fac, self.outfile)42 exporter.export([fac], self.outfile) 43 43 result = open(self.outfile, 'rb').read() 44 44 self.assertEqual( … … 50 50 51 51 def test_export_to_string(self): 52 # we can export singlefaculties to a string.52 # we can export a set of faculties to a string. 53 53 fac = Faculty('Faculty of Cheese', 'faculty', 'F1') 54 54 exporter = FacultyExporter() 55 result = exporter.export( fac, filepath=None)55 result = exporter.export([fac], filepath=None) 56 56 self.assertEqual( 57 57 result, … … 97 97 ) 98 98 return 99 100 class DepartmentExporterTest(unittest.TestCase): 101 # Tests for DepartmentExporter 102 103 layer = SIRPUnitTestLayer 104 105 def setUp(self): 106 self.workdir = tempfile.mkdtemp() 107 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 108 # create some departments in a fake site 109 container = FacultiesContainer() 110 self.site = {'faculties':container} 111 self.fac1 = Faculty('Faculty of Cheese', 'faculty', 'F1') 112 self.fac2 = Faculty('Centre of Onion', 'centre', 'F2') 113 container.addFaculty(self.fac1) 114 container.addFaculty(self.fac2) 115 self.dept1 = Department('Department of Cheddar', 'department', 'D1') 116 self.dept2 = Department('Institue of Gouda', 'institute', 'D2') 117 self.dept3 = Department('Department of Rings', 'department', 'D3') 118 self.fac1.addDepartment(self.dept1) 119 self.fac1.addDepartment(self.dept2) 120 self.fac2.addDepartment(self.dept3) 121 return 122 123 def tearDown(self): 124 shutil.rmtree(self.workdir) 125 return 126 127 def test_ifaces(self): 128 # make sure we fullfill interface contracts 129 obj = DepartmentExporter() 130 verifyObject(ICSVExporter, obj) 131 verifyClass(ICSVExporter, DepartmentExporter) 132 return 133 134 def test_get_as_utility(self): 135 # we can get a faculty exporter as utility 136 result = queryUtility(ICSVExporter, name="departments") 137 self.assertTrue(result is not None) 138 return 139 140 def test_export(self): 141 # we can export an iterable of departments 142 exporter = DepartmentExporter() 143 exporter.export([self.dept1], self.outfile) 144 result = open(self.outfile, 'rb').read() 145 self.assertEqual( 146 result, 147 'code,faculty,title,title_prefix\r\n' 148 'D1,F1,Department of Cheddar,department\r\n' 149 ) 150 return 151 152 def test_export_to_string(self): 153 # we can export an iterable of departments to a string. 154 exporter = DepartmentExporter() 155 result = exporter.export([self.dept1, self.dept2], filepath=None) 156 self.assertEqual( 157 result, 158 'code,faculty,title,title_prefix\r\n' 159 'D1,F1,Department of Cheddar,department\r\n' 160 'D2,F1,Institue of Gouda,institute\r\n' 161 ) 162 return 163 164 def test_export_all(self): 165 # we can export all depts in a site 166 exporter = DepartmentExporter() 167 exporter.export_all(self.site, self.outfile) 168 result = open(self.outfile, 'rb').read() 169 self.assertEqual( 170 result, 171 'code,faculty,title,title_prefix\r\n' 172 'D1,F1,Department of Cheddar,department\r\n' 173 'D2,F1,Institue of Gouda,institute\r\n' 174 'D3,F2,Department of Rings,department\r\n' 175 ) 176 return 177 178 def test_export_all_to_string(self): 179 # we can export all depts in a site to a string 180 exporter = DepartmentExporter() 181 result = exporter.export_all(self.site, filepath=None) 182 self.assertEqual( 183 result, 184 'code,faculty,title,title_prefix\r\n' 185 'D1,F1,Department of Cheddar,department\r\n' 186 'D2,F1,Institue of Gouda,institute\r\n' 187 'D3,F2,Department of Rings,department\r\n' 188 ) 189 return
Note: See TracChangeset for help on using the changeset viewer.