|
6 | 6 | from django.core.management import call_command
|
7 | 7 | from django.test import TestCase
|
8 | 8 |
|
9 |
| -from crowdsourcer.models import Assigned, Marker, MarkingSession, Response |
| 9 | +from crowdsourcer.models import ( |
| 10 | + Assigned, |
| 11 | + Marker, |
| 12 | + MarkingSession, |
| 13 | + PublicAuthority, |
| 14 | + Question, |
| 15 | + Response, |
| 16 | + ResponseType, |
| 17 | +) |
10 | 18 |
|
11 | 19 |
|
12 | 20 | class BaseCommandTestCase(TestCase):
|
@@ -250,3 +258,182 @@ def test_deduplicate(self):
|
250 | 258 | {GREEN}done{NOBOLD}
|
251 | 259 | """,
|
252 | 260 | )
|
| 261 | + |
| 262 | + |
| 263 | +class AssignAutomaticPoints(BaseCommandTestCase): |
| 264 | + fixtures = [ |
| 265 | + "authorities.json", |
| 266 | + "basics.json", |
| 267 | + "users.json", |
| 268 | + "questions.json", |
| 269 | + "options.json", |
| 270 | + ] |
| 271 | + |
| 272 | + def test_basic_run(self): |
| 273 | + data_file = ( |
| 274 | + pathlib.Path(__file__).parent.resolve() / "data" / "automatic_points.csv" |
| 275 | + ) |
| 276 | + |
| 277 | + self.assertEquals(Response.objects.count(), 0) |
| 278 | + self.call_command( |
| 279 | + "add_automatic_points", |
| 280 | + session="Default", |
| 281 | + file=data_file, |
| 282 | + previous="Second Session", |
| 283 | + stage="First Mark", |
| 284 | + commit=True, |
| 285 | + ) |
| 286 | + self.assertEquals(Response.objects.count(), 1) |
| 287 | + |
| 288 | + r = Response.objects.get(question_id=269) |
| 289 | + |
| 290 | + self.assertEquals( |
| 291 | + r.option.description, |
| 292 | + "One or more significant building have been retrofitted", |
| 293 | + ) |
| 294 | + self.assertEquals(r.page_number, "322,323") |
| 295 | + self.assertEquals(r.public_notes, "https://www.example.org/retrofit-rules") |
| 296 | + self.assertEquals(r.evidence, "Awarded the point due to the Legislation") |
| 297 | + self.assertEquals( |
| 298 | + r.private_notes, |
| 299 | + "All District Councils get the point\nAutomatically assigned mark", |
| 300 | + ) |
| 301 | + self.assertEquals(r.authority.name, "Adur District Council") |
| 302 | + |
| 303 | + def test_replace_answers_run(self): |
| 304 | + data_file = ( |
| 305 | + pathlib.Path(__file__).parent.resolve() / "data" / "automatic_points.csv" |
| 306 | + ) |
| 307 | + |
| 308 | + authority = PublicAuthority.objects.get(name="Adur District Council") |
| 309 | + question = Question.objects.get(id=269) |
| 310 | + rt = ResponseType.objects.get(type="First Mark") |
| 311 | + u = User.objects.get(username="marker") |
| 312 | + r = Response.objects.create( |
| 313 | + user=u, |
| 314 | + question=question, |
| 315 | + authority=authority, |
| 316 | + response_type=rt, |
| 317 | + option_id=3, |
| 318 | + page_number="333", |
| 319 | + public_notes="http://example.com/rules", |
| 320 | + evidence="Some evidence", |
| 321 | + private_notes="These are private notes", |
| 322 | + ) |
| 323 | + |
| 324 | + self.assertEquals(Response.objects.count(), 1) |
| 325 | + self.call_command( |
| 326 | + "add_automatic_points", |
| 327 | + session="Default", |
| 328 | + file=data_file, |
| 329 | + previous="Second Session", |
| 330 | + stage="First Mark", |
| 331 | + commit=True, |
| 332 | + update_existing_responses=True, |
| 333 | + ) |
| 334 | + self.assertEquals(Response.objects.count(), 1) |
| 335 | + |
| 336 | + r = Response.objects.get(question_id=269) |
| 337 | + |
| 338 | + self.assertEquals( |
| 339 | + r.option.description, |
| 340 | + "One or more significant building have been retrofitted", |
| 341 | + ) |
| 342 | + self.assertEquals(r.page_number, "322,323") |
| 343 | + self.assertEquals(r.public_notes, "https://www.example.org/retrofit-rules") |
| 344 | + self.assertEquals(r.evidence, "Awarded the point due to the Legislation") |
| 345 | + self.assertEquals( |
| 346 | + r.private_notes, |
| 347 | + "All District Councils get the point\nAutomatically assigned mark\nOverridden by automatic assignment", |
| 348 | + ) |
| 349 | + self.assertEquals(r.authority.name, "Adur District Council") |
| 350 | + |
| 351 | + def test_copy_previous_answers_run_bad_opt_match(self): |
| 352 | + data_file = ( |
| 353 | + pathlib.Path(__file__).parent.resolve() |
| 354 | + / "data" |
| 355 | + / "automatic_points_copy_prev.csv" |
| 356 | + ) |
| 357 | + |
| 358 | + authority = PublicAuthority.objects.get(name="Adur District Council") |
| 359 | + question = Question.objects.get(id=281) |
| 360 | + rt = ResponseType.objects.get(type="Audit") |
| 361 | + u = User.objects.get(username="marker") |
| 362 | + Response.objects.create( |
| 363 | + user=u, |
| 364 | + question=question, |
| 365 | + authority=authority, |
| 366 | + response_type=rt, |
| 367 | + option_id=14, |
| 368 | + page_number="333", |
| 369 | + public_notes="http://example.com/rules", |
| 370 | + evidence="Some evidence", |
| 371 | + private_notes="These are private notes", |
| 372 | + ) |
| 373 | + |
| 374 | + self.assertEquals(Response.objects.count(), 1) |
| 375 | + self.call_command( |
| 376 | + "add_automatic_points", |
| 377 | + session="Second Session", |
| 378 | + file=data_file, |
| 379 | + previous="Default", |
| 380 | + stage="First Mark", |
| 381 | + commit=True, |
| 382 | + ) |
| 383 | + self.assertEquals(Response.objects.count(), 1) |
| 384 | + |
| 385 | + def test_copy_previous_answers_run(self): |
| 386 | + data_file = ( |
| 387 | + pathlib.Path(__file__).parent.resolve() |
| 388 | + / "data" |
| 389 | + / "automatic_points_copy_prev.csv" |
| 390 | + ) |
| 391 | + |
| 392 | + opt_map = ( |
| 393 | + pathlib.Path(__file__).parent.resolve() |
| 394 | + / "data" |
| 395 | + / "automatic_points_opt_map.csv" |
| 396 | + ) |
| 397 | + |
| 398 | + authority = PublicAuthority.objects.get(name="Adur District Council") |
| 399 | + question = Question.objects.get(id=281) |
| 400 | + rt = ResponseType.objects.get(type="Audit") |
| 401 | + u = User.objects.get(username="marker") |
| 402 | + r = Response.objects.create( |
| 403 | + user=u, |
| 404 | + question=question, |
| 405 | + authority=authority, |
| 406 | + response_type=rt, |
| 407 | + option_id=14, |
| 408 | + page_number="333", |
| 409 | + public_notes="http://example.com/rules", |
| 410 | + evidence="Some evidence", |
| 411 | + private_notes="These are private notes", |
| 412 | + ) |
| 413 | + |
| 414 | + self.assertEquals(Response.objects.count(), 1) |
| 415 | + self.call_command( |
| 416 | + "add_automatic_points", |
| 417 | + session="Second Session", |
| 418 | + file=data_file, |
| 419 | + option_map=opt_map, |
| 420 | + previous="Default", |
| 421 | + stage="First Mark", |
| 422 | + commit=True, |
| 423 | + ) |
| 424 | + self.assertEquals(Response.objects.count(), 2) |
| 425 | + |
| 426 | + r = Response.objects.get(question_id=2002) |
| 427 | + |
| 428 | + self.assertEquals( |
| 429 | + r.option.description, |
| 430 | + "Section Session Transport Q1 Opt 1", |
| 431 | + ) |
| 432 | + self.assertEquals(r.page_number, "333") |
| 433 | + self.assertEquals(r.public_notes, "http://example.com/rules") |
| 434 | + self.assertEquals(r.evidence, "Some evidence") |
| 435 | + self.assertEquals( |
| 436 | + r.private_notes, |
| 437 | + "These are private notes\nAutomatically assigned mark", |
| 438 | + ) |
| 439 | + self.assertEquals(r.authority.name, "Adur District Council") |
0 commit comments