| @@ 217-275 (lines=59) @@ | ||
| 214 | self.file_loading(my_task, TEMPLATE_TYPE) |
|
| 215 | ||
| 216 | ||
| 217 | class IssuesWithFilesTest(Initialize): |
|
| 218 | """A class to test errors in file during uploads""" |
|
| 219 | ||
| 220 | def common_check(self, response, my_task): |
|
| 221 | # check errors |
|
| 222 | form = response.context.get('form') |
|
| 223 | self.assertGreater(len(form.errors), 0) |
|
| 224 | ||
| 225 | # no submissions |
|
| 226 | self.assertFalse(Submission.objects.exists()) |
|
| 227 | ||
| 228 | # test task |
|
| 229 | self.assertFalse(my_task.called) |
|
| 230 | ||
| 231 | @patch('submissions.views.ImportCRBAnimTask.delay') |
|
| 232 | def test_crb_anim_wrong_encoding(self, my_task): |
|
| 233 | # submit a crbanim with wrong encoding |
|
| 234 | response = self.client.post( |
|
| 235 | self.url, |
|
| 236 | self.get_data(ds_file="latin_type")) |
|
| 237 | ||
| 238 | # check errors |
|
| 239 | self.common_check(response, my_task) |
|
| 240 | ||
| 241 | @patch('submissions.views.ImportCRBAnimTask.delay') |
|
| 242 | def test_crb_anim_wrong_columns(self, my_task): |
|
| 243 | # submit a crbanim with wrong column |
|
| 244 | response = self.client.post( |
|
| 245 | self.url, |
|
| 246 | self.get_data(ds_file="not_valid_crbanim")) |
|
| 247 | ||
| 248 | # check errors |
|
| 249 | self.common_check(response, my_task) |
|
| 250 | ||
| 251 | @patch('xlrd.book.Book.sheet_names', return_value=['animal', 'sample']) |
|
| 252 | @patch('submissions.views.ImportTemplateTask.delay') |
|
| 253 | def test_template_issues_in_sheets(self, my_task, my_excel): |
|
| 254 | # submit a template file |
|
| 255 | response = self.client.post( |
|
| 256 | self.url, |
|
| 257 | self.get_data(ds_file=TEMPLATE_TYPE)) |
|
| 258 | ||
| 259 | # check errors |
|
| 260 | self.common_check(response, my_task) |
|
| 261 | ||
| 262 | self.assertTrue(my_excel.called) |
|
| 263 | ||
| 264 | @patch.dict( |
|
| 265 | "excel.helpers.exceltemplate.TEMPLATE_COLUMNS", |
|
| 266 | {'breed': ["a column"]}) |
|
| 267 | @patch('submissions.views.ImportTemplateTask.delay') |
|
| 268 | def test_template_issues_in_columns(self, my_task): |
|
| 269 | # submit a template file |
|
| 270 | response = self.client.post( |
|
| 271 | self.url, |
|
| 272 | self.get_data(ds_file=TEMPLATE_TYPE)) |
|
| 273 | ||
| 274 | # check errors |
|
| 275 | self.common_check(response, my_task) |
|
| 276 | ||
| @@ 167-220 (lines=54) @@ | ||
| 164 | self.assertFalse(self.my_task.called) |
|
| 165 | ||
| 166 | ||
| 167 | class ReloadValidationTest(TestBase): |
|
| 168 | def common_check(self, response, my_task): |
|
| 169 | # check errors |
|
| 170 | form = response.context.get('form') |
|
| 171 | self.assertGreater(len(form.errors), 0) |
|
| 172 | ||
| 173 | # test task |
|
| 174 | self.assertFalse(my_task.called) |
|
| 175 | ||
| 176 | @patch('submissions.views.ImportCRBAnimTask.delay') |
|
| 177 | def test_crb_anim_wrong_encoding(self, my_task): |
|
| 178 | # submit a cryoweb like dictionary |
|
| 179 | response = self.client.post( |
|
| 180 | self.url, |
|
| 181 | self.get_data(ds_file="latin_type")) |
|
| 182 | ||
| 183 | # check errors |
|
| 184 | self.common_check(response, my_task) |
|
| 185 | ||
| 186 | @patch('submissions.views.ImportCRBAnimTask.delay') |
|
| 187 | def test_crb_anim_wrong_columns(self, my_task): |
|
| 188 | # submit a cryoweb like dictionary |
|
| 189 | response = self.client.post( |
|
| 190 | self.url, |
|
| 191 | self.get_data(ds_file="not_valid_crbanim")) |
|
| 192 | ||
| 193 | # check errors |
|
| 194 | self.common_check(response, my_task) |
|
| 195 | ||
| 196 | @patch('xlrd.book.Book.sheet_names', return_value=['animal', 'sample']) |
|
| 197 | @patch('submissions.views.ImportTemplateTask.delay') |
|
| 198 | def test_template_issues_in_sheets(self, my_task, my_excel): |
|
| 199 | # submit a template file |
|
| 200 | response = self.client.post( |
|
| 201 | self.url, |
|
| 202 | self.get_data(ds_file=TEMPLATE_TYPE)) |
|
| 203 | ||
| 204 | # check errors |
|
| 205 | self.common_check(response, my_task) |
|
| 206 | ||
| 207 | self.assertTrue(my_excel.called) |
|
| 208 | ||
| 209 | @patch.dict( |
|
| 210 | "excel.helpers.exceltemplate.TEMPLATE_COLUMNS", |
|
| 211 | {'breed': ["a column"]}) |
|
| 212 | @patch('submissions.views.ImportTemplateTask.delay') |
|
| 213 | def test_template_issues_in_columns(self, my_task): |
|
| 214 | # submit a template file |
|
| 215 | response = self.client.post( |
|
| 216 | self.url, |
|
| 217 | self.get_data(ds_file=TEMPLATE_TYPE)) |
|
| 218 | ||
| 219 | # check errors |
|
| 220 | self.common_check(response, my_task) |
|
| 221 | ||
| 222 | ||
| 223 | class CRBAnimReloadSubmissionViewTest( |
|