wulkanowy-web/tests/test_views.py

288 lines
10 KiB
Python
Raw Normal View History

2021-01-23 12:23:24 +01:00
from django.test import TestCase, Client
from django.urls import reverse
import json
class TestViews(TestCase):
def setUp(self):
self.client = Client()
2021-01-26 12:22:24 +01:00
self.csrf_token = Client(enforce_csrf_checks=True)
2021-01-23 12:23:24 +01:00
self.list_url = reverse('home')
self.detail_url = reverse('content')
def test_views(self):
#DEFAULT_VIEW
2021-04-14 21:11:40 +02:00
print("\033[94mTesting login view...")
2021-01-23 12:23:24 +01:00
response = self.client.get(self.list_url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'frontend/index.html')
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:14:30 +02:00
print("\033[92mPassed!")
2021-04-14 21:11:40 +02:00
else:
print("\033[91mFailed!")
2021-01-23 12:23:24 +01:00
#CONTENT_VIEW
2021-04-14 21:11:40 +02:00
print("\033[94mTesting content view...")
2021-01-23 12:23:24 +01:00
response = self.client.get(self.detail_url)
2021-01-26 12:22:24 +01:00
self.assertEquals(response.status_code, 302)
2021-04-14 20:58:44 +02:00
if response.status_code == 302:
2021-04-14 21:14:30 +02:00
print("\033[92mPassed!")
2021-04-14 21:11:40 +02:00
else:
print("\033[91mFailed!")
2021-01-26 12:22:24 +01:00
#ACCOUNT_MANAGER
2021-04-14 21:11:40 +02:00
print("\033[94mTesting account manager view...")
2021-01-26 12:22:24 +01:00
response = self.client.get(reverse('account_manager'))
self.assertEquals(response.status_code, 302)
2021-04-14 20:58:44 +02:00
if response.status_code == 302:
2021-04-14 21:14:30 +02:00
print("\033[92mPassed!")
2021-04-14 21:11:40 +02:00
else:
print("\033[91mFailed!")
2021-01-26 12:22:24 +01:00
#API
data = {
"loginName": "jan@fakelog.cf",
"Password": "jan123",
"Symbol": "powiatwulkanowy",
"diaryUrl": "http://cufs.fakelog.cf/"
}
2021-04-14 20:58:44 +02:00
2021-04-14 21:11:40 +02:00
print("\033[94mTesting login...")
2021-01-26 12:22:24 +01:00
response = self.client.post(reverse('login'), content_type='application/xml', data=json.dumps(data))
2021-01-28 00:08:44 +01:00
cookies_data = response.json()
2021-01-26 12:22:24 +01:00
self.assertEquals(response.status_code, 200)
2021-04-14 21:11:40 +02:00
if response.status_code == 200:
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-26 12:22:24 +01:00
2021-01-31 22:23:03 +01:00
students = cookies_data['data']['students']['data']
2021-01-26 12:22:24 +01:00
#JAN
2021-04-14 21:11:40 +02:00
print("\033[94mTesting registering as Jan Kowalski...")
2021-01-28 00:08:44 +01:00
jan_data = students[0]
2021-01-31 22:23:03 +01:00
cookies_data['data']['students']['data'] = [jan_data]
2021-01-28 12:28:16 +01:00
get_data_test(self.client, cookies_data, self.assertEquals)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
print("\033[95m============================================================")
2021-01-28 00:08:44 +01:00
#JOANNA
2021-04-14 21:11:40 +02:00
print("\033[94mTesting registering as Joanna Czerwińska...")
2021-01-28 00:08:44 +01:00
joanna_data = students[3]
2021-01-31 22:23:03 +01:00
cookies_data['data']['students']['data'] = [joanna_data]
2021-01-28 12:28:16 +01:00
get_data_test(self.client, cookies_data, self.assertEquals)
2021-01-30 22:20:51 +01:00
log_out_test(self.client, self.assertEquals)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 00:08:44 +01:00
2021-01-28 12:28:16 +01:00
def get_data_test(client, cookies_data, assertEquals):
#GRADES
2021-04-14 21:11:40 +02:00
print("\033[94mTesting grades...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('grades'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#TIMETABLE
2021-04-14 21:11:40 +02:00
print("\033[94mTesting timetable...")
2021-02-01 23:41:18 +01:00
response = client.post(reverse('timetable'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
2021-01-28 12:28:16 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#EXAMS
2021-04-14 21:11:40 +02:00
print("\033[94mTesting exams...")
2021-02-02 11:42:45 +01:00
response = client.post(reverse('exams'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
2021-01-28 12:28:16 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#HOMEWORKS
2021-04-14 21:11:40 +02:00
print("\033[94mTesting homeworks...")
2021-02-02 11:42:45 +01:00
response = client.post(reverse('homeworks'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
2021-01-28 12:28:16 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#ATTENDANCE
2021-04-14 21:11:40 +02:00
print("\033[94mTesting attendance...")
2021-02-02 12:03:42 +01:00
response = client.post(reverse('attendance'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
2021-01-28 12:28:16 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#NOTES
2021-04-14 21:11:40 +02:00
print("\033[94mTesting notes...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('notes'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#SCHOOL DATA
2021-04-14 21:11:40 +02:00
print("\033[94mTesting school data...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('school_data'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#DASHBOARD
2021-04-14 21:11:40 +02:00
print("\033[94mTesting dashboard...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('dashboard'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#MOBILE ACCESS
#REGISTERED DEVICES
2021-04-14 21:11:40 +02:00
print("\033[94mTesting registered devices...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('registered_devices'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#REGISTER DEVICE
2021-04-14 21:11:40 +02:00
print("\033[94mTesting registering device...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('register_device'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#MESSAGES
#RECEIVED MESSAGES
2021-04-14 21:11:40 +02:00
print("\033[94mTesting received messages...")
2021-01-28 12:28:16 +01:00
messages_ids = []
response = client.post(reverse('received_messages'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
messages_ids.append([response.json()['data']])
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#SENT MESSAGES
2021-04-14 21:11:40 +02:00
print("\033[94mTesting sent messages...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('sent_messages'), content_type='appication/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
for id in response.json()['data']:
messages_ids.append(id)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#DELETED MESSAGES
2021-04-14 21:11:40 +02:00
print("\033[94mTesting deleted messages...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('deleted_messages'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
messages_ids.append([response.json()['data']])
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#GET RECIPIENTS
2021-04-14 21:11:40 +02:00
print("\033[94mTesting getting recipients...")
2021-01-28 12:28:16 +01:00
response = client.post(reverse('recipients'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
recipients = response.json()['addressee']['data']
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
2021-01-30 21:09:11 +01:00
#STUDENT DATA
2021-04-14 21:11:40 +02:00
print("\033[94mTesting student data...")
2021-01-30 21:09:11 +01:00
response = client.post(reverse('student_data'), content_type='application/xml', data=json.dumps(cookies_data))
2021-02-02 22:24:58 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-02-02 22:24:58 +01:00
#STATS
#PARTIAL
2021-04-14 21:11:40 +02:00
print("\033[94mTesting partial grades stats...")
2021-02-02 22:24:58 +01:00
response = client.post(reverse('partial'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-02-02 22:24:58 +01:00
#YEAR
2021-04-14 21:11:40 +02:00
print("\033[94mTesting year grades stats...")
2021-02-02 22:24:58 +01:00
response = client.post(reverse('year'), content_type='application/xml', data=json.dumps(cookies_data))
2021-01-30 21:09:11 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-30 21:09:11 +01:00
2021-01-28 12:28:16 +01:00
#SEND MESSAGE
2021-04-14 21:11:40 +02:00
print("\033[94mTesting sending message...")
2021-01-28 12:28:16 +01:00
for recipient in recipients:
send_data = {
'cookies_data': json.dumps(cookies_data),
'data': recipient,
'subject': 'Test subject',
'content': 'Test content'
}
response = client.post(reverse('send_message'), content_type='application/xml', data=json.dumps(send_data))
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-28 12:28:16 +01:00
#GETTING MESSAGE CONTENT
2021-04-14 21:11:40 +02:00
print("\033[94mTesting getting content of message...")
2021-01-28 12:28:16 +01:00
for id in messages_ids:
send_data = {
'cookies_data': json.dumps(cookies_data),
'message_id': id
}
response = client.post(reverse('message_content'), content_type='application/xml', data=json.dumps(send_data))
2021-01-30 22:20:51 +01:00
assertEquals(response.status_code, 200)
2021-04-14 20:58:44 +02:00
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
2021-01-30 22:20:51 +01:00
def log_out_test(client, assertEquals):
#LOG OUT
2021-04-14 21:11:40 +02:00
print("\033[94mTesting logging out...")
2021-01-30 22:20:51 +01:00
response = client.get(reverse('log_out'), content_type='application/xml')
2021-04-14 20:58:44 +02:00
assertEquals(response.status_code, 200)
if response.status_code == 200:
2021-04-14 21:11:40 +02:00
print("\033[92mPassed!")
else:
print("\033[91mFailed!")