Skip to content

Commit

Permalink
Merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Aug 31, 2023
2 parents 82c6d9e + cc39d00 commit 3d46d16
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 36 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
"runserver",
"localhost:8000"
]
},
{
"name": "Pytest",
"type": "python",
"request": "test",
"justMyCode": false,
"presentation": {
"hidden": true
}
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
32 changes: 18 additions & 14 deletions Pipfile.lock

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

70 changes: 48 additions & 22 deletions portal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,19 +739,34 @@ class CronTestCase(APITestCase):
class TestUser(CronTestCase):
# TODO: use fixtures
def setUp(self):
(
self.teacher_user,
self.teacher_user_profile,
self.indy_user,
self.indy_user_profile,
self.student_user,
) = self.create_users()

def create_users(self):
teacher_email, _ = signup_teacher_directly(preverified=False)
create_organisation_directly(teacher_email)
self.klass, _, access_code = create_class_directly(teacher_email)
_, _, access_code = create_class_directly(teacher_email)
_, _, student = create_school_student_directly(access_code)
indy_email, _, _ = create_independent_student_directly()

self.teacher_user = User.objects.get(email=teacher_email)
self.teacher_user_profile = UserProfile.objects.get(user=self.teacher_user)
teacher_user = User.objects.get(email=teacher_email)
teacher_user_profile = UserProfile.objects.get(user=teacher_user)

self.indy_user = User.objects.get(email=indy_email)
self.indy_user_profile = UserProfile.objects.get(user=self.indy_user)
indy_user = User.objects.get(email=indy_email)
indy_user_profile = UserProfile.objects.get(user=indy_user)

self.student_user = student.new_user
return (
teacher_user,
teacher_user_profile,
indy_user,
indy_user_profile,
student.new_user,
)

def send_verify_email_reminder(
self,
Expand Down Expand Up @@ -867,30 +882,41 @@ def delete_unverified_users(
is_verified: bool,
assert_exists: bool,
):
teacher_email, _ = signup_teacher_directly(preverified=is_verified)
indy_email, _, _ = create_independent_student_directly(preverified=is_verified)
_, _, student = create_school_student_directly(self.klass.access_code)

teacher_user = User.objects.get(email=teacher_email)
indy_user = User.objects.get(email=indy_email)
student_user = student.new_user
(
teacher_user,
teacher_user_profile,
indy_user,
indy_user_profile,
student_user,
) = self.create_users()

teacher_user.date_joined = timezone.now() - timedelta(days=days, hours=12)
teacher_user.save()
indy_user.date_joined = timezone.now() - timedelta(days=days, hours=12)
indy_user.save()
student_user.date_joined = timezone.now() - timedelta(days=days, hours=12)
student_user.save()
indy_user.date_joined = timezone.now() - timedelta(days=days, hours=12)
indy_user.save()

self.client.get(reverse("delete-unverified-accounts"))
teacher_user_profile.is_verified = is_verified
teacher_user_profile.save()
indy_user_profile.is_verified = is_verified
indy_user_profile.save()

(self.assertTrue if assert_exists else self.assertFalse)(
User.objects.filter(id=teacher_user.id).exists()
)
(self.assertTrue if assert_exists else self.assertFalse)(User.objects.filter(id=indy_user.id).exists())
self.client.get(reverse("delete-unverified-accounts"))

# Assert the student didn't get deleted
assert User.objects.filter(id=student_user.id).exists()
teacher_user_exists = User.objects.filter(id=teacher_user.id).exists()
indy_user_exists = User.objects.filter(id=indy_user.id).exists()
student_user_exists = User.objects.filter(id=student_user.id).exists()
(self.assertTrue if assert_exists else self.assertFalse)(teacher_user_exists)
(self.assertTrue if assert_exists else self.assertFalse)(indy_user_exists)
self.assertTrue(student_user_exists)

if teacher_user_exists:
teacher_user.delete()
if indy_user_exists:
indy_user.delete()
if student_user_exists:
student_user.delete()

delete_unverified_users(
days=18,
Expand Down

0 comments on commit 3d46d16

Please sign in to comment.