Reputation: 1059
in my app named backoffice_engine, my urls.py file is as follows
from django.urls import path, include
from . import views
urlpatterns = [
path('test/', views.test, name='test'),
path('', views.dashboard, name='dashboard'),
path('dashboard/', views.dashboard, name='dashboard'),
path('add_new_client/', views.add_new_client, name='add_new_client'),
path('edit_client/<int:client_id>', views.edit_client, name='edit_client'),
.....some more paths....
]
my test_urls.py file for this urls.py file is as follows
from django.test import SimpleTestCase
from django.urls import reverse, resolve
from backoffice_engine.views import *
class TestBackofficeEngineUrls(SimpleTestCase):
def test_test_url(self):
url = reverse('test')
self.assertEquals(resolve(url).func, test)
def test_blank_url_uses_dashboard_function(self):
url = reverse('dashboard')
self.assertEquals(resolve(url).func, dashboard)
def test_add_new_client(self):
url = reverse('add_new_client')
self.assertEquals(resolve(url).func, add_new_client)
def test_client_detail(self):
url = reverse('client_detail', args=['1'])
self.assertEquals(resolve(url).func, client_detail)
my understanding is runnning coverage on this file should result in coverage report showing that the following urls have been covered by unit tests.
however coverage report for backoffice_engine.urls.py is zero missing by default. the report only is checking only the first 3 lines of the urls.py file
Upvotes: 1
Views: 213
Reputation: 375854
Coverage can't tell you which url patterns were used. Line 4 is the start of one long multi-line statement which assigns all of the URL patterns. It is run just once, when urls.py is imported.
For example, line 7 isn't executed when you visit the "dashboard/" URL. It's executed when the program starts up, to add a pattern for "dashboard/" to the list of all patterns.
Upvotes: 0