Skip to content

Commit

Permalink
fix: update content type in tests and error messages and correct HTML…
Browse files Browse the repository at this point in the history
… placeholder

- Updated test cases to include content_type='application/json' in POST requests.
- Modified error messages in AddReconNote view to remove checks for scan_history_id and subdomain_id.
- Corrected the placeholder text in the HTML input field for adding a to-do.
  • Loading branch information
psyray committed Sep 16, 2024
1 parent 7dddde2 commit 9056061
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions web/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,6 @@ def post(self, request):

if not title:
return Response({"status": False, "error": "Title is required."}, status=400)
if scan_history_id is None:
return Response({"status": False, "error": "Scan history is required."}, status=400)
if subdomain_id is None:
return Response({"status": False, "error": "Subdomain is required."}, status=400)
if not project:
return Response({"status": False, "error": "Project is required."}, status=400)

Expand Down
2 changes: 1 addition & 1 deletion web/recon_note/templates/note/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h5 class="task-heading"></h5>
<div class="compose-content" id="addTaskModalTitle">
<h5 class="">Add to-do</h5>
<form>
<input id="task" type="text" placeholder="to-do Title" class="form-control" name="task" required minlength="3" maxlength="100" pattern="[A-Za-z0-9\s\-_\.]+" title="Please enter only letters, numbers, spaces, dashes, underscores, or dots.">
<input id="task" type="text" placeholder="To-do Title" class="form-control" name="task" required minlength="3" maxlength="100" pattern="[A-Za-z0-9\s\-_\.]+" title="Please enter only letters, numbers, spaces, dashes, underscores, or dots.">
<div class="mt-2">
<label for="scanHistoryIDropdown" class="form-label">Select Scan History (Optional)</label>
<select class="w-100 form-control" id="scanHistoryIDropdown" data-toggle="select2" data-width="100%">
Expand Down
12 changes: 6 additions & 6 deletions web/recon_note/tests/test_recon_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_add_recon_note_success(self):
"description": "This is a new recon note",
"project": self.data_generator.project.slug,
}
response = self.client.post(api_url, data)
response = self.client.post(api_url, data, content_type='application/json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(response.json()["status"])

Expand All @@ -51,11 +51,11 @@ def test_add_recon_note_missing_data(self):
"title": "Incomplete Note",
"slug": self.data_generator.project.slug,
}
response = self.client.post(api_url, data)
response = self.client.post(api_url, data, content_type='application/json')
self.assertIn(response.status_code, [status.HTTP_400_BAD_REQUEST])
self.assertFalse(response.json()["status"])
self.assertIn("error", response.json())
self.assertEqual(response.json()["error"], "Subdomain ID is required.")
self.assertEqual(response.json()["error"], "Project is required.")

def test_list_recon_notes(self):
"""Test listing all recon notes."""
Expand All @@ -67,7 +67,7 @@ def test_delete_recon_note_success(self):
"""Test deleting a recon note successfully."""
api_url = reverse("delete_note")
data = {"id": self.todo_note.id}
response = self.client.post(api_url, data)
response = self.client.post(api_url, data, content_type='application/json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(response.json()["status"])
self.assertFalse(TodoNote.objects.filter(id=self.todo_note.id).exists())
Expand All @@ -76,6 +76,6 @@ def test_delete_recon_note_not_found(self):
"""Test deleting a recon note that does not exist."""
api_url = reverse("delete_note")
data = {"id": 99999} # Non-existent ID
response = self.client.post(api_url, data)
response = self.client.post(api_url, data, content_type='application/json')
self.assertIn(response.status_code, [status.HTTP_404_NOT_FOUND])
self.assertFalse(response.json()["status"])
self.assertFalse(response.json()["status"])

0 comments on commit 9056061

Please sign in to comment.