Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated testing #178

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/my_presentation.pptx
Binary file not shown.
34 changes: 2 additions & 32 deletions app/website/tests/test_contactUs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
class TestContactForm(TestCase):

def setUp(self) -> None:
user = User.objects.create_user(username='test3', email = 'test3@hotmailtestttt.com', password='passpass22')
self.user = User.objects.create_user(username='test3', email = 'test3@hotmailtestttt.com', password='passpass22')
self.client.force_login(self.user)
return super().setUp()

def test_contact_form_successful(self):
response = self.client.post(reverse("home"), {
'username':'test3',
'password':'passpass22'}, follow=True)

#check if post response was a success
self.assertEqual(response.status_code, 200)

#Should return true if user is logged in
self.assertTrue(response.context['user'].is_authenticated)

#Makes a post request to the contact form on contact us page
response = self.client.post(reverse("contact_us"), {
'email':'test3@hotmailtestttt.com',
Expand All @@ -36,16 +27,6 @@ def test_contact_form_successful(self):
self.assertEquals(mail.outbox[0].subject, "Question from test3@hotmailtestttt.com")

def test_contact_form_invalid_email(self):
response = self.client.post(reverse("home"), {
'username':'test3',
'password':'passpass22'}, follow=True)

#check if post response was a success
self.assertEqual(response.status_code, 200)

#Should return true if user is logged in
self.assertTrue(response.context['user'].is_authenticated)

#Makes a post request to the contact form on contact us page passing an invalid email
response = self.client.post(reverse("contact_us"), {
'email':'h',
Expand All @@ -59,16 +40,6 @@ def test_contact_form_invalid_email(self):
self.assertEqual(len(mail.outbox), 0)

def test_contact_form_invalid_question(self):
response = self.client.post(reverse("home"), {
'username':'test3',
'password':'passpass22'}, follow=True)

#check if post response was a success
self.assertEqual(response.status_code, 200)

#Should return true if user is logged in
self.assertTrue(response.context['user'].is_authenticated)

#Makes a post request to the contact form on contact us page passing an empty question
response = self.client.post(reverse("contact_us"), {
'email':'bob12@hotmaill.commm',
Expand All @@ -82,4 +53,3 @@ def test_contact_form_invalid_question(self):




16 changes: 13 additions & 3 deletions app/website/tests/test_editprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,25 @@ def test_profile_picture_change_unsuccessful(self):
#check if profile picture remains the same (default image)
self.assertEqual(user.profile.profile_pic.url, '/media/default.jpg')

#Test without specifying name of form being passed
def test_post_no_form_specified(self):
response = self.client.post(reverse("edit_profile"), {
'bio':'Test11 Updated Bio'
}, follow=True)
#Check if post request was a success
self.assertEqual(response.status_code, 200)
#Check to see if correct template was used
self.assertTemplateUsed(response, 'edit_profile.html')
user = User.objects.get(username=self.user.username)
#check if bio updated, should return true as bio did not update
self.assertNotEqual(user.profile.bio, 'Test11 Updated Bio')


def tearDown(self) -> None:
#remove 'test.jpg' from storage if it exists
fs = FileSystemStorage("media/profile_pictures/")
if fs.exists('test.jpg'):
fs.delete('test.jpg')
#remove 'test.bmp'
if fs.exists('test.bmp'):
fs.delete('test.bmp')
#enable logging again after tests are completed
logging.disable(logging.NOTSET)
return super().tearDown()
154 changes: 152 additions & 2 deletions app/website/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.test import TestCase
from website.forms import SignUpForm

from website.forms import SignUpForm, ChangePasswordForm, EditProfileForm, EditProfilePageForm
from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.files.storage import FileSystemStorage
import logging

class TestSignUpForm(TestCase):

Expand Down Expand Up @@ -112,3 +115,150 @@ def test_form_with_invalid_userGroup(self):
self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #error invalid user_group


class TestChangePasswordForm(TestCase):

def setUp(self) -> None:
user = User.objects.create_user(username='test33', email = 'test3@hotmailtestttt.com', password='passpass22', first_name = 'Bob', last_name='Johnson')
user = User.objects.get(username = 'test33')
self.user = user
return super().setUp()

def test_form_successful(self):
form = ChangePasswordForm(user=self.user,data={
'old_password' : 'passpass22',
'new_password1' : 'passpass222',
'new_password2' : 'passpass222'
})

self.assertTrue(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 0)

def test_form_invalid_too_common(self):
form = ChangePasswordForm(user=self.user,data={
'old_password' : 'passpass22',
'new_password1' : 'password123',
'new_password2' : 'password123'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #Error password is too common

def test_form_invalid_too_short(self):
form = ChangePasswordForm(user=self.user, data={
'old_password' : 'passpass22',
'new_password1' : 'pass22',
'new_password2' : 'pass22'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #1 error due to length

def test_form_invalid_all_numeric(self):
form = ChangePasswordForm(user=self.user,data={
'old_password' : 'passpass22',
'new_password1' : '123456789',
'new_password2' : '123456789'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #1 error password can't be entirely numeric

def test_form_invalid_empty(self):
form = ChangePasswordForm(user=self.user, data={ })
self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 3) #3 errors due to empty fields

def test_form_password_personal_info(self):
form = ChangePasswordForm(user=self.user, data={
'old_password' : 'passpass22',
'new_password1' : 'Johnson2244',
'new_password2' : 'Johnson2244'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #1 error password can't contain personal information



class TestEditProfileForm(TestCase):
def setUp(self) -> None:
user = User.objects.create_user(username='test44', email = 'test4@hotmailtestttt.com', password='passpass22')
user = User.objects.get(username = 'test44')
self.user = user
return super().setUp()

def test_form_valid(self):
form = EditProfileForm(instance = self.user, data={
'username' : 'test44',
'first_name' : 'bob',
'last_name' : 'johnson',
'email' : 'test23@test.com'
})

self.assertTrue(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 0)

def test_form_username_taken(self):
form = EditProfileForm(data={
'username' : 'test44',
'first_name' : 'bob',
'last_name' : 'johnson',
'email' : 'test23@test.com'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #Error username already taken

def test_form_invalid_email(self):
form = EditProfileForm(instance = self.user, data={
'username' : 'test44',
'first_name' : 'bob',
'last_name' : 'johnson',
'email' : 'test23com'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #Error email is invalid

def test_form_invalid_name_length(self):
name = 'bobby' * 35 #175 char
last_name = 'davis' * 35 #175 char
form = EditProfileForm(instance = self.user, data={
'username' : 'test44',
'first_name' : name,
'last_name' : last_name,
'email' : 'test23@test.com'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 2) #Error char limit first_name and last_name

def test_form_invalid_username(self):
form = EditProfileForm(data={
'username' : 'test&*@',
'first_name' : 'bob',
'last_name' : 'johnson',
'email' : 'test23@test.com'
})

self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 1) #Error invalid username

def test_form_invalid_form(self):
form = EditProfileForm(data={})
self.assertFalse(form.is_valid())
#print(form.errors)
self.assertEqual(len(form.errors), 4) #4 errors due to 4 empty fields
42 changes: 42 additions & 0 deletions app/website/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,45 @@ def test_url_faq_is_resolved(self):
def test_url_contactUs_is_resolved(self):
url = reverse("contact_us")
self.assertEquals(resolve(url).func, contact_us)

def test_url_profile_is_resolved(self):
url = reverse("profile", kwargs={'username' : 'test'})
self.assertEquals(resolve(url).func, Profile)

def test_url_editProfile_is_resolved(self):
url = reverse("edit_profile")
self.assertEquals(resolve(url).func, edit_profile)

def test_url_changePassword_is_resolved(self):
url = reverse("change_password")
self.assertEquals(resolve(url).func, change_password)

def test_url_presentationPreview_is_resolved(self):
url = reverse("presentation_preview")
self.assertEquals(resolve(url).func, presentation_preview)

def test_url_loadingPage_is_resolved(self):
url = reverse("loading_page")
self.assertEquals(resolve(url).func, loading_page_view)

def test_url_exerciseLoadingPage_is_resolved(self):
url = reverse("exercise_loading_page")
self.assertEquals(resolve(url).func, exercise_loading_page_view)

def test_url_generateAdaptedContent_is_resolved(self):
url = reverse("generate_adapted_content")
self.assertEquals(resolve(url).func, generate_adapted_content_view)

def test_url_openChats_is_resolved(self):
url = reverse("open_chats")
self.assertEquals(resolve(url).func, open_chats)

def test_url_newChats_is_resolved(self):
url = reverse("new_chats")
self.assertEquals(resolve(url).func, new_chats)

def test_url_chats_is_resolved(self):
url = reverse("chat", kwargs={'username' : 'test'})
self.assertEquals(resolve(url).func, chat)


Loading