Repository: ddionrails/ddionrails

Issue:
Remove StudyRedirectView
~blocked by: #126~


Discussion:

Resolving patch:
diff --git a/config/urls.py b/config/urls.py
--- a/config/urls.py
+++ b/config/urls.py
@@ -13,7 +13,7 @@
 from config.views import HomePageView
 from ddionrails.concepts.views import TopicRedirectView
 from ddionrails.data.views import VariableRedirectView
-from ddionrails.studies.views import StudyDetailView, StudyRedirectView, study_topics
+from ddionrails.studies.views import StudyDetailView, study_topics
 
 # These variable names are desired by Django
 handler400 = "config.views.bad_request"  # pylint: disable=invalid-name
@@ -83,7 +83,6 @@
         instruments_views.QuestionRedirectView.as_view(),
         name="question_redirect",
     ),
-    path("study/<uuid:id>", StudyRedirectView.as_view(), name="study_redirect"),
 ]
 
 if settings.DEBUG:
diff --git a/ddionrails/studies/views.py b/ddionrails/studies/views.py
--- a/ddionrails/studies/views.py
+++ b/ddionrails/studies/views.py
@@ -6,7 +6,6 @@
 from django.http.response import HttpResponse
 from django.shortcuts import get_object_or_404, render
 from django.views.generic import DetailView
-from django.views.generic.base import RedirectView
 
 from ddionrails.data.models import Dataset, Variable
 from ddionrails.instruments.models import Instrument, Question
@@ -14,16 +13,6 @@
 from .models import Study
 
 
-class StudyRedirectView(RedirectView):
-    """ RedirectView for studies.Study model """
-
-    permanent = False
-
-    def get_redirect_url(self, *args, **kwargs):
-        study = get_object_or_404(Study, id=kwargs["id"])
-        return study.get_absolute_url()
-
-
 class StudyDetailView(DetailView):
     """ DetailView for studies.Study model """
 


Test patch:
diff --git a/tests/studies/test_views.py b/tests/studies/test_views.py
--- a/tests/studies/test_views.py
+++ b/tests/studies/test_views.py
@@ -4,28 +4,13 @@
 """ Test cases for views in ddionrails.studies app """
 
 import pytest
-from django.http.response import Http404
 from django.urls import reverse
 
-from ddionrails.studies.views import StudyDetailView, StudyRedirectView
 from tests import status
 
 pytestmark = [pytest.mark.studies, pytest.mark.views]
 
-
-class TestStudyRedirectView:
-    def test_study_redirect(self, rf, study):
-        request = rf.get("study", kwargs={"pk": study.pk})
-        response = StudyRedirectView.as_view()(request, id=study.pk)
-
-        assert status.HTTP_302_FOUND == response.status_code
-
-    @pytest.mark.django_db
-    def test_study_redirect_invalid_id(self, rf):
-        invalid_study_id = 999
-        request = rf.get("study", kwargs={"pk": invalid_study_id})
-        with pytest.raises(Http404):
-            StudyRedirectView.as_view()(request, id=invalid_study_id)
+LANGUAGE = "en"
 
 
 class TestStudyDetailView:
@@ -44,24 +29,27 @@ def test_study_detail_view_with_existing_study_pk(self, client, study):
         assert expected_instruments == output_instruments
 
     @pytest.mark.django_db
-    def test_study_detail_view_with_non_existing_study_name(self, rf):
+    def test_study_detail_view_with_non_existing_study_name(self, client):
         non_existing_study_name = "not-in-database"
         url = reverse("study_detail", kwargs={"study_name": non_existing_study_name})
-        request = rf.get(url)
-        with pytest.raises(Http404):
-            StudyDetailView.as_view()(request, study_name=non_existing_study_name)
+        response = client.get(url)
+        assert status.HTTP_404_NOT_FOUND == response.status_code
 
 
-# class TestStudyTopicsView:
-#     def test_study_topics_view_with_existing_study_name(self, rf, study):
-#         url = reverse("study.topics", kwargs={"study_name": study.name})
-#         request = rf.get(url)
-#         response = study_topics(request, study_name=study.name)
-#         assert response.status_code == 200
-#
-#     def test_study_topics_view_with_non_existing_study_name(self, rf, db):
-#         non_existing_study_name = "not-in-database"
-#         url = reverse("study.topics", kwargs={"study_name": non_existing_study_name})
-#         request = rf.get(url)
-#         with pytest.raises(Http404):
-#             study_topics(request, study_name=non_existing_study_name)
+class TestStudyTopicsView:
+    def test_study_topics_view_with_existing_study_name(self, client, study):
+        url = reverse(
+            "study_topics", kwargs={"study_name": study.name, "language": LANGUAGE}
+        )
+        response = client.get(url)
+        assert status.HTTP_200_OK == response.status_code
+
+    @pytest.mark.django_db
+    def test_study_topics_view_with_non_existing_study_name(self, client):
+        non_existing_study_name = "not-in-database"
+        url = reverse(
+            "study_topics",
+            kwargs={"study_name": non_existing_study_name, "language": LANGUAGE},
+        )
+        response = client.get(url)
+        assert status.HTTP_404_NOT_FOUND == response.status_code