Skip to content

Commit

Permalink
Merge pull request #181 from MithishR/mahi_tests
Browse files Browse the repository at this point in the history
tests added for payment page
  • Loading branch information
ojusharma authored Apr 5, 2024
2 parents 1739284 + f2323f8 commit 63f0d67
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
Binary file modified Django/communicado/pages/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified Django/communicado/pages/static/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion Django/communicado/pages/templates/pages/payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,3 @@ <h1>Payment</h1>
</div>
</body>
</html>

66 changes: 65 additions & 1 deletion Django/communicado/pages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .models import *
from django.test import LiveServerTestCase
from django.contrib.auth.hashers import make_password
from django.shortcuts import render
#from selenium import webdriver
#from selenium.webdriver.common.keys import Keys
#from selenium.webdriver.chrome.options import Options
Expand Down Expand Up @@ -554,4 +555,67 @@ def test_edit_event_page_success(self):
self.assertEqual(response.status_code, 302)
self.assertIsNotNone(event_organizer)
events = Events.objects.filter(eventOrganizerID=event_organizer)
self.assertIn(event, events)
self.assertIn(event, events)

def test_user_account_page(self):

user = users.objects.create(
role="Admin",
username="testuser",
email="[email protected]",
address="123 Test St"
)



response = render(None, "pages/useraccount.html", {'user': user})


self.assertEqual(response.status_code, 200)


self.assertContains(response, '<h1>Your Account Information</h1>')
self.assertContains(response, '<strong>Role:</strong> {}'.format(user.role))
self.assertContains(response, '<strong>Username:</strong> {}'.format(user.username))
self.assertContains(response, '<strong>Email:</strong> {}'.format(user.email))
self.assertContains(response, '<strong>Address:</strong> {}'.format(user.address))
self.assertContains(response, '<a href="#" class="btn">Edit Account Details</a>')
self.assertContains(response, '<a href="userbookinfo" class="btn">Booking History</a>')

def test_payment_view_get(self):
response = self.client.get(reverse('payment'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'pages/payment.html')

def test_payment_view_post_success(self):
data = {
'card_number': '1234567890123456',
'expiration_date': '12/25',
'cvv': '123',
'cardholder_name': 'John Doe'
}
response = self.client.post(reverse('payment'), data)
self.assertEqual(response.status_code, 302)

def test_payment_view_post_invalid_card_number(self):
data = {
'card_number': '123456', # Invalid card number
'expiration_date': '12/25',
'cvv': '123',
'cardholder_name': 'John Doe'
}
response = self.client.post(reverse('payment'), data)
self.assertEqual(response.status_code, 302)

def test_payment_page_contains_elements(self):
response = self.client.get(reverse('payment'))

# Check if the page contains the payment form elements
self.assertContains(response, '<form', count=1)
self.assertContains(response, '<input type="text" id="card_number" name="card_number" required>', count=1)
self.assertContains(response, '<input type="text" id="expiration_date" name="expiration_date" pattern="(0[1-9]|1[0-2])\/[0-9]{2}" placeholder="MM/YY" required>', count=1)
self.assertContains(response, '<input type="password" id="cvv" name="cvv" required>', count=1)
self.assertContains(response, '<input type="text" id="cardholder_name" name="cardholder_name" required>', count=1)
self.assertContains(response, '<input type="submit" value="Pay">', count=1)


0 comments on commit 63f0d67

Please sign in to comment.