Refactored redundant endpoints into one with search queries (/profiles/:account_id?fields= & account-settings/:account_id?fields=)
Removed re_path routes, which is returning a template index.html on every request to the endpoint that doesn't have a handler, which is causing append slash behavior to not working (more details below)
Adjusted test cases to fit with the refactoring
Removal of re_path(r'.*', ) in mesh/urls.py
This removal is to allow the appending slash behavior to work properly
About appending slash behavior: with the current Django setup, Django is setting APPEND_SLASH = true as a default behavior. This allows the Django app to "append" slash on requests that don't have a trailing slash by permanently redirecting the request to the correct one. For example, we have an API endpoint at /example/helloworld/, when requesting to /example/helloworld, the Django app is expected to permanently redirect the request to /example/helloworld/, acting as an "append slash" behavior. But said re_path in mesh/urls.py is causing this redirect not to take place when a request to /example/helloworld is sent to the app, because the re_path takes priority and returns the user a template HTML file as a response instead of redirecting to /example/helloworld/.
By removing said re_path, the "append" slash behavior is working properly, allowing users to send requests to an endpoint with or without a trailing slash.
Testing with and without trailing slash
As mentioned above, the appending slash behavior, under the hood, is actually permanently redirecting requests to the correct one. So when we testing a request without the trailing slash, it will return a response with a status code 301
In test cases:
❌ Incorrect way of sending test request (without trailing slash):
from django.test import TestCase, Client
class YourTestClass(TestCase):
def setUp(self):
self.client = Client()
def your_test_case(self):
response = self.client.get("/accounts")
self.assertEqual(response.status_code, 200) # this will not pass ❌
This will causing failures as the response.status_code is 301 instead of 200, because the app is permanently redirect.
✅ Correct way of sending test requests (without trailing slash):
from django.test import TestCase, Client
class YourTestClass(TestCase):
def setUp(self):
self.client = Client()
def your_test_case(self):
response = self.client.get("/accounts", follow=True)
self.assertEqual(response.status_code, 200) # this will pass ✅
response = self.client.get("/accounts/")
self.assertEqual(response.status_code, 200) # this will pass ✅
Addresses #358
What I Did
/profiles/:account_id?fields=
&account-settings/:account_id?fields=
)re_path
routes, which is returning a templateindex.html
on every request to the endpoint that doesn't have a handler, which is causing append slash behavior to not working (more details below)Removal of
re_path(r'.*', )
inmesh/urls.py
APPEND_SLASH = true
as a default behavior. This allows the Django app to "append" slash on requests that don't have a trailing slash by permanently redirecting the request to the correct one. For example, we have an API endpoint at/example/helloworld/
, when requesting to/example/helloworld
, the Django app is expected to permanently redirect the request to/example/helloworld/
, acting as an "append slash" behavior. But saidre_path
inmesh/urls.py
is causing this redirect not to take place when a request to/example/helloworld
is sent to the app, because the re_path takes priority and returns the user a template HTML file as a response instead of redirecting to/example/helloworld/
.re_path
, the "append" slash behavior is working properly, allowing users to send requests to an endpoint with or without a trailing slash.Testing with and without trailing slash
As mentioned above, the appending slash behavior, under the hood, is actually permanently redirecting requests to the correct one. So when we testing a request without the trailing slash, it will return a response with a status code 301
In test cases:
❌ Incorrect way of sending test request (without trailing slash):
This will causing failures as the
response.status_code
is 301 instead of 200, because the app is permanently redirect.✅ Correct way of sending test requests (without trailing slash):