LetsMesh / Site

Repository for the Website named Let's Mesh
https://letsmesh.vercel.app
6 stars 2 forks source link

API Endpoints refactoring #359

Open blu3eee opened 3 weeks ago

blu3eee commented 3 weeks ago

Addresses #358

What I Did

Removal of re_path(r'.*', ) in mesh/urls.py

Testing with and without trailing slash

❌ 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 ✅