Fix: more api fixes (#10204)

This commit is contained in:
shamoon
2025-06-19 08:28:41 -07:00
committed by GitHub
parent 0a1786f39b
commit 83391af866
5 changed files with 183 additions and 16 deletions

View File

@@ -1278,3 +1278,34 @@ class TestBulkEditObjectPermissions(APITestCase):
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
class TestFullPermissionsFlag(APITestCase):
def setUp(self):
super().setUp()
self.admin = User.objects.create_superuser(username="admin")
def test_full_perms_flag(self):
"""
GIVEN:
- API request to list documents
WHEN:
- full_perms flag is set to true, 1, false, or a random value
THEN:
- Permissions field is included or excluded accordingly
"""
self.client.force_authenticate(self.admin)
Document.objects.create(title="Doc", checksum="xyz", owner=self.admin)
resp = self.client.get("/api/documents/?full_perms=true")
self.assertIn("permissions", resp.data["results"][0])
resp = self.client.get("/api/documents/?full_perms=1")
self.assertIn("permissions", resp.data["results"][0])
resp = self.client.get("/api/documents/?full_perms=false")
self.assertNotIn("permissions", resp.data["results"][0])
resp = self.client.get("/api/documents/?full_perms=garbage")
self.assertNotIn("permissions", resp.data["results"][0])

View File

@@ -394,6 +394,50 @@ class TestApiWorkflows(DirectoriesMixin, APITestCase):
self.assertEqual(workflow.triggers.first().filter_has_tags.first(), self.t1)
self.assertEqual(workflow.actions.first().assign_title, "Action New Title")
def test_api_update_workflow_no_trigger_actions(self):
"""
GIVEN:
- Existing workflow
WHEN:
- API request to update an existing workflow with no triggers and actions
- API request to update an existing workflow with empty actions and no triggers
THEN:
- No changes are made to the workflow
- Actions are removed, but triggers are not
"""
response = self.client.patch(
f"{self.ENDPOINT}{self.workflow.id}/",
json.dumps(
{
"name": "Workflow Updated",
"order": 1,
},
),
content_type="application/json",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
workflow = Workflow.objects.get(id=self.workflow.id)
self.assertEqual(workflow.name, "Workflow Updated")
self.assertEqual(workflow.triggers.count(), 1)
self.assertEqual(workflow.actions.count(), 1)
response = self.client.patch(
f"{self.ENDPOINT}{self.workflow.id}/",
json.dumps(
{
"name": "Workflow Updated 2",
"order": 1,
"actions": [],
},
),
content_type="application/json",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
workflow = Workflow.objects.get(id=self.workflow.id)
self.assertEqual(workflow.name, "Workflow Updated 2")
self.assertEqual(workflow.triggers.count(), 1)
self.assertEqual(workflow.actions.count(), 0)
def test_api_auto_remove_orphaned_triggers_actions(self):
"""
GIVEN:
@@ -630,3 +674,63 @@ class TestApiWorkflows(DirectoriesMixin, APITestCase):
content_type="application/json",
)
self.assertEqual(response.status_code, expected_resp_code)
def test_patch_trigger_cannot_change_id(self):
"""
GIVEN:
- An existing workflow trigger
- An existing workflow action
WHEN:
- PATCHing the trigger with a different 'id' in the body
- PATCHing the action with a different 'id' in the body
THEN:
- HTTP 400 error is returned
"""
response = self.client.patch(
f"/api/workflow_triggers/{self.trigger.id}/",
{
"id": self.trigger.id + 1,
"filter_filename": "patched.pdf",
},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.trigger.refresh_from_db()
self.assertNotEqual(self.trigger.filter_filename, "patched.pdf")
response = self.client.patch(
f"/api/workflow_triggers/{self.trigger.id}/",
{
"id": self.trigger.id,
"filter_filename": "patched.pdf",
},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.trigger.refresh_from_db()
self.assertEqual(self.trigger.filter_filename, "patched.pdf")
response = self.client.patch(
f"/api/workflow_actions/{self.action.id}/",
{
"id": self.action.id + 1,
"assign_title": "Patched Title",
},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.action.refresh_from_db()
self.assertNotEqual(self.action.assign_title, "Patched Title")
response = self.client.patch(
f"/api/workflow_actions/{self.action.id}/",
{
"id": self.action.id,
"assign_title": "Patched Title",
},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.action.refresh_from_db()
self.assertEqual(self.action.assign_title, "Patched Title")