summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authoradityacp2021-01-25 13:12:56 +0530
committeradityacp2021-01-25 14:28:11 +0530
commit1e5c8af8748602d90a52f51d45799274155f8cd9 (patch)
treed51c46ee81866b7065f994b9e3c100457947312c /yaksh
parentc474c68a2621e8c470ce2751103128fa793be62e (diff)
downloadonline_test-1e5c8af8748602d90a52f51d45799274155f8cd9.tar.gz
online_test-1e5c8af8748602d90a52f51d45799274155f8cd9.tar.bz2
online_test-1e5c8af8748602d90a52f51d45799274155f8cd9.zip
Fix views and models tests
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py4
-rw-r--r--yaksh/templates/yaksh/monitor.html16
-rw-r--r--yaksh/test_models.py19
-rw-r--r--yaksh/test_views.py21
-rw-r--r--yaksh/views.py25
5 files changed, 37 insertions, 48 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 7609859..3e3e2d1 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -2178,6 +2178,8 @@ class AnswerPaperManager(models.Manager):
return best_attempt
def get_user_scores(self, question_papers, user, course_id):
+ if not question_papers:
+ return None
qp_ids = list(zip(*question_papers))[0]
papers = self.filter(
course_id=course_id, user_id=user.get("id"),
@@ -2277,6 +2279,8 @@ class AnswerPaper(models.Model):
)
def get_per_question_score(self, question_ids):
+ if not question_ids:
+ return None
que_ids = list(zip(*question_ids))[1]
answers = self.answers.filter(
question_id__in=que_ids).values("question_id", "marks")
diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html
index fccf201..5e8fdc3 100644
--- a/yaksh/templates/yaksh/monitor.html
+++ b/yaksh/templates/yaksh/monitor.html
@@ -202,23 +202,9 @@ $(document).ready(function()
<form action="{% url 'yaksh:download_quiz_csv' course.id quiz.id %}" method="post">
{% csrf_token %}
<div class="modal-body">
- <b>Uncheck unwanted columns</b>
- <br>
- {% for field in csv_fields %}
- <div class="form-check form-check-inline">
- <label class="form-check-label">
- {% if field == 'username' or field == 'questions' %}
- <input class="form-check-input" name="csv_fields" type="checkbox" value="{{ field }}" checked onclick="return false"> {{ field }}
- {% else %}
- <input class="form-check-input" name="csv_fields" type="checkbox" value="{{ field }}" checked> {{ field }}
- {% endif %}
- </label>
- </div>
- <br>
- {% endfor %}
<b>Select Attempt Number: Default latest attempt</b>
<select class="form-control" name = "attempt_number">
- {%for attempt_number in attempt_numbers %}
+ {% for attempt_number in attempt_numbers %}
{% if forloop.last %}
<option value="{{ attempt_number }}" selected>{{ attempt_number }} (Latest)</option>
{% else %}
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index fe0d3b5..a424b36 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -1416,27 +1416,34 @@ class AnswerPaperTestCases(unittest.TestCase):
def test_get_per_question_score(self):
# Given
question_id = self.question4.id
- expected_score = 1
+ question_name = self.question4.summary
+ expected_score = {"Q4": 1.0}
# When
score = self.answerpaper_single_question.get_per_question_score(
- question_id
+ [(question_name, question_id)]
)
# Then
self.assertEqual(score, expected_score)
# Given
question_id = self.question2.id
- expected_score = 0
+ question_name = self.question2.summary
+ expected_score = {"Q2": 0.0}
# When
- score = self.answerpaper.get_per_question_score(question_id)
+ score = self.answerpaper.get_per_question_score(
+ [(question_name, question_id)]
+ )
# Then
self.assertEqual(score, expected_score)
# Given
question_id = 131
- expected_score = 'NA'
+ question_name = "NA"
+ expected_score = {'NA': 0}
# When
- score = self.answerpaper.get_per_question_score(question_id)
+ score = self.answerpaper.get_per_question_score(
+ [(question_name, question_id)]
+ )
# Then
self.assertEqual(score, expected_score)
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 31066d1..89d209e 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -4955,6 +4955,14 @@ class TestDownloadCsv(TestCase):
total_marks=1.0, fixed_question_order=str(self.question.id)
)
self.question_paper.fixed_questions.add(self.question)
+ self.learning_unit = LearningUnit.objects.create(
+ order=1, type="quiz", quiz=self.quiz)
+ self.learning_module = LearningModule.objects.create(
+ order=1, name="download module", description="download module",
+ check_prerequisite=False, creator=self.user)
+ self.learning_module.learning_unit.add(self.learning_unit.id)
+ self.course.learning_module.add(self.learning_module)
+
# student answerpaper
user_answer = "def add(a, b)\n\treturn a+b"
@@ -5056,7 +5064,9 @@ class TestDownloadCsv(TestCase):
kwargs={'course_id': self.course.id}),
follow=True
)
- file_name = "{0}.csv".format(self.course.name.lower())
+ file_name = "{0}.csv".format(
+ self.course.name.replace(" ", "_").lower()
+ )
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get('Content-Disposition'),
'attachment; filename="{0}"'.format(file_name))
@@ -5089,15 +5099,16 @@ class TestDownloadCsv(TestCase):
username=self.user.username,
password=self.user_plaintext_pass
)
- response = self.client.get(
+ response = self.client.post(
reverse('yaksh:download_quiz_csv',
kwargs={"course_id": self.course.id,
"quiz_id": self.quiz.id}),
+ data={"attempt_number": 1},
follow=True
)
- file_name = "{0}-{1}-attempt{2}.csv".format(
- self.course.name.replace('.', ''),
- self.quiz.description.replace('.', ''), 1
+ file_name = "{0}-{1}-attempt-{2}.csv".format(
+ self.course.name.replace(' ', '_'),
+ self.quiz.description.replace(' ', '_'), 1
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get('Content-Disposition'),
diff --git a/yaksh/views.py b/yaksh/views.py
index 3c83ee9..5b67570 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -103,10 +103,6 @@ def add_as_moderator(users, group_name=MOD_GROUP_NAME):
user.profile.save()
-CSV_FIELDS = ['name', 'username', 'roll_number', 'institute', 'department',
- 'questions', 'marks_obtained', 'out_of', 'percentage', 'status']
-
-
def get_html_text(md_text):
"""Takes markdown text and converts it to html"""
return markdown.markdown(
@@ -1400,13 +1396,11 @@ def monitor(request, quiz_id=None, course_id=None):
attempt_number=last_attempt['last_attempt_num']
)
)
- csv_fields = CSV_FIELDS
context = {
"papers": papers,
"quiz": quiz,
"msg": "Quiz Results",
"latest_attempts": latest_attempts,
- "csv_fields": csv_fields,
"attempt_numbers": attempt_numbers,
"course": course
}
@@ -1821,18 +1815,6 @@ def user_data(request, user_id, questionpaper_id=None, course_id=None):
return my_render_to_response(request, 'yaksh/user_data.html', context)
-def _expand_questions(questions, field_list):
- i = field_list.index('questions')
- field_list.remove('questions')
- for question in questions:
- field_list.insert(
- i, 'Q-{0}-{1}-{2}-marks'.format(question.id, question.summary,
- question.points))
- field_list.insert(
- i+1, 'Q-{0}-{1}-comments'.format(question.id, question.summary))
- return field_list
-
-
@login_required
@email_verified
def download_quiz_csv(request, course_id, quiz_id):
@@ -1840,13 +1822,12 @@ def download_quiz_csv(request, course_id, quiz_id):
if not is_moderator(current_user):
raise Http404('You are not allowed to view this page!')
course = get_object_or_404(Course, id=course_id)
- quiz = get_object_or_404(Quiz, id=quiz_id)
if not course.is_creator(current_user) and \
not course.is_teacher(current_user):
raise Http404('The quiz does not belong to your course')
+ quiz = get_object_or_404(Quiz, id=quiz_id)
question_paper = quiz.questionpaper_set.last()
if request.method == 'POST':
- csv_fields = request.POST.getlist('csv_fields')
attempt_number = request.POST.get('attempt_number')
questions = question_paper.get_question_bank()
answerpapers = AnswerPaper.objects.select_related(
@@ -1874,10 +1855,10 @@ def download_quiz_csv(request, course_id, quiz_id):
course.name.replace(' ', '_'),
quiz.description.replace(' ', '_'), attempt_number
)
- output_file = df.to_csv(response, index=False)
+ df.to_csv(response, index=False)
return response
else:
- return monitor(request, quiz_id)
+ return monitor(request, quiz_id, course_id)
@login_required