Changeset 7739 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 1 Mar 2012, 09:22:47 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_export.py
r7731 r7739 7 7 from waeup.sirp.interfaces import ICSVExporter 8 8 from waeup.sirp.testing import SIRPUnitTestLayer 9 from waeup.sirp.university import FacultiesContainer, Faculty, Department 10 from waeup.sirp.university.export import FacultyExporter, DepartmentExporter 9 from waeup.sirp.university import ( 10 FacultiesContainer, Faculty, Department, Course, 11 ) 12 from waeup.sirp.university.export import ( 13 FacultyExporter, DepartmentExporter, CourseExporter, 14 ) 11 15 12 16 class FacultyExporterTest(unittest.TestCase): … … 133 137 134 138 def test_get_as_utility(self): 135 # we can get a facultyexporter as utility139 # we can get a department exporter as utility 136 140 result = queryUtility(ICSVExporter, name="departments") 137 141 self.assertTrue(result is not None) … … 188 192 ) 189 193 return 194 195 class CourseExporterTest(unittest.TestCase): 196 # Tests for CourseExporter 197 198 layer = SIRPUnitTestLayer 199 200 def setUp(self): 201 self.workdir = tempfile.mkdtemp() 202 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 203 # create some departments and courses in a fake site 204 container = FacultiesContainer() 205 self.site = {'faculties':container} 206 self.fac = Faculty('Faculty of Cheese', 'faculty', 'F1') 207 container.addFaculty(self.fac) 208 self.dept1 = Department('Department of Cheddar', 'department', 'D1') 209 self.dept2 = Department('Institue of Gouda', 'institute', 'D2') 210 self.fac.addDepartment(self.dept1) 211 self.fac.addDepartment(self.dept2) 212 self.course1 = Course('Cheese Basics', 'C1') 213 self.course2 = Course('Advanced Cheese Making', 'C2') 214 self.course3 = Course('Selling Cheese', 'C3') 215 self.dept1.courses[u'C1'] = self.course1 216 self.dept1.courses['C2'] = self.course2 217 self.dept2.courses[u'C3'] = self.course3 218 return 219 220 def tearDown(self): 221 shutil.rmtree(self.workdir) 222 return 223 224 def test_ifaces(self): 225 # make sure we fullfill interface contracts 226 obj = CourseExporter() 227 verifyObject(ICSVExporter, obj) 228 verifyClass(ICSVExporter, CourseExporter) 229 return 230 231 def test_get_as_utility(self): 232 # we can get a course exporter as utility 233 result = queryUtility(ICSVExporter, name="courses") 234 self.assertTrue(result is not None) 235 return 236 237 def test_export(self): 238 # we can export an iterable of courses 239 exporter = CourseExporter() 240 exporter.export([self.course1], self.outfile) 241 result = open(self.outfile, 'rb').read() 242 self.assertEqual( 243 result, 244 'code,faculty,department,title,credits,passmark,semester\r\n' 245 'C1,F1,,Cheese Basics,0,40,1\r\n' 246 ) 247 return 248 249 def test_export_to_string(self): 250 # we can export an iterable of courses to a string. 251 exporter = CourseExporter() 252 result = exporter.export([self.course1, self.course2], filepath=None) 253 self.assertEqual( 254 result, 255 'code,faculty,department,title,credits,passmark,semester\r\n' 256 'C1,F1,,Cheese Basics,0,40,1\r\n' 257 'C2,F1,,Advanced Cheese Making,0,40,1\r\n' 258 ) 259 return 260 261 def test_export_all(self): 262 # we can export all courses in a site 263 exporter = CourseExporter() 264 exporter.export_all(self.site, self.outfile) 265 result = open(self.outfile, 'rb').read() 266 self.assertEqual( 267 result, 268 'code,faculty,department,title,credits,passmark,semester\r\n' 269 'C1,F1,,Cheese Basics,0,40,1\r\n' 270 'C2,F1,,Advanced Cheese Making,0,40,1\r\n' 271 'C3,F1,,Selling Cheese,0,40,1\r\n' 272 ) 273 return 274 275 def test_export_all_to_string(self): 276 # we can export all courses in a site to a string 277 exporter = CourseExporter() 278 result = exporter.export_all(self.site, filepath=None) 279 self.assertEqual( 280 result, 281 'code,faculty,department,title,credits,passmark,semester\r\n' 282 'C1,F1,,Cheese Basics,0,40,1\r\n' 283 'C2,F1,,Advanced Cheese Making,0,40,1\r\n' 284 'C3,F1,,Selling Cheese,0,40,1\r\n' 285 ) 286 return
Note: See TracChangeset for help on using the changeset viewer.