Commit 084c82a0 authored by Marten Kenbeek's avatar Marten Kenbeek
Browse files

Added filtered list view for registered action.

parent 2d3c6516
......@@ -8,4 +8,10 @@ app_name = "courses-api"
router = DefaultRouter()
router.register("courses", CourseViewSet)
router.register("actions", RegisteredActionViewSet)
urlpatterns = router.urls
urlpatterns = router.urls + [
path(
"actions/<slug:platform>/<slug:course_id>/",
RegisteredActionViewSet.as_view({"get": "list"}),
name="registeredaction-list",
)
]
......@@ -17,4 +17,7 @@ class RegisteredActionViewSet(ModelViewSet):
permission_classes = [IsAuthenticated]
def get_queryset(self):
return super().get_queryset().filter(course__user=self.request.user)
queryset = super().get_queryset().filter(course__user=self.request.user)
if "course_id" in self.kwargs:
queryset = queryset.filter(course_id=self.kwargs["course_id"])
return queryset
......@@ -25,7 +25,13 @@ register(
register(UserFactory, "_teacher", email="teacher@example.com", role=User.TEACHER)
register(UserFactory, "qdt", email="qdt@example.com", role=User.QDT)
register(CourseFactory)
register(RegisteredActionFactory)
register(RegisteredActionFactory, "_registered_action")
@pytest.fixture
def registered_action(teacher, _registered_action):
teacher.courses.add(_registered_action.course)
return _registered_action
@pytest.fixture
......
......@@ -7,7 +7,7 @@ def test_can_view_course(admin_api_client, course):
response = admin_api_client.get(
reverse("courses-api:course-detail", kwargs={"pk": course.pk})
)
assert response.status_code == 200, "could not get course detail"
assert response.status_code == 200, str(response.content)
assert response.data == {
"pk": course.pk,
"course_id": course.course_id,
......@@ -18,13 +18,12 @@ def test_can_view_course(admin_api_client, course):
@pytest.mark.django_db
def test_can_view_registered_action(teacher, teacher_api_client, registered_action):
teacher.courses.add(registered_action.course)
response = teacher_api_client.get(
reverse(
"courses-api:registeredaction-detail", kwargs={"pk": registered_action.pk}
)
)
assert response.status_code == 200, "could not get registered_action detail"
assert response.status_code == 200, str(response.content)
assert response.data == {
"course_id": registered_action.course_id,
"date": "2017-07-16",
......@@ -32,3 +31,14 @@ def test_can_view_registered_action(teacher, teacher_api_client, registered_acti
"pk": registered_action.pk,
"title": "Updated quiz 1",
}, "view did not return correct data"
@pytest.mark.django_db
def test_can_filter_action_list(teacher, teacher_api_client, registered_action):
response = teacher_api_client.get(
reverse(
"courses-api:registeredaction-list",
kwargs={"platform": "coursera", "course_id": registered_action.course_id},
)
)
assert response.status_code == 200, str(response.content)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment