Files
CyberPanel/userManagment/tests.py

180 lines
6.5 KiB
Python
Raw Normal View History

2017-10-24 19:16:36 +05:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2019-11-18 14:27:49 +05:00
from django.test import TestCase, Client
from django.urls import reverse
import json
2019-11-18 20:20:47 +05:00
from loginSystem.models import Administrator, ACL
2019-11-18 14:27:49 +05:00
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
2017-10-24 19:16:36 +05:00
# Create your tests here.
2019-11-18 14:27:49 +05:00
2019-11-18 19:43:25 +05:00
class TestUserManagement(TestCase):
2019-11-18 14:27:49 +05:00
def setUp(self):
## Initiate Client
self.client = Client()
self.adminLogin = reverse('adminLogin')
self.verifyLogin = reverse('verifyLogin')
## Create Login User
response = self.client.get(self.adminLogin)
2019-11-18 19:43:25 +05:00
#
self.assertTemplateUsed(response, 'loginSystem/login.html')
2019-11-18 14:27:49 +05:00
self.submitUserCreation = reverse('submitUserCreation')
2019-11-18 19:43:25 +05:00
self.submitUserDeletion = reverse('submitUserDeletion')
self.saveModifications = reverse('saveModifications')
self.fetchUserDetails = reverse('fetchUserDetails')
self.saveResellerChanges = reverse('saveResellerChanges')
2019-11-18 20:20:47 +05:00
self.createACLFunc = reverse('createACLFunc')
2019-11-18 14:27:49 +05:00
## Verify login
data_ret = {'username': 'admin', 'password': '1234567'}
json_data = json.dumps(data_ret)
response = self.client.post(self.verifyLogin, json_data, content_type="application/json")
json_data = json.loads(response.content)
self.assertEqual(json_data['loginStatus'], 1)
def test_submitUserCreation(self):
## Login
data_ret = {'firstName': 'Usman', 'lastName': 'Nasir', 'email': 'usman@cyberpersons.com', 'userName': 'usman',
'password': '1234567', 'websitesLimit': 50, 'selectedACL':'user', 'securityLevel': 'HIGH'}
json_data = json.dumps(data_ret)
response = self.client.post(self.submitUserCreation, json_data, content_type="application/json")
json_data = json.loads(response.content)
self.assertEqual(json_data['status'], 1)
self.assertEqual(json_data['createStatus'], 1)
self.assertEqual(Administrator.objects.filter(userName='usman').count(), 1)
2019-11-18 19:43:25 +05:00
def test_submitUserDeletion(self):
self.test_submitUserCreation()
data_ret = {'accountUsername': 'usman'}
json_data = json.dumps(data_ret)
response = self.client.post(self.submitUserDeletion, json_data, content_type="application/json")
json_data = json.loads(response.content)
self.assertEqual(json_data['status'], 1)
self.assertEqual(json_data['deleteStatus'], 1)
self.assertEqual(Administrator.objects.filter(userName='usman').count(), 0)
def test_saveModifications(self):
self.test_submitUserCreation()
data_ret = {'accountUsername': 'usman','firstName': 'Rehan', 'lastName': 'Nasir', 'email': 'usman@cyberpersons.com',
'securityLevel': "LOW", 'password': '1234567'}
json_data = json.dumps(data_ret)
## Modification
response = self.client.post(self.saveModifications, json_data, content_type="application/json")
json_data = json.loads(response.content)
self.assertEqual(json_data['status'], 1)
self.assertEqual(json_data['saveStatus'], 1)
## Check Modification
# response = self.client.post(self.fetchUserDetails, json_data, content_type="application/json")
# logging.writeToFile(response.content)
# json_data = json.loads(response.content)
self.assertEqual(Administrator.objects.get(userName='usman').firstName, 'Rehan')
self.assertEqual(Administrator.objects.get(userName='usman').lastName, 'Nasir')
self.assertEqual(Administrator.objects.get(userName='usman').securityLevel, 1)
def test_saveResellerChangess(self):
self.test_submitUserCreation()
data_ret = {'newOwner': 'admin', 'userToBeModified':'usman', 'websitesLimit': 100}
json_data = json.dumps(data_ret)
## Modification
response = self.client.post(self.saveResellerChanges, json_data, content_type="application/json")
json_data = json.loads(response.content)
self.assertEqual(json_data['status'], 1)
## Check Modification
# response = self.client.post(self.fetchUserDetails, json_data, content_type="application/json")
# logging.writeToFile(response.content)
# json_data = json.loads(response.content)
self.assertEqual(Administrator.objects.get(userName='usman').initWebsitesLimit, 100)
2019-11-18 20:20:47 +05:00
def test_createACLFunc(self):
data_ret = {'aclName': 'hello', 'makeAdmin':1,
'createNewUser': 1,
'versionManagement': 1,
'listUsers': 1,
'resellerCenter': 1,
'deleteUser': 1,
'changeUserACL': 1,
'createWebsite': 1,
'modifyWebsite': 1,
'suspendWebsite': 1,
'deleteWebsite': 1,
'createPackage': 1,
'listPackages': 1,
'deletePackage': 1,
'modifyPackage': 1,
'createDatabase': 1,
'deleteDatabase': 1,
'listDatabases': 1,
'createNameServer': 1,
'createDNSZone': 1,
'deleteZone': 1,
'addDeleteRecords': 1,
'createEmail': 1,
'listEmails': 1,
'deleteEmail': 1,
'emailForwarding': 1,
'changeEmailPassword': 1,
'dkimManager': 1,
'createFTPAccount': 1,
'deleteFTPAccount': 1,
'listFTPAccounts': 1,
'createBackup': 1,
'restoreBackup': 1,
'addDeleteDestinations': 1,
'scheDuleBackups': 1,
'remoteBackups': 1,
'manageSSL': 1,
'hostnameSSL': 1,
'mailServerSSL': 1}
json_data = json.dumps(data_ret)
## Modification
response = self.client.post(self.createACLFunc, json_data, content_type="application/json")
json_data = json.loads(response.content)
self.assertEqual(json_data['status'], 1)
## Check Modification
# response = self.client.post(self.fetchUserDetails, json_data, content_type="application/json")
# logging.writeToFile(response.content)
# json_data = json.loads(response.content)
self.assertEqual(ACL.objects.filter(name='hello').count(), 1)
2019-11-18 14:27:49 +05:00