mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 05:45:59 +01:00
complete api tests
This commit is contained in:
80
api/tests.py
80
api/tests.py
@@ -68,3 +68,83 @@ class TestAPI(TestCase):
|
|||||||
exists = 1
|
exists = 1
|
||||||
|
|
||||||
self.assertEqual(exists, 1)
|
self.assertEqual(exists, 1)
|
||||||
|
|
||||||
|
def test_getUserInfo(self):
|
||||||
|
|
||||||
|
## Login
|
||||||
|
|
||||||
|
data_ret = {'adminUser': 'admin', 'adminPass': '1234567', 'username': 'admin'}
|
||||||
|
response = self.MakeRequest('getUserInfo', data_ret)
|
||||||
|
|
||||||
|
self.assertEqual(response['status'], 1)
|
||||||
|
|
||||||
|
def test_changeUserPassAPI(self):
|
||||||
|
|
||||||
|
## Login
|
||||||
|
|
||||||
|
data_ret = {'adminUser': 'admin', 'adminPass': '1234567', 'websiteOwner': 'admin', 'ownerPassword': '1234567'}
|
||||||
|
response = self.MakeRequest('changeUserPassAPI', data_ret)
|
||||||
|
|
||||||
|
self.assertEqual(response['changeStatus'], 1)
|
||||||
|
|
||||||
|
def test_changePackageAPI(self):
|
||||||
|
|
||||||
|
## Login
|
||||||
|
|
||||||
|
data_ret = {'adminUser': 'admin', 'adminPass': '1234567', 'websiteName': 'cyberpanel.xyz', 'packageName': 'Default'}
|
||||||
|
response = self.MakeRequest('changePackageAPI', data_ret)
|
||||||
|
|
||||||
|
self.assertEqual(response['changePackage'], 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_submitWebsiteStatus(self):
|
||||||
|
|
||||||
|
## Suspend check
|
||||||
|
data_ret = {'adminUser': 'admin', 'adminPass': '1234567', 'websiteName': 'cyberpanel.xyz', 'state': 'Suspend'}
|
||||||
|
|
||||||
|
response = self.MakeRequest('submitWebsiteStatus', data_ret)
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
self.assertEqual(response['websiteStatus'], 1)
|
||||||
|
|
||||||
|
exists = 0
|
||||||
|
|
||||||
|
if self.MakeRequestRaw('http://cyberpanel.xyz').find('404') > -1 or self.MakeRequestRaw(
|
||||||
|
'http://cyberpanel.xyz').find('Access to this resource on the server is denied!') > -1:
|
||||||
|
exists = 1
|
||||||
|
|
||||||
|
self.assertEqual(exists, 1)
|
||||||
|
|
||||||
|
suspend = 0
|
||||||
|
import os
|
||||||
|
if os.path.exists('/usr/local/lsws/conf/vhosts/cyberpanel.xyz-suspended'):
|
||||||
|
suspend = 1
|
||||||
|
|
||||||
|
self.assertEqual(suspend, 1)
|
||||||
|
|
||||||
|
## Unsuspend check
|
||||||
|
|
||||||
|
data_ret = {'adminUser': 'admin', 'adminPass': '1234567', 'websiteName': 'cyberpanel.xyz', 'state': 'Unsuspend'}
|
||||||
|
|
||||||
|
response = self.MakeRequest('submitWebsiteStatus', data_ret)
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
self.assertEqual(response['websiteStatus'], 1)
|
||||||
|
|
||||||
|
exists = 0
|
||||||
|
|
||||||
|
if self.MakeRequestRaw('http://cyberpanel.xyz').find('CyberPanel') > -1:
|
||||||
|
exists = 1
|
||||||
|
|
||||||
|
self.assertEqual(exists, 1)
|
||||||
|
|
||||||
|
suspend = 0
|
||||||
|
import os
|
||||||
|
if os.path.exists('/usr/local/lsws/conf/vhosts/cyberpanel.xyz'):
|
||||||
|
suspend = 1
|
||||||
|
|
||||||
|
self.assertEqual(suspend, 1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ def getUserInfo(request):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
user = Administrator.objects.get(userName=username)
|
user = Administrator.objects.get(userName=username)
|
||||||
data_ret = {'status': 0,
|
data_ret = {'status': 1,
|
||||||
'firstName': user.firstName,
|
'firstName': user.firstName,
|
||||||
'lastName': user.lastName,
|
'lastName': user.lastName,
|
||||||
'email': user.email,
|
'email': user.email,
|
||||||
@@ -145,8 +145,6 @@ def changeUserPassAPI(request):
|
|||||||
websiteOwn.password = hashPassword.hash_password(ownerPassword)
|
websiteOwn.password = hashPassword.hash_password(ownerPassword)
|
||||||
websiteOwn.save()
|
websiteOwn.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_ret = {'changeStatus': 1, 'error_message': "None"}
|
data_ret = {'changeStatus': 1, 'error_message': "None"}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user