2014-07-21 18:44:54 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-07-22 03:26:41 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
2022-07-22 03:26:41 +02:00
|
|
|
from helpdesk.models import Queue, Ticket, UserSettings
|
|
|
|
import sys
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-30 06:07:08 +02:00
|
|
|
|
2018-07-19 06:06:57 +02:00
|
|
|
User = get_user_model()
|
|
|
|
|
2014-07-21 18:44:54 +02:00
|
|
|
|
2019-03-20 13:47:57 +01:00
|
|
|
def get_user(username='helpdesk.staff',
|
|
|
|
password='password',
|
|
|
|
is_staff=False,
|
|
|
|
is_superuser=False):
|
2014-07-21 18:44:54 +02:00
|
|
|
try:
|
|
|
|
user = User.objects.get(username=username)
|
|
|
|
except User.DoesNotExist:
|
2019-03-20 13:47:57 +01:00
|
|
|
user = User.objects.create_user(username=username,
|
|
|
|
password=password,
|
|
|
|
email='%s@example.com' % username)
|
|
|
|
user.is_staff = is_staff
|
|
|
|
user.is_superuser = is_superuser
|
2014-07-21 18:44:54 +02:00
|
|
|
user.save()
|
|
|
|
else:
|
|
|
|
user.set_password(password)
|
|
|
|
user.save()
|
|
|
|
return user
|
|
|
|
|
|
|
|
|
2019-10-16 17:36:55 +02:00
|
|
|
def get_staff_user():
|
|
|
|
return get_user(is_staff=True)
|
|
|
|
|
|
|
|
|
2014-07-21 18:44:54 +02:00
|
|
|
def reload_urlconf(urlconf=None):
|
2015-11-18 15:07:33 +01:00
|
|
|
|
2018-12-28 09:13:52 +01:00
|
|
|
from importlib import reload
|
2015-11-18 15:07:33 +01:00
|
|
|
|
2014-07-21 18:44:54 +02:00
|
|
|
if urlconf is None:
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
urlconf = settings.ROOT_URLCONF
|
|
|
|
|
2015-11-06 15:22:44 +01:00
|
|
|
if HELPDESK_URLCONF in sys.modules:
|
|
|
|
reload(sys.modules[HELPDESK_URLCONF])
|
|
|
|
|
|
|
|
if urlconf in sys.modules:
|
2014-07-21 18:44:54 +02:00
|
|
|
reload(sys.modules[urlconf])
|
2015-11-06 15:22:44 +01:00
|
|
|
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import clear_url_caches
|
2015-11-06 15:22:44 +01:00
|
|
|
clear_url_caches()
|
|
|
|
|
|
|
|
|
2014-07-30 06:07:08 +02:00
|
|
|
def create_ticket(**kwargs):
|
|
|
|
q = kwargs.get('queue', None)
|
|
|
|
if q is None:
|
|
|
|
try:
|
|
|
|
q = Queue.objects.all()[0]
|
|
|
|
except IndexError:
|
|
|
|
q = Queue.objects.create(title='Test Q', slug='test', )
|
|
|
|
data = {
|
|
|
|
'title': "I wish to register a complaint",
|
|
|
|
'queue': q,
|
|
|
|
}
|
|
|
|
data.update(kwargs)
|
2017-10-30 08:17:40 +01:00
|
|
|
return Ticket.objects.create(**data)
|
|
|
|
|
|
|
|
|
2015-11-06 15:22:44 +01:00
|
|
|
HELPDESK_URLCONF = 'helpdesk.urls'
|
2018-08-30 12:03:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def print_response(response, stdout=False):
|
|
|
|
content = response.content.decode()
|
|
|
|
if stdout:
|
|
|
|
print(content)
|
|
|
|
else:
|
|
|
|
with open("response.html", "w") as f: # pragma: no cover
|
|
|
|
f.write(content) # pragma: no cover
|