test_saveResellerChangess

This commit is contained in:
Usman Nasir
2019-11-18 19:43:25 +05:00
parent 769155a0e6
commit 1acde8bc4a

View File

@@ -10,7 +10,7 @@ from loginSystem.models import Administrator
# Create your tests here. # Create your tests here.
class TestLogin(TestCase): class TestUserManagement(TestCase):
def setUp(self): def setUp(self):
## Initiate Client ## Initiate Client
@@ -22,9 +22,15 @@ class TestLogin(TestCase):
## Create Login User ## Create Login User
response = self.client.get(self.adminLogin) response = self.client.get(self.adminLogin)
self.assertTemplateUsed(response, 'loginSystem/login.html')
#
self.assertTemplateUsed(response, 'loginSystem/login.html')
self.submitUserCreation = reverse('submitUserCreation') self.submitUserCreation = reverse('submitUserCreation')
self.submitUserDeletion = reverse('submitUserDeletion')
self.saveModifications = reverse('saveModifications')
self.fetchUserDetails = reverse('fetchUserDetails')
self.saveResellerChanges = reverse('saveResellerChanges')
## Verify login ## Verify login
@@ -32,7 +38,6 @@ class TestLogin(TestCase):
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
response = self.client.post(self.verifyLogin, json_data, content_type="application/json") response = self.client.post(self.verifyLogin, json_data, content_type="application/json")
logging.writeToFile(response.content)
json_data = json.loads(response.content) json_data = json.loads(response.content)
self.assertEqual(json_data['loginStatus'], 1) self.assertEqual(json_data['loginStatus'], 1)
@@ -45,7 +50,6 @@ class TestLogin(TestCase):
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
response = self.client.post(self.submitUserCreation, json_data, content_type="application/json") response = self.client.post(self.submitUserCreation, json_data, content_type="application/json")
logging.writeToFile(response.content)
json_data = json.loads(response.content) json_data = json.loads(response.content)
@@ -54,5 +58,64 @@ class TestLogin(TestCase):
self.assertEqual(Administrator.objects.filter(userName='usman').count(), 1) self.assertEqual(Administrator.objects.filter(userName='usman').count(), 1)
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)