Skip to content

Commit

Permalink
Finished faq and contact page and added testing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshg03 committed Jan 29, 2024
1 parent b5a77ef commit 3f334a2
Show file tree
Hide file tree
Showing 9 changed files with 646 additions and 17 deletions.
Binary file added app/my_presentation.pptx
Binary file not shown.
28 changes: 28 additions & 0 deletions app/website/templates/contact_us.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'base.html' %}

{% block content %}

<div class="col-md-6 offset-md-3">
<h1 class="mb-4" style="text-align: center;">Contact Us</h1>
<p><strong>If you have any other questions, please feel free to contact us
and our team will get back to you.</strong> </p>
</br>
<form method="POST" action="{% url 'contact_us' %}">
{% csrf_token %}
<div class="mb-3">
<input type="email" class="form-control" name="email", placeholder="Email" required>
</div>
</br>
<div class="mb-3">
<textarea name="question" class="form-control" placeholder="Enter your question here" required></textarea>
</div>
</br>
<button type="send" style="margin-right: 7rem;" class="btn btn-outline-primary">Send</button>
</form>
</div>



</div>

{% endblock %}
346 changes: 346 additions & 0 deletions app/website/templates/faq.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/website/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'chatbot' %}">Virtual Assistant</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'faq' %}">FAQ</a>
</li>

{% else %}

Expand Down
85 changes: 85 additions & 0 deletions app/website/tests/test_contactUs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from django.test import TestCase
from django.core import mail
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib import auth

class TestContactForm(TestCase):

def setUp(self) -> None:
user = User.objects.create_user(username='test3', email = 'test3@hotmailtestttt.com', password='passpass22')
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',
'question':'Can I have a summary generated in a different language?'
}, follow=True)

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

#check to see that if one email was sent
self.assertEqual(len(mail.outbox), 1)
#check to see if the subject line for email was correct
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',
'question':'Can I have a summary generated in a different language?'
}, follow=True)

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

#check to see that if no email was sent since the form is invalid
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',
'question':''
}, follow=True)

#check if post response was a success
self.assertEquals(response.status_code, 200)
#check to see that if no email was sent since the form is invalid
self.assertEqual(len(mail.outbox), 0)




14 changes: 13 additions & 1 deletion app/website/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_url_detectPlagiarism_is_resolved(self):
url = reverse("detect_plagiarism")
self.assertEquals(resolve(url).func, detect_plagiarism_view)

def test_url_generatePresentation_is_resolved(self):
def test_url_generateExercise_is_resolved(self):
url = reverse("generate_exercise")
self.assertEquals(resolve(url).func, generate_exercise_view)

def test_url_virtualAssistant_is_resolved(self):
url = reverse("chatbot")
self.assertEquals(resolve(url).func, chatbot_view)

def test_url_faq_is_resolved(self):
url = reverse("faq")
self.assertEquals(resolve(url).func, faq)

def test_url_contactUs_is_resolved(self):
url = reverse("contact_us")
self.assertEquals(resolve(url).func, contact_us)
148 changes: 134 additions & 14 deletions app/website/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib.auth.models import User, Group
from django.core.cache import cache

class TestViews(TestCase):

#Creates the student and teacher groups for the tests needed for detect plagiarism view
def setUp(self) -> None:
Group.objects.get_or_create(name='teacher')
Group.objects.get_or_create(name='student')
return super().setUp()

"""
Testing to see if Users can view our pages correctly.
"""
Expand All @@ -21,15 +29,29 @@ def test_register_view(self):
#check to see if correct template was used
self.assertTemplateUsed(response, 'register.html')

def test_faq_view(self):
response = self.client.get(reverse("faq"))
#check to see if get request was successful
self.assertEquals(response.status_code, 200)
#check to see if the correct template was used
self.assertTemplateUsed(response, 'faq.html')

def test_contactUs_view(self):
response = self.client.get(reverse("contact_us"))
#check to see if get request was successful
self.assertEquals(response.status_code, 200)
#check to see if the correct template was used
self.assertTemplateUsed(response, 'contact_us.html')

"""This is testing to see if a logged in user trys to access the register page,
if they do they should be redirected back to the home page.
"""
def test_authenticated_register_view(self):
#creates the user and saves it in the test database
user = User.objects.create_user(username='test', password='passpass22')
user = User.objects.create_user(username='test1', email = 'test1@hotmailtestttt.com', password='passpass22')
#login
response = self.client.post(reverse("home"), {
'username':'test',
'username':'test1',
'password':'passpass22'}, follow=True)
#check if post request was successful
self.assertEqual(response.status_code, 200)
Expand All @@ -45,52 +67,150 @@ def test_authenticated_register_view(self):
"""
def test_generateSummary_view_authenticated(self):
#creates the user and saves it in the test database
user = User.objects.create_user(username='test', password='passpass22')
user = User.objects.create_user(username='test2', email = 'test2@hotmailtestttt.com', password='passpass22')
#login
response = self.client.post(reverse("home"), {
'username':'test',
'username':'test2',
'password':'passpass22'}, follow=True)
#check if post request was successful
self.assertEqual(response.status_code, 200)
#check if user is authenticated (logged in)
self.assertTrue(response.context['user'].is_authenticated)
response = self.client.post(reverse("generate_summary"))
#check to see if post request was successful
response = self.client.get(reverse("generate_summary"))
#check to see if get request was successful
self.assertEqual(response.status_code, 200)
#Check to see if correct template was used
self.assertTemplateUsed(response, 'summary_generation.html')

def test_generatePresentation_view_authenticated(self):
#creates the user and saves it in the test database
user = User.objects.create_user(username='test2', password='passpass22')
#creates the user and saves it in the test database
user = User.objects.create_user(username='test3', email = 'test3@hotmailtestttt.com', password='passpass22')
#login
response = self.client.post(reverse("home"), {
'username':'test2',
'username':'test3',
'password':'passpass22'}, follow=True)
#check if post request was successful
self.assertEqual(response.status_code, 200)
#check if user is authenticated (logged in)
self.assertTrue(response.context['user'].is_authenticated)
response = self.client.post(reverse("generate_presentation"))
#check if post request was successful
response = self.client.get(reverse("generate_presentation"))
#check if get request was successful
self.assertEqual(response.status_code, 200)
#Check to see if correct template was used
self.assertTemplateUsed(response, 'presentation_generation.html')

def test_generateExercise_view_authenticated(self):
#creates the user and saves it in the test database
user = User.objects.create_user(username='test4', email = 'test4@hotmailtestttt.com', password='passpass22')
#login
response = self.client.post(reverse("home"), {
'username':'test4',
'password':'passpass22'}, follow=True)
#check if post request was successful
self.assertEqual(response.status_code, 200)
#check if user is authenticated (logged in)
self.assertTrue(response.context['user'].is_authenticated)
response = self.client.get(reverse("generate_exercise"))
#check if get request was successful
self.assertEqual(response.status_code, 200)
#Check to see if correct template was used
self.assertTemplateUsed(response, 'exercise_generation.html')

def test_virtualAssistant_view_authenticated(self):
#creates the user and saves it in the test database
user = User.objects.create_user(username='test5', email = 'test5@hotmailtestttt.com', password='passpass22')
#login
response = self.client.post(reverse("home"), {
'username':'test5',
'password':'passpass22'}, follow=True)
#check if post request was successful
self.assertEqual(response.status_code, 200)
#check if user is authenticated (logged in)
self.assertTrue(response.context['user'].is_authenticated)
response = self.client.get(reverse("chatbot"))
#check if get request was successful
self.assertEqual(response.status_code, 200)
#check to see if correct template was used
self.assertTemplateUsed(response, 'chatbot.html')

def test_detectPlagiarism_view_authenticated_teacher_group(self):
#Creates as user with the teacher group and logs in
response = self.client.post(reverse("register"),{
'username' : 'bob12',
'first_name' : 'Bob',
'last_name' : 'Johnson',
'email' : 'bobj@hotmaill.com',
'password1' : 'passpass22',
'password2' : 'passpass22',
'user_group' : 'teacher'
})
#If registration is successful then it will redirect to homepage
self.assertEquals(response.status_code, 302)
#check if it redirects to home page after registeration
self.assertRedirects(response, reverse("home"))
response = self.client.get(reverse("detect_plagiarism"))
#check if get request was successful
self.assertEqual(response.status_code, 200)
#Check to see if correct template was used
self.assertTemplateUsed(response, 'plagiarism_detection.html')

def test_detectPlagiarism_view_authenticated_student_group(self):
#Creates as user with the student group and logs in
response = self.client.post(reverse("register"),{
'username' : 'bob13',
'first_name' : 'Bob',
'last_name' : 'Johnson',
'email' : 'bobj13@hotmaill.com',
'password1' : 'passpass22',
'password2' : 'passpass22',
'user_group' : 'student'
})
#If registration is successful then it will redirect to homepage
self.assertEquals(response.status_code, 302)
#check if it redirects to home page after registeration
self.assertRedirects(response, reverse("home"))
response = self.client.get(reverse("detect_plagiarism"))
#Check to see if user is redirected to home page since user is part of the student group
self.assertEqual(response.status_code, 302)
#Redirects user back to home page since user is part of the student group
self.assertRedirects(response, reverse("home"))

"""These two tests below check to see if an unauthenticated user is trying to
view the generateSummary and generatePresentation pages. If they are they will
be redirected back to the home page.
"""
def test_generateSummary_view_not_authenticated(self):
response = self.client.post(reverse("generate_summary"))
response = self.client.get(reverse("generate_summary"))
#If user is not authenticated then it will redirect to homepage
self.assertEqual(response.status_code, 302)
#Redirects user back to home page since user is not authenticated
self.assertRedirects(response, reverse("home"))

def test_generatePresentation_view_not_authenticated(self):
response = self.client.post(reverse("generate_presentation"))
response = self.client.get(reverse("generate_presentation"))
#If user is not authenticated then it will redirect to homepage
self.assertEqual(response.status_code, 302)
#Redirects user back to home page since user is not authenticated
self.assertRedirects(response, reverse("home"))

def test_generateExercise_view_not_authenticated(self):
response = self.client.get(reverse("generate_exercise"))
#If user is not authenticated then it will redirect to homepage
self.assertEqual(response.status_code, 302)
#Redirects user back to home page since user is not authenticated
self.assertRedirects(response, reverse("home"))

def test_virtualAssistant_view_not_authenticated(self):
response = self.client.get(reverse("chatbot"))
#If user is not authenticated then it will redirect to homepage
self.assertEqual(response.status_code, 302)
#Redirects user back to home page since user is not authenticated
self.assertRedirects(response, reverse("home"))

def test_detectPlagiarism_view_not_authenticated(self):
response = self.client.get(reverse("detect_plagiarism"))
#If user is not authenticated then it will redirect to homepage
self.assertEqual(response.status_code, 302)
#Redirects user back to home page since user is not authenticated
self.assertRedirects(response, reverse("home"))

4 changes: 3 additions & 1 deletion app/website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
path('reset/<uidb64>/<token>', auth_views.PasswordResetConfirmView.as_view(template_name = "password_reset_form.html"), name = 'password_reset_confirm'),
path('reset_password_complete/', auth_views.PasswordResetCompleteView.as_view(template_name = "password_reset_done.html"), name = 'password_reset_complete'),
path('chat/<str:username>/', chat, name='chat'),
path('send_message/<str:username>/', send_message, name='send_message'),
path('send_message/<str:username>/', send_message, name='send_message'),
path('faq', views.faq, name='faq'),
path('contact_us', views.contact_us, name='contact_us'),
]
Loading

0 comments on commit 3f334a2

Please sign in to comment.