Update test_views.py

This commit is contained in:
Tomasz F 2021-04-14 21:11:40 +02:00 committed by GitHub
parent 3ea63036f5
commit 25867d35e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,29 +11,35 @@ class TestViews(TestCase):
def test_views(self):
#DEFAULT_VIEW
print("Testing login view...")
print("\033[94mTesting login view...")
response = self.client.get(self.list_url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'frontend/index.html')
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!"")
else:
print("\033[91mFailed!")
#CONTENT_VIEW
print("Testing content view...")
print("\033[94mTesting content view...")
response = self.client.get(self.detail_url)
self.assertEquals(response.status_code, 302)
if response.status_code == 302:
print("Passed!")
print("\033[92mPassed!"")
else:
print("\033[91mFailed!")
#ACCOUNT_MANAGER
print("Testing account manager view...")
print("\033[94mTesting account manager view...")
response = self.client.get(reverse('account_manager'))
self.assertEquals(response.status_code, 302)
if response.status_code == 302:
print("Passed!")
print("\033[92mPassed!"")
else:
print("\033[91mFailed!")
#API
data = {
@ -43,162 +49,205 @@ class TestViews(TestCase):
"diaryUrl": "http://cufs.fakelog.cf/"
}
print("Testing login...")
print("\033[94mTesting login...")
response = self.client.post(reverse('login'), content_type='application/xml', data=json.dumps(data))
cookies_data = response.json()
self.assertEquals(response.status_code, 200)
if response.status_code == 200:
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
students = cookies_data['data']['students']['data']
#JAN
print("Testing registering as Jan Kowalski...")
print("\033[94mTesting registering as Jan Kowalski...")
jan_data = students[0]
cookies_data['data']['students']['data'] = [jan_data]
get_data_test(self.client, cookies_data, self.assertEquals)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
print("\033[95m============================================================")
#JOANNA
print("Testing registering as Joanna Czerwińska...")
print("\033[94mTesting registering as Joanna Czerwińska...")
joanna_data = students[3]
cookies_data['data']['students']['data'] = [joanna_data]
get_data_test(self.client, cookies_data, self.assertEquals)
log_out_test(self.client, self.assertEquals)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
def get_data_test(client, cookies_data, assertEquals):
#GRADES
print("Testing grades...")
print("\033[94mTesting grades...")
response = client.post(reverse('grades'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#TIMETABLE
print("Testing timetable...")
print("\033[94mTesting timetable...")
response = client.post(reverse('timetable'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#EXAMS
print("Testing exams...")
print("\033[94mTesting exams...")
response = client.post(reverse('exams'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#HOMEWORKS
print("Testing homeworks...")
print("\033[94mTesting homeworks...")
response = client.post(reverse('homeworks'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#ATTENDANCE
print("Testing attendance...")
print("\033[94mTesting attendance...")
response = client.post(reverse('attendance'), content_type='application/xml', data=json.dumps({'cookies': json.dumps(cookies_data), 'week': 0}))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#NOTES
print("Testing notes...")
print("\033[94mTesting notes...")
response = client.post(reverse('notes'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#SCHOOL DATA
print("Testing school data...")
print("\033[94mTesting school data...")
response = client.post(reverse('school_data'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#DASHBOARD
print("Testing dashboard...")
print("\033[94mTesting dashboard...")
response = client.post(reverse('dashboard'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#MOBILE ACCESS
#REGISTERED DEVICES
print("Testing registered devices...")
print("\033[94mTesting registered devices...")
response = client.post(reverse('registered_devices'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#REGISTER DEVICE
print("Testing registering device...")
print("\033[94mTesting registering device...")
response = client.post(reverse('register_device'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#MESSAGES
#RECEIVED MESSAGES
print("Testing received messages...")
print("\033[94mTesting received messages...")
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']])
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#SENT MESSAGES
print("Testing sent messages...")
print("\033[94mTesting sent messages...")
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)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#DELETED MESSAGES
print("Testing deleted messages...")
print("\033[94mTesting deleted messages...")
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']])
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#GET RECIPIENTS
print("Testing getting recipients...")
print("\033[94mTesting getting recipients...")
response = client.post(reverse('recipients'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
recipients = response.json()['addressee']['data']
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#STUDENT DATA
print("Testing student data...")
print("\033[94mTesting student data...")
response = client.post(reverse('student_data'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#STATS
#PARTIAL
print("Testing partial grades stats...")
print("\033[94mTesting partial grades stats...")
response = client.post(reverse('partial'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#YEAR
print("Testing year grades stats...")
print("\033[94mTesting year grades stats...")
response = client.post(reverse('year'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#SEND MESSAGE
print("Testing sending message...")
print("\033[94mTesting sending message...")
for recipient in recipients:
send_data = {
'cookies_data': json.dumps(cookies_data),
@ -209,10 +258,12 @@ def get_data_test(client, cookies_data, assertEquals):
response = client.post(reverse('send_message'), content_type='application/xml', data=json.dumps(send_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
#GETTING MESSAGE CONTENT
print("Testing getting content of message...")
print("\033[94mTesting getting content of message...")
for id in messages_ids:
send_data = {
'cookies_data': json.dumps(cookies_data),
@ -221,12 +272,16 @@ def get_data_test(client, cookies_data, assertEquals):
response = client.post(reverse('message_content'), content_type='application/xml', data=json.dumps(send_data))
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")
def log_out_test(client, assertEquals):
#LOG OUT
print("Testing logging out...")
print("\033[94mTesting logging out...")
response = client.get(reverse('log_out'), content_type='application/xml')
assertEquals(response.status_code, 200)
if response.status_code == 200:
print("\033[92m Passed!")
print("\033[92mPassed!")
else:
print("\033[91mFailed!")