Skip to content

Commit a6d95fb

Browse files
committed
Fix failing tests
1 parent 74dd129 commit a6d95fb

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

exercise/api/mixins.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.http import Http404
1+
from rest_framework.exceptions import NotFound
22

33
from authorization.api.mixins import ApiResourceMixin
44
from authorization.permissions import ACCESS
@@ -26,7 +26,7 @@ class ExerciseBaseResourceMixin(ExerciseRevealRuleMixin,
2626
def get_exercise_object(self):
2727
exercise = self.get_object_or_none(self.exercise_kw, LearningObject)
2828
if not exercise:
29-
raise Http404("Learning object not found")
29+
raise NotFound("Learning object not found")
3030
return exercise
3131

3232
def get_course_module_object(self):
@@ -55,7 +55,7 @@ class SubmissionBaseResourceMixin(ExerciseBaseResourceMixin,
5555
def get_submission_object(self):
5656
submission = self.get_object_or_none(self.submission_kw, Submission)
5757
if not submission:
58-
raise Http404("Submission not found")
58+
raise NotFound("Submission not found")
5959
return submission
6060

6161
def get_exercise_object(self):

exercise/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import urllib
33
from datetime import datetime, timedelta
44
from io import BytesIO, StringIO
5+
from unittest.mock import patch
56

67
from django.conf import settings
78
from django.contrib.auth.models import User
@@ -823,7 +824,7 @@ def test_uploading_and_viewing_file(self):
823824
py_file = StringIO('print("Tekijät ja Hyyppö")')
824825
py_file.name = 'test.py'
825826

826-
with png_file, py_file:
827+
with png_file, py_file, patch('exercise.exercise_models.load_feedback_page'):
827828
response = self.client.post(exercise.get_absolute_url(), {
828829
"key": "value",
829830
"file1": png_file,

userprofile/api/views.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from rest_framework.settings import api_settings
55

66
from lib.api.mixins import ListSerializerMixin, MeUserMixin
7+
from lib.api.filters import FieldValuesFilter
8+
79
from lib.api.constants import REGEX_INT_ME
810

911
from ..models import UserProfile
@@ -37,7 +39,13 @@ class UserViewSet(ListSerializerMixin,
3739
filter_backends = (
3840
IsTeacherOrAdminOrSelf,
3941
filters.SearchFilter,
42+
FieldValuesFilter,
4043
)
44+
field_values_map = {
45+
'id': 'user_id',
46+
'student_id': 'student_id',
47+
'email': 'user__email',
48+
}
4149
search_fields = ['=user__email']
4250
lookup_field = 'user_id' # UserProfile.user.id
4351
lookup_url_kwarg = 'user_id'
@@ -54,8 +62,11 @@ def get_queryset(self):
5462
queryset = super().get_queryset()
5563

5664
# Only restrict the list endpoint
57-
if getattr(self, 'action', None) == 'list' and not self.request.query_params.get('search'):
58-
return queryset.none()
65+
if getattr(self, 'action', None) == 'list':
66+
has_search = self.request.query_params.get('search')
67+
has_field_filter = self.request.query_params.get('field')
68+
if not (has_search or has_field_filter):
69+
return queryset.none()
5970

6071
return queryset
6172

0 commit comments

Comments
 (0)