Coverage for articles/tests/test_urls.py: 93.75%

16 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-13 16:37 -0700

1import pytest 

2from django.urls import resolve, reverse 

3 

4from .factories import ArticleFactory 

5 

6pytestmark = pytest.mark.django_db 

7 

8 

9@pytest.fixture 

10def article(): 

11 return ArticleFactory() 

12 

13 

14def test_article_list_reverse(): 

15 """article_list should reverse to /articles/.""" 

16 assert reverse("article_list") == "/articles/" 1b

17 

18 

19def test_article_list_resolve(): 

20 """/articles/" should resolve to article_list.""" 

21 assert resolve("/articles/").view_name == "article_list" 1c

22 

23 

24def test_article_add_reverse(): 

25 """article_new should reverse to /articles/new/.""" 

26 assert reverse("article_new") == "/articles/new/" 1d

27 

28 

29def test_article_add_resolve(): 

30 """/articles/new/" should resolve to article_new.""" 

31 assert resolve("/articles/new/").view_name == "article_new" 1e

32 

33 

34# TODO Revisit ArticleFactory() construction & build an appropriate slug to test 

35""" 

36def test_article_detail_reverse(article): 

37 # article_detail should reverse to /articles/uuid. 

38 url = reverse("article_detail", kwargs={"pk": article.id}) 

39 assert url == f"/articles/{article.id}/" 

40 

41 

42def test_article_detail_resolve(article): 

43 # /articles/{article.id}/ should resolve to article_detail. 

44 url = f"/articles/{article.id}/" 

45 assert resolve(url).view_name == "article_detail" 

46"""