Changeset 14939 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 18 Jan 2018, 07:34:42 (7 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r14648 r14939 1345 1345 invalid_line = check_csv_charset(filecontent.splitlines()) 1346 1346 if invalid_line: 1347 self.flash(_( 1348 "Your file contains forbidden characters or " 1349 "has invalid CSV format. " 1350 "First problematic line detected: line %s. " 1351 "Please replace." % invalid_line), type='danger') 1347 if invalid_line == -1: 1348 self.flash(_( 1349 "The data in your file contain trailing whitespaces." 1350 "Please replace."), type='danger') 1351 else: 1352 self.flash(_( 1353 "Your file contains forbidden characters or " 1354 "has invalid CSV format. " 1355 "First problematic line detected: line %s. " 1356 "Please replace." % invalid_line), type='danger') 1352 1357 logger.info('%s - invalid file uploaded: %s' % 1353 1358 (ob_class, target)) -
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r14511 r14939 40 40 SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'test_file.csv') 41 41 FORBIDDEN_FILE = os.path.join(os.path.dirname(__file__), 'forbidden_file.csv') 42 FORBIDDEN_FILE_2 = os.path.join( 43 os.path.dirname(__file__), 'forbidden_file_2.csv') 42 44 43 45 class UniversitySetup(FunctionalTestCase): … … 193 195 self.assertTrue( 194 196 'Your file contains forbidden characters or' 197 in self.browser.contents) 198 logfile = os.path.join( 199 self.app['datacenter'].storage, 'logs', 'datacenter.log') 200 logcontent = open(logfile).read() 201 self.assertTrue('zope.mgr - browser.pages.DatacenterUploadPage - ' 202 'invalid file uploaded:' in logcontent) 203 return 204 205 def test_forbidden_file_upload_2(self): 206 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 207 self.browser.open(self.datacenter_path) 208 self.assertEqual(self.browser.headers['Status'], '200 Ok') 209 self.assertEqual(self.browser.url, self.datacenter_path) 210 self.browser.getLink("Upload data").click() 211 file = open(FORBIDDEN_FILE_2) 212 ctrl = self.browser.getControl(name='uploadfile:file') 213 file_ctrl = ctrl.mech_control 214 file_ctrl.add_file(file, filename='my_corrupted_file.csv') 215 self.browser.getControl('Upload').click() 216 self.assertTrue( 217 'The data in your file contain trailing whitespaces.' 195 218 in self.browser.contents) 196 219 logfile = os.path.join( -
main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py
r13537 r14939 756 756 757 757 def check_csv_charset(iterable): 758 """Check contents of `iterable` regarding valid CSV encoding. 758 """Check contents of `iterable` regarding valid CSV encoding and 759 trailing whitespaces in data. 759 760 760 761 `iterable` is expected to be an iterable on _rows_ (not … … 764 765 765 766 Returns line num of first illegal char or ``None``. Line nums 766 start counting with 1 (not zero). 767 start counting with 1 (not zero). Returns -1 if data contain 768 trailing whitespaces. 767 769 """ 768 770 linenum = 1 … … 771 773 for row in reader: 772 774 linenum += 1 775 for value in row.values(): 776 if value.endswith(' '): 777 return -1 773 778 except UnicodeDecodeError: 774 779 return linenum -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_helpers.py
r12433 r14939 537 537 self.assertEqual(helpers.check_csv_charset(csv), 2) 538 538 539 540 def test_invalid_data3(self): 541 csv = ( 542 "code,title,title_prefix\n" 543 "FAC1,Faculty 1,faculty\n" 544 "FAC2,Faculty 2 ,institute\n" 545 "FAC3,Fäcülty 3,school\n" 546 ).splitlines() 547 self.assertEqual(helpers.check_csv_charset(csv), -1) 539 548 540 549 class MemInfoTestCase(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.