wulkanowy-web/tests/test_views.py

57 lines
1.9 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
response = self.client.get(self.list_url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'frontend/index.html')
#CONTENT_VIEW
response = self.client.get(self.detail_url)
2021-01-26 12:22:24 +01:00
self.assertEquals(response.status_code, 302)
#ACCOUNT_MANAGER
response = self.client.get(reverse('account_manager'))
self.assertEquals(response.status_code, 302)
#API
data = {
"loginName": "jan@fakelog.cf",
"Password": "jan123",
"Symbol": "powiatwulkanowy",
"diaryUrl": "http://cufs.fakelog.cf/"
}
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-01-28 00:08:44 +01:00
students = cookies_data['data']['register_r']['data']
2021-01-26 12:22:24 +01:00
#JAN
2021-01-28 00:08:44 +01:00
jan_data = students[0]
cookies_data['data']['register_r']['data'] = [jan_data]
2021-01-26 12:22:24 +01:00
2021-01-28 00:08:44 +01:00
response = self.client.post(reverse('grades'), content_type='application/xml', data=json.dumps(cookies_data))
self.assertEquals(response.status_code, 200)
print(response.content)
#JOANNA
joanna_data = students[3]
cookies_data['data']['register_r']['data'] = [joanna_data]
response = self.client.post(reverse('grades'), content_type='application/xml', data=json.dumps(cookies_data))
self.assertEquals(response.status_code, 200)
print(response.content)