def test_save_question_attempt_success_true(self): self.login_user() user = User.objects.get(id=1) check_achievement_conditions(user.profile) pk = Question.objects.get(slug='program-question-1').pk resp = self.client.post('/ajax/save_question_attempt/', data={ 'question': pk, 'user_input': 'test', 'test_cases': { 1: { 'passed': True } } }, content_type='application/json', HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(200, resp.status_code) self.assertJSONEqual( str(resp.content, encoding='utf8'), { 'success': True, 'curr_points': 50, 'point_diff': 0, 'achievements': '' })
def test_context_object(self): user = User.objects.get(id=1) check_achievement_conditions( user.profile) # make sure a program question has been answered resp = self.client.get('/questions/create/') self.assertEqual(resp.status_code, 200) self.assertEqual(resp.context['question_types'], [ { 'name': 'Program', 'count': 1, 'unanswered_count': 0 }, { 'name': 'Function', 'count': 1, 'unanswered_count': 1 }, { 'name': 'Parsons', 'count': 1, 'unanswered_count': 1 }, { 'name': 'Debugging', 'count': 1, 'unanswered_count': 1 }, ])
def test_context_object(self): self.login_user() user = User.objects.get(id=1) check_achievement_conditions(user.profile) resp = self.client.get('/users/achievements/') self.assertEqual(resp.status_code, 200) self.assertEqual(len(resp.context['achievements_not_earned']), 9) self.assertEqual(resp.context['num_achievements_earned'], 1) self.assertEqual(resp.context['num_achievements'], 10)
def test_context_object(self): self.login_user() user = User.objects.get(id=1) check_achievement_conditions(user.profile) resp = self.client.get('/users/dashboard/') self.assertEqual(resp.status_code, 200) self.assertEqual(len(resp.context['questions_to_do']), 2) self.assertEqual(len(resp.context['studies']), 0) self.assertEqual(len(resp.context['all_achievements']), len(Achievement.objects.all())) self.assertEqual(resp.context['all_complete'], False) self.assertEqual(resp.context['codewof_profile'], user.profile) self.assertEqual(resp.context['goal'], user.profile.goal) self.assertEqual(resp.context['num_questions_answered'], 1)