Changeset 5744 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 13 Feb 2011, 01:31:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_jambtables.py
r5740 r5744 42 42 from waeup.sirp.datacenter import DataCenter 43 43 from waeup.sirp.applicants.jambtables import ( 44 JAMBData Table, JAMBDataPlugin, JAMBDataRoot,44 JAMBDataPlugin, JAMBDataRoot, 45 45 ) 46 from waeup.sirp.applicants.jambtables.interfaces import IJAMBDataTable47 46 48 47 class FakeSite(dict): … … 69 68 return 70 69 71 class JAMBTableTestCase(JAMBTableTestCaseBase):72 def test_createJAMBTable(self):73 table = JAMBDataTable()74 self.assertEqual(table._data_len, 0)75 self.assertEqual(table._temporary, False)76 self.assertEqual(table._datafile_path, None)77 return78 79 def test_iterator(self):80 table = JAMBDataTable()81 self.assertEqual(len(list(table)), 0)82 table.importFromCSV(self.datafile)83 self.assertEqual(len(list(table)), 3)84 85 def test_import(self):86 table = JAMBDataTable()87 self.assertEqual(table.import_datetime, None)88 table.importFromCSV(self.datafile)89 self.assertNotEqual(table.import_datetime, None)90 91 def test_clear(self):92 table = JAMBDataTable()93 table.importFromCSV(self.datafile)94 path = table._datafile_path95 table.clear()96 exists = os.path.exists(path)97 self.assertEqual(exists, False)98 self.assertEqual(0, len(list(table)))99 100 def test_clear_broken_path(self):101 table = JAMBDataTable()102 table.importFromCSV(self.datafile)103 path = table._datafile_path104 table._datafile_path = 'not-existent-path'105 table.clear()106 107 def test_import_datetime(self):108 table = JAMBDataTable()109 self.assertTrue(table.import_datetime is None)110 table.importFromCSV(self.datafile)111 now = datetime.now()112 diff = now - table.import_datetime113 self.assertTrue(diff.seconds < 5)114 table.clear()115 self.assertTrue(table.import_datetime is None)116 117 def test_importer_username(self):118 table = JAMBDataTable()119 self.assertTrue(table.importer_username is None)120 table.importFromCSV(self.datafile, 'manfred')121 self.assertEqual(table.importer_username, u'manfred')122 self.assertTrue(isinstance(table.importer_username, unicode))123 table.importFromCSV(self.datafile, 'fred')124 self.assertEqual(table.importer_username, u'fred')125 table.importFromCSV(self.datafile)126 self.assertTrue(table.importer_username is None)127 table.clear()128 self.assertTrue(table.importer_username is None)129 130 def test_keys(self):131 table = JAMBDataTable()132 self.assertFalse('91100546DD' in table.keys())133 table.importFromCSV(self.datafile)134 self.assertTrue('91100546DD' in table.keys())135 self.assertFalse('91100546DE' in table.keys())136 137 def test_items(self):138 table = JAMBDataTable()139 self.assertEqual([], list(table.items()))140 table.importFromCSV(self.datafile)141 self.assertNotEqual([], list(table.items()))142 143 def test_interface_compliance(self):144 self.assertTrue(verifyClass(IJAMBDataTable, JAMBDataTable))145 table = JAMBDataTable()146 self.assertTrue(verifyObject(IJAMBDataTable, table))147 table.importFromCSV(self.datafile)148 self.assertTrue(verifyObject(IJAMBDataTable, table))149 150 class JAMBTableFunctionalTestCase(JAMBTableTestCaseBase):151 """A test case where we check JAMB tables inside a site.152 """153 154 def setUp(self):155 super(JAMBTableFunctionalTestCase, self).setUp()156 157 # We need at least these to register factories for a University.158 grok.testing.grok('waeup.sirp.student')159 grok.testing.grok('waeup.sirp.hostel')160 grok.testing.grok('waeup.sirp.university')161 162 self.site = University()163 sm = LocalSiteManager(self.site)164 self.site.setSiteManager(sm)165 self.datacenter_dir = tempfile.mkdtemp()166 self.datacenter = self.site['datacenter']167 self.datacenter.setStoragePath(self.datacenter_dir)168 # If the old datacenter already had a jambtables dir, remove it...169 if os.path.isdir(170 os.path.join(self.datacenter_dir, 'jambdata')171 ):172 shutil.rmtree(os.path.join(self.datacenter_dir, 'jambdata'))173 return174 175 def tearDown(self):176 shutil.rmtree(self.tempdir)177 shutil.rmtree(self.datacenter_dir)178 # Unregister site...179 setSite()180 return181 182 def test_createJAMBTableInSite(self):183 table = JAMBDataTable()184 self.assertEqual(table._data_len, 0)185 self.assertEqual(table._temporary, False)186 self.assertEqual(table._datafile_path, None)187 table.importFromCSV(self.datafile)188 return189 190 def test_createJAMBTableOutsideSite(self):191 clearSite(self.site)192 table = JAMBDataTable()193 self.assertEqual(table._data_len, 0)194 self.assertEqual(table._temporary, False)195 self.assertEqual(table._datafile_path, None)196 table.importFromCSV(self.datafile)197 return198 70 199 71 class JAMBDataPluginTestCase(unittest.TestCase): … … 293 165 suite = unittest.TestSuite() 294 166 for testcase in [ 295 JAMBTableTestCase,296 JAMBTableFunctionalTestCase,297 167 JAMBDataPluginTestCase, 298 168 ]:
Note: See TracChangeset for help on using the changeset viewer.