Skip to content

Commit

Permalink
log voting timestamp [Refactor]: Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FSadrieh committed May 22, 2023
1 parent 1e7e58f commit 1c6aa4c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,6 @@ def send_textanswer_reminder_to_user(cls, user: UserProfile, evaluation_url_tupl


class VoteTimestamp(models.Model):
"""A timestamp, when a user voted for a course."""

evaluation = models.ForeignKey(Evaluation, models.PROTECT)
evaluation = models.ForeignKey(Evaluation, models.CASCADE)
timestamp = models.DateTimeField(verbose_name=_("vote timestamp"), auto_now_add=True)
1 change: 1 addition & 0 deletions evap/staff/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def __init__(self, data=None, *, instance: Course):
"_participant_count",
"_voter_count",
"voters",
"votetimestamp",
}

CONTRIBUTION_COPIED_FIELDS = {
Expand Down
8 changes: 3 additions & 5 deletions evap/staff/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,18 +1257,16 @@ class TestSemesterVoteTimestampsExport(WebTestStaffMode):
@classmethod
def setUpTestData(cls):
cls.manager = make_manager()
cls.semester = baker.make(Semester)
cls.evaluation = baker.make(Evaluation, course__semester=cls.semester)
cls.timestamp = baker.make(VoteTimestamp, evaluation=cls.evaluation)
cls.timestamp = baker.make(VoteTimestamp)

cls.url = f"/staff/semester/{cls.semester.pk}/vote_timestamps_export"
cls.url = f"/staff/semester/{cls.timestamp.evaluation.course.semester.pk}/vote_timestamps_export"
cls.test_users = [cls.manager]

def test_view_downloads_csv_file(self):
response = self.app.get(self.url, user=self.manager)
expected_content = (
"Evaluation id;Timestamp;Course type;Course degrees;Vote end date\n"
+ f"{self.evaluation.id};{self.timestamp.timestamp};{self.evaluation.course.type.name};{', '.join([degree.name for degree in self.evaluation.course.degrees.all()])};{self.evaluation.vote_end_datetime}\n"
+ f"{self.timestamp.evaluation.id};{self.timestamp.timestamp};{self.timestamp.evaluation.course.type.name};{', '.join([degree.name for degree in self.timestamp.evaluation.course.degrees.all()])};{self.timestamp.evaluation.vote_end_datetime}\n"
).encode("utf-8")
self.assertEqual(response.content, expected_content)

Expand Down
3 changes: 1 addition & 2 deletions evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,7 @@ def semester_participation_export(_request, semester_id):
@manager_required
def vote_timestamps_export(__, semester_id):
semester = get_object_or_404(Semester, id=semester_id)
evaluations = semester.evaluations.all()
timestamps = VoteTimestamp.objects.filter(evaluation__in=evaluations)
timestamps = VoteTimestamp.objects.filter(evaluation__course__semester=semester)

filename = f"Timestamp-{semester.name}.csv"
response = AttachmentResponse(filename, content_type="text/csv")
Expand Down
4 changes: 2 additions & 2 deletions evap/student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ def test_vote_timestamp(self):
form = page.forms["student-vote-form"]
self.fill_form(form)
form.submit()
self.assertEqual(len(VoteTimestamp.objects.all()), timestamps_before + 1)
time = VoteTimestamp.objects.all().first().timestamp
self.assertEqual(VoteTimestamp.objects.count(), timestamps_before + 1)
time = VoteTimestamp.objects.latest("timestamp").timestamp
self.assertTrue(time > time_before)
self.assertTrue(time < datetime.datetime.now())

Expand Down

0 comments on commit 1c6aa4c

Please sign in to comment.