class TicketActTest(APITestCase):
    def setUp(self):
        self.tkt = TicketAct()

    def test_create_issue(self):
        data = {
            'subject': 'Hi, this is a test subject',
            'content': 'and this is test content',
            'department': 2,
            'category': 1,
            'urgent': True
            }
        self.tkt.create_issue(data)
        self.assertEqual(TicketActivity.objects.all().count(), 1)

    def test_get_with_state(self):
        data = {
            'subject': 'Hi, this is a test subject',
            'content': 'and this is test content',
            'department': 3,
            'category': 1,
            'urgent': True
            }
        tkt_obj = self.tkt.create_issue(data)
        result = self.tkt.get_with_state(dept=3)
        expected_keys = {
            'subject',
            'content',
            'department',
            'category',
            'urgent',
            'uuid'
        }
        self.assertIsNotNone(result, expected_keys)
        self.assertEqual(result[0]['ticket_uuid'], tkt_obj.uuid)
 def get(self, request):
     dept = request.query_params.get('dept')
     cat = request.query_params.get('cat')
     state = request.query_params.get('status')
     urgent = request.query_params.get('urgent')
     response = TicketAct().get_with_state(dept, cat, state, urgent)
     return Response(response, status=status.HTTP_200_OK)
    def get(self, request):
        if len(request.query_params) is not 0:
            param = request.query_params.get('search')
            objs = TicketAct().new_search_implement(param)
            return render(request, 'searchpage.html', {'tkt_info': objs})
        objs = TicketAct().get_all_tickets()
        if 'message' in objs:
            return render(request, 'no_ticket.html')

        paginator = Paginator(objs, 15)  # Show 15 ticket per page
        page = request.GET.get('page')
        try:
            tickets = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            tickets = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results
            tickets = paginator.page(paginator.num_pages)

        return render(request, All_TICKET_TEMPLATE, {'tkt_info': tickets})
 def post(self, request):
     data = request.data
     response = TicketAct().assigne_ticket(data)
     return Response(response, status=status.HTTP_200_OK)
 def delete(self, request, ticket_uuid):
     TicketAct().delete_ticket(ticket_uuid)
     arg_num = reverse('get_tickets')
     messages.success(request, 'The Ticket has been Deleted')
     return HttpResponseRedirect(arg_num)
 def put(self, request, ticket_uuid):
     data = request.data
     obj = TicketAct().modify(ticket_uuid, data)
     messages.success(request, 'The Ticket has been Updated')
     return render(request, 'view_ticket.html', {'info': obj})
 def get(self, request, ticket_uuid):
     obj = TicketAct().retreive_single_ticket(ticket_uuid)
     return render(request, 'view_ticket.html', {'info': obj})
 def post(self, request):
     data = request.data
     tkt_obj = TicketAct().create_issue(data)
     messages.success(request, 'The Ticket has been Created')
     return render(request, RAISE_TICKET_TEMPLATE, {'tkt_info': tkt_obj})
 def setUp(self):
     self.tkt = TicketAct()