def test_incomplete_submissions(self):
        """ Data generation should ignore incomplete submissions
            Incomplete submissions have no metrics to process.
        """

        # Set as admin.
        self.user.is_staff=True
        self.user.save()

        # Create a new submission.
        submission = Submission(
            user=self.user,
            inventory_id=Via.inventory_id,
            current_page=0
        )
        submission.save()

        # Generate data
        data = generate_data_from_sessions(self.sessions, self.user)

        for submission in data['submission_counts']:
            # Verify the Via count is correct
            correct_count = Submission.objects.filter(
                inventory_id=submission['inventory_id']
            ).exclude(
                metric__isnull=True
            ).count()

            self.assertEqual(submission['count'], correct_count)
Exemplo n.º 2
0
    def create_submission(cls, user, inventory_cls):
        """ Generate and save a single submission for an inventory """

        # Create an inventory
        inventory = inventory_cls()

        # Generate the submission
        submission = Submission()
        submission.inventory_id = inventory.inventory_id
        submission.user = user
        submission.current_page = inventory.n_pages - 1
        submission.save()
        inventory.set_submission(submission)

        # Set answers and compute metrics
        inventory.answers = get_answers(inventory_cls.__name__)
        inventory.compute_metrics()

        # Save the metrics
        inventory.save_metrics()

        # Mark the submission as complete
        submission.current_page = None
        submission.save()