Skip to content

Commit

Permalink
fix: Upgrade DRF, Cypress and switch to pypdf
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Dec 10, 2024
1 parent b29396d commit 349c43e
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 201 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ black = "*"
django-selenium-clean = "==1.0.1"
django-test-migrations = "==1.4.0"
isort = "*"
PyPDF2 = "==2.10.6"
pypdf = "==5.1.0"
pytest = "==8.*"
pytest-cov = "*"
pytest-django = "==4.8.0"
Expand Down
24 changes: 12 additions & 12 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cfl_common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"django-import-export==4.2.0",
"django-pipeline==3.1.0",
"django-two-factor-auth==1.17.0",
"djangorestframework==3.15.1",
"djangorestframework==3.15.2",
"libsass==0.23.0",
"more-itertools==8.7.0",
"pgeocode==0.4.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"cypress": "^12.0.0"
"cypress": "^13.0.0"
}
}
34 changes: 20 additions & 14 deletions portal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from datetime import date, datetime, timedelta
from unittest.mock import ANY, Mock, patch

import PyPDF2
import pytest
from common.mail import campaign_ids
from common.models import (
Class,
DailyActivity,
Expand All @@ -16,7 +16,6 @@
UserProfile,
UserSession,
)
from common.mail import campaign_ids
from common.tests.utils.classes import create_class_directly
from common.tests.utils.organisation import (
create_organisation_directly,
Expand All @@ -35,6 +34,7 @@
from game.models import Level
from game.tests.utils.attempt import create_attempt
from game.tests.utils.level import create_save_level
from pypdf import PdfReader
from rest_framework.test import APIClient, APITestCase

from deploy import captcha
Expand Down Expand Up @@ -93,10 +93,10 @@ def test_reminder_cards(self):

# read PDF, check there's only 1 page and that the correct student details show
with io.BytesIO(response.content) as pdf_file:
file_reader = PyPDF2.PdfFileReader(pdf_file)
assert file_reader.getNumPages() == 1
file_reader = PdfReader(pdf_file)
assert len(file_reader.pages) == 1

page_text = file_reader.getPage(0).extractText()
page_text = file_reader.pages[0].extract_text()
assert NAME1 in page_text
assert NAME2 in page_text
assert PASSWORD1 in page_text
Expand All @@ -119,11 +119,11 @@ def test_reminder_cards(self):

# Check there are 2 pages and that each page contains the warning text
with io.BytesIO(response.content) as pdf_file:
file_reader = PyPDF2.PdfFileReader(pdf_file)
assert file_reader.getNumPages() == 2
file_reader = PdfReader(pdf_file)
assert len(file_reader.pages) == 2

page1_text = file_reader.getPage(0).extractText()
page2_text = file_reader.getPage(1).extractText()
page1_text = file_reader.pages[0].extract_text()
page2_text = file_reader.pages[1].extract_text()
assert REMINDER_CARDS_PDF_WARNING_TEXT in page1_text
assert REMINDER_CARDS_PDF_WARNING_TEXT in page2_text

Expand Down Expand Up @@ -252,20 +252,24 @@ def test_release_verified_student(self):
assert response.status_code == 302

student = Student.objects.get(pk=self.student.pk)

assert student.user.is_verified

c.logout()
c.login(username=self.email, password=self.password)

teacher = Teacher.objects.factory("the", "teacher", "[email protected]", "password")
teacher = Teacher.objects.factory(
"the", "teacher", "[email protected]", "password"
)
level = Level.objects.create()

level.owner = student.new_user.userprofile
level.shared_with.add(teacher.new_user)
level.save()

students_levels = Level.objects.filter(owner=student.new_user.userprofile).all()
students_levels = Level.objects.filter(
owner=student.new_user.userprofile
).all()

for level in students_levels.all():
assert level.shared_with.exists()
Expand All @@ -292,7 +296,9 @@ def test_release_verified_student(self):
student = Student.objects.get(pk=self.student.pk)
assert not student.user.is_verified

students_levels = Level.objects.filter(owner=student.new_user.userprofile).all()
students_levels = Level.objects.filter(
owner=student.new_user.userprofile
).all()

for level in students_levels.all():
assert not level.shared_with.exists()
Expand Down
Loading

0 comments on commit 349c43e

Please sign in to comment.