From b572ef17a2e9213fe00825dd1e77052c7059dd8b Mon Sep 17 00:00:00 2001 From: Maksudul Haque Date: Sat, 7 Sep 2024 13:35:05 +0000 Subject: [PATCH] Fix Megod Name Generation --- drf_test_generator/viewset.py | 1 + tests/test_viewset_test_generator_pytest.py | 26 ++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drf_test_generator/viewset.py b/drf_test_generator/viewset.py index 1c00a23..8dc999f 100644 --- a/drf_test_generator/viewset.py +++ b/drf_test_generator/viewset.py @@ -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( diff --git a/tests/test_viewset_test_generator_pytest.py b/tests/test_viewset_test_generator_pytest.py index d7797e5..4d72ef7 100644 --- a/tests/test_viewset_test_generator_pytest.py +++ b/tests/test_viewset_test_generator_pytest.py @@ -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( """\ @@ -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 """