Пример #1
0
    def test_with_priority_request(self):
        '''
        Check page shows up requests sorted by priority
        '''
        # making names for requests
        requests = ['request'+str(i) for i in range(10)]

        # iterate over different priorities
        for pr in range(1, 3):
            # creating 10 new requests with priority
            for request in requests:
                request = SavedRequest(priority=pr)
                request.save()

            tr = list(SavedRequest.objects.filter(priority=pr).order_by('-id'))
            test_requests = tr[:10]
            response = self.client.get(reverse('requests')+"?order_by=" +
                                       str(pr))
            # check if last requests with specified priority appear at the page
            for t_request in test_requests:
                self.assertIn(t_request, response.context['requests'])
Пример #2
0
    def process_request(self, request):
        # store requests if they are not ajax
        if request.is_ajax():
            return
        new_request = SavedRequest()
        new_request.path = request.get_full_path()
        new_request.host = request.get_host()
        new_request.method = request.method
        new_request.save()

        # for example how other priorities can be assigned
        if 'edit' in request.path:
            new_request.priority = 2
        elif 'login' in request.path:
            new_request.priority = 3
        elif 'order_by' in request.GET:
            new_request.priority = 0
        new_request.save()