Skip to content

Commit

Permalink
Fix query by uncatigorized
Browse files Browse the repository at this point in the history
  • Loading branch information
timthelion committed Feb 11, 2020
1 parent 74450e9 commit bb9d886
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
12 changes: 6 additions & 6 deletions helpdesk/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def get_datatables_context(self, **kwargs):
"""
objects = self.get()
order_by = '-date_created'
draw = int(kwargs.get('draw', None)[0])
length = int(kwargs.get('length', None)[0])
start = int(kwargs.get('start', None)[0])
search_value = kwargs.get('search[value]', None)[0]
order_column = kwargs.get('order[0][column]', None)[0]
order = kwargs.get('order[0][dir]', None)[0]
draw = int(kwargs.get('draw', [0])[0])
length = int(kwargs.get('length', [25])[0])
start = int(kwargs.get('start', [0])[0])
search_value = kwargs.get('search[value]', [""])[0]
order_column = kwargs.get('order[0][column]', ['5'])[0]
order = kwargs.get('order[0][dir]', ["asc"])[0]

order_column = DATATABLES_ORDER_COLUMN_CHOICES[order_column]
# django orm '-' -> desc
Expand Down
103 changes: 103 additions & 0 deletions helpdesk/tests/test_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse

from helpdesk.models import KBCategory, KBItem, Queue, Ticket
from helpdesk.query import query_to_base64

from helpdesk.tests.helpers import (get_staff_user, reload_urlconf, User, create_ticket, print_response)


class QueryTests(TestCase):
def setUp(self):
self.queue = Queue.objects.create(
title="Test queue",
slug="test_queue",
allow_public_submission=True,
)
self.queue.save()
cat = KBCategory.objects.create(
title="Test Cat",
slug="test_cat",
description="This is a test category",
queue=self.queue,
)
cat.save()
self.kbitem1 = KBItem.objects.create(
category=cat,
title="KBItem 1",
question="What?",
answer="A KB Item",
)
self.user = get_staff_user()
self.ticket1 = Ticket.objects.create(
title="unassigned to kbitem",
queue=self.queue,
description="lol",
)
self.ticket1.save()
self.ticket2 = Ticket.objects.create(
title="assigned to kbitem",
queue=self.queue,
description="lol",
kbitem=self.kbitem1,
)
self.ticket2.save()

def loginUser(self, is_staff=True):
"""Create a staff user and login"""
User = get_user_model()
self.user = User.objects.create(
username='User_1',
is_staff=is_staff,
)
self.user.set_password('pass')
self.user.save()
self.client.login(username='User_1', password='pass')

def test_query_basic(self):
self.loginUser()
query = query_to_base64({})
response = self.client.get(reverse('helpdesk:datatables_ticket_list', args=[query]))
self.assertEqual(
response.json(),
{"data":
[{"ticket": "1 [test_queue-1]", "id": 1, "priority": 3, "title": "unassigned to kbitem", "queue": {"title": "Test queue", "id": 1}, "status": "Open", "created": "now", "due_date": None, "assigned_to": "None", "submitter": None, "row_class": "", "time_spent": "", "kbitem": ""},
{"ticket": "2 [test_queue-2]", "id": 2, "priority": 3, "title": "assigned to kbitem", "queue": {"title": "Test queue", "id": 1}, "status": "Open", "created": "now", "due_date": None, "assigned_to": "None", "submitter": None, "row_class": "", "time_spent": "", "kbitem": "KBItem 1"}],
"recordsFiltered": 2,
"recordsTotal": 2,
"draw": 0,
},
)

def test_query_by_kbitem(self):
self.loginUser()
query = query_to_base64(
{'filtering': {'kbitem__in': [self.kbitem1.pk]}}
)
response = self.client.get(reverse('helpdesk:datatables_ticket_list', args=[query]))
self.assertEqual(
response.json(),
{"data":
[{"ticket": "2 [test_queue-2]", "id": 2, "priority": 3, "title": "assigned to kbitem", "queue": {"title": "Test queue", "id": 1}, "status": "Open", "created": "now", "due_date": None, "assigned_to": "None", "submitter": None, "row_class": "", "time_spent": "", "kbitem": "KBItem 1"}],
"recordsFiltered": 1,
"recordsTotal": 1,
"draw": 0,
},
)

def test_query_by_no_kbitem(self):
self.loginUser()
query = query_to_base64(
{'filtering_or': {'kbitem__in': [self.kbitem1.pk]}}
)
response = self.client.get(reverse('helpdesk:datatables_ticket_list', args=[query]))
self.assertEqual(
response.json(),
{"data":
[{"ticket": "2 [test_queue-2]", "id": 2, "priority": 3, "title": "assigned to kbitem", "queue": {"title": "Test queue", "id": 1}, "status": "Open", "created": "now", "due_date": None, "assigned_to": "None", "submitter": None, "row_class": "", "time_spent": "", "kbitem": "KBItem 1"}],
"recordsFiltered": 1,
"recordsTotal": 1,
"draw": 0,
},
)
2 changes: 2 additions & 0 deletions helpdesk/views/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,8 @@ def ticket_list(request):
pattern_pks = [int(pattern) for pattern in patterns]
if -1 in pattern_pks:
query_params['filtering_or'][filter_null_params[param]] = True
else:
query_params['filtering_or'][filter_command] = pattern_pks
query_params['filtering'][filter_command] = pattern_pks
except ValueError:
pass
Expand Down
4 changes: 4 additions & 0 deletions quicktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class QuickDjangoTest(object):
'django.contrib.sites',
'django.contrib.staticfiles',
'bootstrap4form',
'account',
'pinax.invitations',
'pinax.teams',
'helpdesk',
'reversion',
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
Expand Down

0 comments on commit bb9d886

Please sign in to comment.