Code Duplication    Length = 17-26 lines in 3 locations

web/opensubmit/tests/test_executor.py 3 locations

@@ 374-399 (lines=26) @@
371
            self.assertIn("localhost", email.body)
372
373
    def test_broken_validator_feedback(self):
374
        from django.core import mail
375
376
        grading = create_pass_fail_grading()
377
        assignment = create_validated_assignment(
378
            self.course, grading, "/submfiles/validation/1000tfm/", "validator.zip")
379
        assignment.save()
380
        sf = create_submission_file("/submfiles/validation/1000tfm/packed.zip")
381
        sub = create_validatable_submission(
382
            self.user, assignment, sf)
383
        test_machine = self._register_executor()
384
        sub.assignment.test_machines.add(test_machine)
385
386
        # Fire up the executor
387
        self.assertEqual(False, self._run_executor())
388
        sub.refresh_from_db()
389
        self.assertEqual(sub.state, Submission.TEST_VALIDITY_FAILED)
390
        text = sub.get_validation_result().result
391
        self.assertIn("Internal error", text)
392
        # Check mail outbox for student information
393
        self.assertEqual(1, len(mail.outbox))
394
        for email in mail.outbox:
395
            self.assertIn("Validation failed", email.subject)
396
            self.assertIn("failed", email.body)
397
            self.assertIn("localhost", email.body)
398
399
    def test_output_logging(self):
400
        grading = create_pass_fail_grading()
401
        assignment = create_validated_assignment(
402
            self.course, grading, "/submfiles/validation/1000fff/", "validator.py")
@@ 421-443 (lines=23) @@
418
        grading = create_pass_fail_grading()
419
        assignment = create_validated_assignment(
420
            self.course, 
421
            grading, 
422
            "/submfiles/validation/d000fff/",
423
            "validator_build.py",
424
            "validator_run.py")
425
        assignment.attachment_test_timeout = 1
426
        assignment.save()
427
        sf = create_submission_file("/submfiles/validation/d000fff/helloworld.c")
428
        sub = create_validatable_submission(
429
            self.user, assignment, sf)
430
        test_machine = self._register_executor()
431
        sub.assignment.test_machines.add(test_machine)
432
433
        # Fire up the executor for validation
434
        self.assertEqual(True, self._run_executor())
435
        # Fire up the executor for full test
436
        self.assertEqual(True, self._run_executor())
437
        # Check if timeout marking took place
438
        sub.refresh_from_db()
439
        self.assertEqual(sub.state, Submission.TEST_FULL_FAILED)
440
        assert("took too long" in sub.get_fulltest_result().result)
441
        # Failed full tests shall not be reported
442
        self.assertEqual(0, len(mail.outbox))
443
444
    def test_single_file_validator_test(self):
445
        sub = self._register_test_machine()
446
@@ 356-372 (lines=17) @@
353
        sf = create_submission_file("/submfiles/validation/d000fff/helloworld.c")
354
        sub = create_validatable_submission(
355
            self.user, assignment, sf)
356
        test_machine = self._register_executor()
357
        sub.assignment.test_machines.add(test_machine)
358
359
        # Fire up the executor, should mark the submission as timed out
360
        self.assertEqual(True, self._run_executor())
361
        # Check if timeout marking took place
362
        sub.refresh_from_db()
363
        self.assertEqual(sub.state, Submission.TEST_VALIDITY_FAILED)
364
        text = sub.get_validation_result().result
365
        self.assertIn("took too long", text)
366
        # Check mail outbox for student information
367
        self.assertEqual(1, len(mail.outbox))
368
        for email in mail.outbox:
369
            self.assertIn("Validation failed", email.subject)
370
            self.assertIn("failed", email.body)
371
            self.assertIn("localhost", email.body)
372
373
    def test_broken_validator_feedback(self):
374
        from django.core import mail
375