commit
220ecbf243
6 changed files with 186 additions and 22 deletions
|
@ -39,6 +39,7 @@ def login(request, *args, **kwargs):
|
||||||
'success': False
|
'success': False
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
request.session['is_logged'] = True
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
request.session[request.session.session_key] = Fernet.generate_key().decode('utf-8')
|
request.session[request.session.session_key] = Fernet.generate_key().decode('utf-8')
|
||||||
|
@ -51,7 +52,6 @@ def login(request, *args, **kwargs):
|
||||||
sender_return['s'] = sender_return['s'].encode()
|
sender_return['s'] = sender_return['s'].encode()
|
||||||
sender_return['s'] = rkey.encrypt(sender_return['s'])
|
sender_return['s'] = rkey.encrypt(sender_return['s'])
|
||||||
sender_return['s'] = sender_return['s'].decode('utf-8')
|
sender_return['s'] = sender_return['s'].decode('utf-8')
|
||||||
request.session['is_logged'] = True
|
|
||||||
data_response = {'success': True, 'data': sender_return}
|
data_response = {'success': True, 'data': sender_return}
|
||||||
return JsonResponse(data_response)
|
return JsonResponse(data_response)
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,12 @@ const displayData = () => {
|
||||||
<input class="with-gap" name="group1" value='`+ student.UczenPelnaNazwa + `' type="radio" checked />
|
<input class="with-gap" name="group1" value='`+ student.UczenPelnaNazwa + `' type="radio" checked />
|
||||||
<span>`+ student.UczenPelnaNazwa + `</span>
|
<span>`+ student.UczenPelnaNazwa + `</span>
|
||||||
</label>
|
</label>
|
||||||
</p>`
|
</p>`;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
document.querySelector("#content").innerHTML += `<button id="button" class="waves-light waves-effect btn red darken-1">LOGIN</button>`
|
document.querySelector("#content").innerHTML += `<button id="button" class="waves-light waves-effect btn red darken-1">LOGIN</button>`;
|
||||||
const button_ = document.querySelector("#button")
|
const button_ = document.querySelector("#button");
|
||||||
button_.addEventListener('click', logIn)
|
button_.addEventListener('click', logIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
const logIn = () => {
|
const logIn = () => {
|
||||||
|
@ -28,9 +28,9 @@ const logIn = () => {
|
||||||
studentName = ele[i].value;
|
studentName = ele[i].value;
|
||||||
students.forEach((student) => {
|
students.forEach((student) => {
|
||||||
if (student.UczenPelnaNazwa == studentName) {
|
if (student.UczenPelnaNazwa == studentName) {
|
||||||
cookies_data.data.register_r.data = [student]
|
cookies_data.data.register_r.data = [student];
|
||||||
sessionStorage.setItem('cookies_data', JSON.stringify(cookies_data));
|
sessionStorage.setItem('cookies_data', JSON.stringify(cookies_data));
|
||||||
window.location.href = '/content/'
|
window.location.href = '/content/';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,6 +215,8 @@ const sendMessage = () => {
|
||||||
'subject': subject_,
|
'subject': subject_,
|
||||||
'content': content_
|
'content': content_
|
||||||
}
|
}
|
||||||
|
console.log(cookies_data)
|
||||||
|
console.log(recipient_)
|
||||||
fetch(url = '../api/messages/send', {
|
fetch(url = '../api/messages/send', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.shortcuts import render
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
def default_view(request, *args, **kwargs):
|
def default_view(request, *args, **kwargs):
|
||||||
|
request.session['has_session'] = True
|
||||||
return render(request, 'frontend/index.html')
|
return render(request, 'frontend/index.html')
|
||||||
|
|
||||||
def content_view(request, *args, **kwargs):
|
def content_view(request, *args, **kwargs):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.urls import reverse, resolve
|
from django.urls import reverse, resolve
|
||||||
from frontend.views import default_view, content_view
|
from frontend.views import default_view, content_view, account_manager_view
|
||||||
from app.views import login, grades, timetable, exams, homeworks, attendance, notes
|
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, school_data, dashboard, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, recipients, send, message_content
|
||||||
|
|
||||||
class TestUrls(SimpleTestCase):
|
class TestUrls(SimpleTestCase):
|
||||||
#views
|
#views
|
||||||
|
@ -13,6 +13,10 @@ class TestUrls(SimpleTestCase):
|
||||||
url = reverse('content')
|
url = reverse('content')
|
||||||
self.assertEquals(resolve(url).func, content_view)
|
self.assertEquals(resolve(url).func, content_view)
|
||||||
|
|
||||||
|
def test_account_manager_is_resolved(self):
|
||||||
|
url = reverse('account_manager')
|
||||||
|
self.assertEquals(resolve(url).func, account_manager_view)
|
||||||
|
|
||||||
#API
|
#API
|
||||||
def test_login_is_resolved(self):
|
def test_login_is_resolved(self):
|
||||||
url = reverse('login')
|
url = reverse('login')
|
||||||
|
@ -41,3 +45,45 @@ class TestUrls(SimpleTestCase):
|
||||||
def test_notes_is_resolved(self):
|
def test_notes_is_resolved(self):
|
||||||
url = reverse('notes')
|
url = reverse('notes')
|
||||||
self.assertEquals(resolve(url).func, notes)
|
self.assertEquals(resolve(url).func, notes)
|
||||||
|
|
||||||
|
def test_school_data_is_resolved(self):
|
||||||
|
url = reverse('school_data')
|
||||||
|
self.assertEquals(resolve(url).func, school_data)
|
||||||
|
|
||||||
|
def test_dashboard_is_resolved(self):
|
||||||
|
url = reverse('dashboard')
|
||||||
|
self.assertEquals(resolve(url).func, dashboard)
|
||||||
|
|
||||||
|
#MOBILE ACCESS
|
||||||
|
def test_registered_devices_is_resolved(self):
|
||||||
|
url = reverse('registered_devices')
|
||||||
|
self.assertEquals(resolve(url).func, registered_devices)
|
||||||
|
|
||||||
|
def test_register_device_is_resolved(self):
|
||||||
|
url = reverse('register_device')
|
||||||
|
self.assertEquals(resolve(url).func, register_device_)
|
||||||
|
|
||||||
|
#MESSAGES
|
||||||
|
def test_received_messages_is_resolved(self):
|
||||||
|
url = reverse('received_messages')
|
||||||
|
self.assertEquals(resolve(url).func, received_messages)
|
||||||
|
|
||||||
|
def test_sent_messages_is_resolved(self):
|
||||||
|
url = reverse('sent_messages')
|
||||||
|
self.assertEquals(resolve(url).func, sent_messages)
|
||||||
|
|
||||||
|
def test_deleted_messages_is_resolved(self):
|
||||||
|
url = reverse('deleted_messages')
|
||||||
|
self.assertEquals(resolve(url).func, deleted_messages)
|
||||||
|
|
||||||
|
def test_get_recipients_is_resolved(self):
|
||||||
|
url = reverse('recipients')
|
||||||
|
self.assertEquals(resolve(url).func, recipients)
|
||||||
|
|
||||||
|
def test_send_message_is_resolved(self):
|
||||||
|
url = reverse('send_message')
|
||||||
|
self.assertEquals(resolve(url).func, send)
|
||||||
|
|
||||||
|
def test_get_message_content_is_resolved(self):
|
||||||
|
url = reverse('message_content')
|
||||||
|
self.assertEquals(resolve(url).func, message_content)
|
|
@ -5,6 +5,7 @@ import json
|
||||||
class TestViews(TestCase):
|
class TestViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = Client()
|
self.client = Client()
|
||||||
|
self.csrf_token = Client(enforce_csrf_checks=True)
|
||||||
self.list_url = reverse('home')
|
self.list_url = reverse('home')
|
||||||
self.detail_url = reverse('content')
|
self.detail_url = reverse('content')
|
||||||
|
|
||||||
|
@ -19,3 +20,117 @@ class TestViews(TestCase):
|
||||||
response = self.client.get(self.detail_url)
|
response = self.client.get(self.detail_url)
|
||||||
|
|
||||||
self.assertEquals(response.status_code, 302)
|
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))
|
||||||
|
cookies_data = response.json()
|
||||||
|
|
||||||
|
self.assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
students = cookies_data['data']['register_r']['data']
|
||||||
|
#JAN
|
||||||
|
jan_data = students[0]
|
||||||
|
cookies_data['data']['register_r']['data'] = [jan_data]
|
||||||
|
get_data_test(self.client, cookies_data, self.assertEquals)
|
||||||
|
#JOANNA
|
||||||
|
joanna_data = students[3]
|
||||||
|
cookies_data['data']['register_r']['data'] = [joanna_data]
|
||||||
|
get_data_test(self.client, cookies_data, self.assertEquals)
|
||||||
|
|
||||||
|
|
||||||
|
def get_data_test(client, cookies_data, assertEquals):
|
||||||
|
#GRADES
|
||||||
|
response = client.post(reverse('grades'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#TIMETABLE
|
||||||
|
response = client.post(reverse('timetable'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#EXAMS
|
||||||
|
response = client.post(reverse('exams'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#HOMEWORKS
|
||||||
|
response = client.post(reverse('homeworks'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#ATTENDANCE
|
||||||
|
response = client.post(reverse('attendance'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#NOTES
|
||||||
|
response = client.post(reverse('notes'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#SCHOOL DATA
|
||||||
|
response = client.post(reverse('school_data'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#DASHBOARD
|
||||||
|
response = client.post(reverse('dashboard'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#MOBILE ACCESS
|
||||||
|
#REGISTERED DEVICES
|
||||||
|
response = client.post(reverse('registered_devices'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#REGISTER DEVICE
|
||||||
|
response = client.post(reverse('register_device'), content_type='application/xml', data=json.dumps(cookies_data))
|
||||||
|
assertEquals(response.status_code, 200)
|
||||||
|
|
||||||
|
#MESSAGES
|
||||||
|
#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']])
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
|
#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']])
|
||||||
|
|
||||||
|
#GET 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']
|
||||||
|
|
||||||
|
#SEND MESSAGE
|
||||||
|
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)
|
||||||
|
|
||||||
|
#GETTING MESSAGE CONTENT
|
||||||
|
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))
|
||||||
|
assertEquals(response.status_code, 200)
|
Loading…
Reference in a new issue