def test_validate_extension_format(self): with open(self.FILE_XML, 'rb') as f: uploaded_file = SimpleUploadedFile('incoming_students.xml', f.read()) form = PyExcelFileForm( trips_year=self.trips_year, files={'spreadsheet': uploaded_file} ) self.assertFalse(form.is_valid())
def test_upload_form_bom_csv(self): with open(self.FILE_CSV_WITH_BOM, 'rb') as f: uploaded_file = SimpleUploadedFile('incoming_students.csv', f.read()) form = PyExcelFileForm( trips_year=self.trips_year, files={'spreadsheet': uploaded_file} ) IncomingStudent.objects.create_from_sheet(form.load_sheet(), self.trips_year) self.assertEqual(IncomingStudent.objects.count(), 2)
def test_upload_form_csv(self): with open(self.FILE_CSV, 'rb') as f: uploaded_file = SimpleUploadedFile('incoming_students.csv', f.read()) form = PyExcelFileForm( trips_year=self.trips_year, files={'spreadsheet': uploaded_file} ) sheet = form.load_sheet() self.assertEqual(len(list(sheet.rows())), 3)