I have a Django project with the following urlpattern defined on project level:
urlpatterns = [
path('', include(('ws_shopify.urls', 'ws_shopify'), namespace='shopify')),
]
The file ws_shopify.urls
defines the following urlpatterns:
urlpatterns = [
path('api/shopify/', ShopifyWebhookAPIView.as_view(), name='webhook'),
]
The class ShopifyWebhookAPIView
defines the following endpoint:
from rest_framework.views import APIView
class ShopifyWebhookAPIView(APIView):
@action(detail=False, methods=['post'], url_path='(?P<webshop_name>.+)/order_created', name='order-created')
def order_created(self, request: Request, webshop_name=None):
return Response({'message': f'Order created for {webshop_name}'})
My question is:
What is the correct name of this endpoint to be used in a test case using reverse()
?
I am trying this now:
class WebhookTestCase(TestCase):
def test_that_url_resolves(self):
url = reverse('shopify:webhook:order-created', kwargs={'webshop_name': 'my-shop'})
self.assertEqual(url, '/api/shopify/my-shop/order_created')
But this fails with the following error message:
django.urls.exceptions.NoReverseMatch: 'webhook' is not a registered namespace inside 'shopify'