Commit 07c288cd authored by Marten Kenbeek's avatar Marten Kenbeek
Browse files

Fixed registered action creation.

parent 084c82a0
......@@ -11,6 +11,15 @@ class CourseSerializer(serializers.ModelSerializer):
class RegisteredActionSerializer(serializers.ModelSerializer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["course"].queryset = Course.objects.filter(
user=self.context["request"].user
)
course = serializers.SlugRelatedField("course_id", queryset=Course.objects.all())
class Meta:
model = RegisteredAction
fields = ["pk", "course_id", "title", "date", "description"]
fields = ["pk", "course", "title", "date", "description"]
......@@ -14,9 +14,16 @@ def test_can_serialize_course(course):
@pytest.mark.django_db
def test_can_serialize_registered_action(registered_action):
assert RegisteredActionSerializer(registered_action).data == {
"course_id": registered_action.course_id,
def test_can_serialize_registered_action(teacher, registered_action):
class Request:
pass
obj = Request()
obj.user = teacher
assert RegisteredActionSerializer(
registered_action, context={"request": obj}
).data == {
"course": registered_action.course_id,
"date": "2017-07-16",
"description": "Changed the second question in quiz 1 to make it clearer",
"pk": registered_action.pk,
......
......@@ -25,7 +25,7 @@ def test_can_view_registered_action(teacher, teacher_api_client, registered_acti
)
assert response.status_code == 200, str(response.content)
assert response.data == {
"course_id": registered_action.course_id,
"course": registered_action.course_id,
"date": "2017-07-16",
"description": "Changed the second question in quiz 1 to make it clearer",
"pk": registered_action.pk,
......@@ -42,3 +42,29 @@ def test_can_filter_action_list(teacher, teacher_api_client, registered_action):
)
)
assert response.status_code == 200, str(response.content)
@pytest.mark.django_db
def test_can_create_registered_action(teacher_api_client, teacher, course):
response = teacher_api_client.post(
reverse("courses-api:registeredaction-list"),
{
"course": course.course_id,
"date": "2017-09-20",
"title": "Title",
"description": "-",
},
)
assert response.status_code == 400, str(response.content)
teacher.courses.add(course)
response = teacher_api_client.post(
reverse("courses-api:registeredaction-list"),
{
"course": course.course_id,
"date": "2017-09-20",
"title": "Title",
"description": "-",
},
)
assert response.status_code == 201, 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