'Test whether LoncapaProblem.update_score can deliver queued result to the right subproblem'

def test_update_score(self):

    answer_ids = sorted(self.problem.get_question_answers())
    old_cmap = CorrectMap()
    for (i, answer_id) in enumerate(answer_ids):
        queuekey = (1000 + i)
        queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(UTC))
        old_cmap.update(CorrectMap(answer_id=answer_ids[i], queuestate=queuestate))
    grader_msg = '<span>MESSAGE</span>'
    correct_score_msg = json.dumps({'correct': True, 'score': 1, 'msg': grader_msg})
    incorrect_score_msg = json.dumps({'correct': False, 'score': 0, 'msg': grader_msg})
    xserver_msgs = {'correct': correct_score_msg, 'incorrect': incorrect_score_msg}
    for correctness in ['correct', 'incorrect']:
        self.problem.correct_map = CorrectMap()
        self.problem.correct_map.update(old_cmap)
        self.problem.update_score(xserver_msgs[correctness], queuekey=0)
        self.assertEquals(self.problem.correct_map.get_dict(), old_cmap.get_dict())
        for answer_id in answer_ids:
            self.assertTrue(self.problem.correct_map.is_queued(answer_id))
    for correctness in ['correct', 'incorrect']:
        for (i, answer_id) in enumerate(answer_ids):
            self.problem.correct_map = CorrectMap()
            self.problem.correct_map.update(old_cmap)
            new_cmap = CorrectMap()
            new_cmap.update(old_cmap)
            npoints = (1 if (correctness == 'correct') else 0)
            new_cmap.set(answer_id=answer_id, npoints=npoints, correctness=correctness, msg=grader_msg, queuestate=None)
            self.problem.update_score(xserver_msgs[correctness], queuekey=(1000 + i))
            self.assertEquals(self.problem.correct_map.get_dict(), new_cmap.get_dict())
            for (j, test_id) in enumerate(answer_ids):
                if (j == i):
                    self.assertFalse(self.problem.correct_map.is_queued(test_id))
                else:
                    self.assertTrue(self.problem.correct_map.is_queued(test_id))
