Skip to content

Commit

Permalink
started on fix for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl committed Nov 11, 2024
1 parent f644199 commit 377aa3e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/feedback/filters/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FeedbackFilter(filters.FilterSet):

feedback_type = filters.CharFilter(
method="fiter_feedback_type", label="List of feedback type"
method="filter_feedback_type", label="List of feedback type"
)

status = filters.ModelChoiceFilter(
Expand All @@ -27,7 +27,7 @@ class FeedbackFilter(filters.FilterSet):
)
)

def fiter_feedback_type(self, queryset, _name, feedback_type):
def filter_feedback_type(self, queryset, _name, feedback_type):

if feedback_type == "Idea":
return queryset.filter(Q(instance_of=Idea))
Expand Down
2 changes: 0 additions & 2 deletions app/feedback/models/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@


class Bug(Feedback):
pass

url = models.URLField(max_length=200, blank=True, null=True)
browser = models.CharField(max_length=200, default="")
platform = models.CharField(max_length=200, default="")
2 changes: 2 additions & 0 deletions app/feedback/views/feedback.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import filters, status
from rest_framework.response import Response
from django_filters.rest_framework import DjangoFilterBackend

from app.common.pagination import BasePagination
from app.common.permissions import BasicViewPermission
Expand All @@ -21,6 +22,7 @@ class FeedbackViewSet(BaseViewSet):
pagination_class = BasePagination
permission_classes = [BasicViewPermission]

filter_backends = [DjangoFilterBackend, filters.SearchFilter]
filterset_class = FeedbackFilter
search_fields = [
"title",
Expand Down
17 changes: 9 additions & 8 deletions app/tests/feedback/test_feedback_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.feedback.factories.bug_factory import BugFactory
from app.feedback.factories.idea_factory import IdeaFactory
from app.util.test_utils import get_api_client
from app.feedback.enums import Status

FEEDBACK_BASE_URL = "/feedbacks/"

Expand Down Expand Up @@ -150,9 +151,6 @@ def test_destroy_your_own_feedback_as_member(member, type):

initial_response = client.post(url, data=data)

print(initial_response.data)
print(f"Author: {initial_response.data['author']}")

feedback_id = initial_response.data["id"]

url = f"{FEEDBACK_BASE_URL}{feedback_id}/"
Expand Down Expand Up @@ -281,17 +279,20 @@ def test_filter_feedback_type_as_member(member, feedback_type):
def test_status_filter_as_member(member):
"""A member should be able to filter feedbacks by status"""

BugFactory(author=member)
IdeaFactory(author=member)
BugFactory(author=member, status=Status.OPEN)
IdeaFactory(author=member, status=Status.OPEN)

url = f"{FEEDBACK_BASE_URL}?status=1"
url = f"{FEEDBACK_BASE_URL}?status={Status.OPEN}"
client = get_api_client(member)
response = client.get(url)

data = response.data

print(data)

results = data["results"]

assert response.status_code == status.HTTP_200_OK
assert data["count"] == 2
assert results[0]["status"] == "OPEN"
assert results[1]["status"] == "OPEN"
assert results[0]["status"] == Status.OPEN
assert results[1]["status"] == Status.OPEN

0 comments on commit 377aa3e

Please sign in to comment.