From 85c4125fb7c5e2e05bb37290993439ab98443fc8 Mon Sep 17 00:00:00 2001 From: Prixite Date: Tue, 11 Apr 2023 12:04:38 +0500 Subject: [PATCH 1/2] add missing test cases. --- app/tests/base.py | 9 +++++++ app/tests/test_employee.py | 16 +++++++++++++ app/tests/{folder.py => test_folder.py} | 15 ++++++++++++ app/tests/test_user.py | 32 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+) rename app/tests/{folder.py => test_folder.py} (87%) diff --git a/app/tests/base.py b/app/tests/base.py index 7ee2fc70..0e038199 100644 --- a/app/tests/base.py +++ b/app/tests/base.py @@ -1,3 +1,5 @@ +from datetime import datetime, timedelta + from django.test import TestCase from app import factories, models @@ -37,6 +39,7 @@ def setUp(self) -> None: is_default=True, organization=self.organization, ) + self.owner = factories.UserFactory( username="owner@example.com", email="owner@example.com", @@ -167,3 +170,9 @@ def setUp(self) -> None: self.folder = factories.FolderFactory() self.document = factories.DocumentFactory() + self.leave = factories.LeaveFactory( + employee=self.employee, + organization=self.organization, + leave_from=datetime.now(), + leave_to=datetime.now() + +timedelta(days=1), + ) diff --git a/app/tests/test_employee.py b/app/tests/test_employee.py index 249bed29..8320779e 100644 --- a/app/tests/test_employee.py +++ b/app/tests/test_employee.py @@ -175,6 +175,12 @@ def test_employee_list_neagtive(self): self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + def test_employee_delete(self): + self.client.force_login(self.owner) + response = self.client.delete(f"/api/employees/{self.employee.id}/") + + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + class CompensationTestCase(BaseTestCase): def test_compensation_post(self): @@ -881,6 +887,16 @@ def test_get_all_leaves(self): response = self.client.get("/api/attendance/?id=2") self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_leave_update(self): + self.client.force_login(self.owner) + data = { + "updated_by": self.owner.id, + "hr_comment": "leave approved.", + "status": "approved", + } + response = self.client.patch(f"/api/leave/{self.leave.id}/", data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + class StandupTestCase(BaseTestCase): def test_standup_get(self): diff --git a/app/tests/folder.py b/app/tests/test_folder.py similarity index 87% rename from app/tests/folder.py rename to app/tests/test_folder.py index 1d53a378..e51f613b 100644 --- a/app/tests/folder.py +++ b/app/tests/test_folder.py @@ -104,3 +104,18 @@ def test_document_delete(self): self.client.force_login(self.owner) response = self.client.delete(f"/api/documents/{self.document.id}/") self.assertEqual(response.status_code, 204) + +class AWSTestCase(BaseTestCase): + def test_aws_upload_file(self): + self.client.force_login(self.owner) + data = { + "filename": "test", + "filetype": ".jpg" + } + response = self.client.post("/api/aws_upload_file/", data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_aws_delete_upload_file(self): + self.client.force_login(self.owner) + response = self.client.delete("/api/aws_delete_file/key/") + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) \ No newline at end of file diff --git a/app/tests/test_user.py b/app/tests/test_user.py index 4bcaf250..6045be3b 100644 --- a/app/tests/test_user.py +++ b/app/tests/test_user.py @@ -21,11 +21,36 @@ def test_user_change_password_negative(self): response = self.client.patch("/api/change_password/", data=user_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + def test_user_reset_password(self): + data = {"email": "user@example.com"} + response = self.client.post("/api/password-reset/", data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_user_reset_password_negative(self): + data = {"email": "fake@example.com"} + response = self.client.post("/api/password-reset/", data=data) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + def test_login(self): login_data = {"email": "user@example.com", "password": "admin"} response = self.client.post("/api/login/", data=login_data) self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_login_invalid_credential(self): + login_data = {"email": "user@example.com", "password": "admin1"} + response = self.client.post("/api/login/", data=login_data) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + def test_delete_user(self): + self.client.force_login(self.owner) + response = self.client.delete(f"/api/users/{self.org_user.id}/") + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + + def test_delete_user_negative(self): + self.client.force_login(self.owner) + response = self.client.delete(f"/api/users/{self.owner.id}/") + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + def test_onboarding(self): onboarding_data = { "first_name": "Test", @@ -49,3 +74,10 @@ def test_get_user_filter_data(self): self.client.force_login(self.owner) response = self.client.get("/api/users/") self.assertEqual(response.status_code, status.HTTP_200_OK) + + +class UserModuleRoleTestCase(BaseTestCase): + def test_get_user_list(self): + self.client.force_login(self.owner) + response = self.client.get(f"/api/users/{self.owner.id}/access/") + self.assertEqual(response.status_code, status.HTTP_200_OK) From 73c46d817c0139ce62d035a9101bf57e5c4f2ced Mon Sep 17 00:00:00 2001 From: Prixite Date: Tue, 11 Apr 2023 12:07:08 +0500 Subject: [PATCH 2/2] fixes --- app/tests/test_folder.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/tests/test_folder.py b/app/tests/test_folder.py index e51f613b..34bbaa88 100644 --- a/app/tests/test_folder.py +++ b/app/tests/test_folder.py @@ -105,17 +105,15 @@ def test_document_delete(self): response = self.client.delete(f"/api/documents/{self.document.id}/") self.assertEqual(response.status_code, 204) + class AWSTestCase(BaseTestCase): def test_aws_upload_file(self): self.client.force_login(self.owner) - data = { - "filename": "test", - "filetype": ".jpg" - } + data = {"filename": "test", "filetype": ".jpg"} response = self.client.post("/api/aws_upload_file/", data=data) self.assertEqual(response.status_code, status.HTTP_200_OK) - + def test_aws_delete_upload_file(self): self.client.force_login(self.owner) response = self.client.delete("/api/aws_delete_file/key/") - self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) \ No newline at end of file + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)