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