Skip to content

Commit

Permalink
Merge pull request #2 from saadmk11/fix-method-name
Browse files Browse the repository at this point in the history
Fix Method Name Generation
  • Loading branch information
saadmk11 authored Sep 7, 2024
2 parents ed3ee93 + b572ef1 commit a80f1b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions drf_test_generator/viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def build_request(self, http_method: str) -> str:
def build_test_method_name(
self, basename: str, action_name: str, http_method: str
) -> str:
basename = basename.replace("-", "_")
return f"test_{basename}_{action_name}_{http_method}"

def build_reverse(
Expand Down
26 changes: 13 additions & 13 deletions tests/test_viewset_test_generator_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PostViewSet(viewsets.ModelViewSet):
...

router = routers.DefaultRouter()
router.register("posts", PostViewSet, basename="post")
router.register("posts", PostViewSet, basename="blog-post")

expected_tests = textwrap.dedent(
"""\
Expand All @@ -28,43 +28,43 @@ class PostViewSet(viewsets.ModelViewSet):
@pytest.mark.django_db
def test_post_list_get(client):
url = reverse('post-list')
def test_blog_post_list_get(client):
url = reverse('blog-post-list')
response = client.get(url)
assert response.status_code == status.HTTP_200_OK
@pytest.mark.django_db
def test_post_create_post(client):
url = reverse('post-list')
def test_blog_post_create_post(client):
url = reverse('blog-post-list')
response = client.post(url, data={})
assert response.status_code == status.HTTP_201_CREATED
@pytest.mark.django_db
def test_post_retrieve_get(client):
url = reverse('post-detail', kwargs={'pk': None})
def test_blog_post_retrieve_get(client):
url = reverse('blog-post-detail', kwargs={'pk': None})
response = client.get(url)
assert response.status_code == status.HTTP_200_OK
@pytest.mark.django_db
def test_post_update_put(client):
url = reverse('post-detail', kwargs={'pk': None})
def test_blog_post_update_put(client):
url = reverse('blog-post-detail', kwargs={'pk': None})
response = client.put(url, data={})
assert response.status_code == status.HTTP_200_OK
@pytest.mark.django_db
def test_post_partial_update_patch(client):
url = reverse('post-detail', kwargs={'pk': None})
def test_blog_post_partial_update_patch(client):
url = reverse('blog-post-detail', kwargs={'pk': None})
response = client.patch(url, data={})
assert response.status_code == status.HTTP_200_OK
@pytest.mark.django_db
def test_post_destroy_delete(client):
url = reverse('post-detail', kwargs={'pk': None})
def test_blog_post_destroy_delete(client):
url = reverse('blog-post-detail', kwargs={'pk': None})
response = client.delete(url)
assert response.status_code == status.HTTP_204_NO_CONTENT
"""
Expand Down

0 comments on commit a80f1b2

Please sign in to comment.