Example #1
0
    def test_Reprocessing(self):
        crash_id = create_new_ooid()

        def mocked_publish(queue, crash_ids):
            assert queue == "reprocessing"
            assert crash_ids == [crash_id]
            return True

        Reprocessing.implementation().publish = mocked_publish

        url = reverse("api:model_wrapper", args=("Reprocessing", ))
        response = self.client.get(url)
        assert response.status_code == 403

        params = {"crash_ids": crash_id}
        response = self.client.get(url, params, HTTP_AUTH_TOKEN="somecrap")
        assert response.status_code == 403

        user = User.objects.create(username="******")
        self._add_permission(user, "reprocess_crashes")

        perm = Permission.objects.get(codename="reprocess_crashes")
        # but make a token that only has the 'reprocess_crashes'
        # permission associated with it
        token = Token.objects.create(user=user, notes="Only reprocessing")
        token.permissions.add(perm)

        response = self.client.get(url, params, HTTP_AUTH_TOKEN=token.key)
        assert response.status_code == 405

        response = self.client.post(url, params, HTTP_AUTH_TOKEN=token.key)
        assert response.status_code == 200
        assert json.loads(response.content) is True
Example #2
0
    def test_Reprocessing(self):
        def mocked_publish(queue, crash_ids):
            assert queue == 'reprocessing'
            assert crash_ids == ['xxxx']
            return True

        Reprocessing.implementation().publish = mocked_publish

        url = reverse('api:model_wrapper', args=('Reprocessing',))
        response = self.client.get(url)
        assert response.status_code == 403

        params = {
            'crash_ids': 'xxxx',
        }
        response = self.client.get(url, params, HTTP_AUTH_TOKEN='somecrap')
        assert response.status_code == 403

        user = User.objects.create(username='******')
        self._add_permission(user, 'reprocess_crashes')

        perm = Permission.objects.get(codename='reprocess_crashes')
        # but make a token that only has the 'reprocess_crashes'
        # permission associated with it
        token = Token.objects.create(user=user, notes="Only reprocessing")
        token.permissions.add(perm)

        response = self.client.get(url, params, HTTP_AUTH_TOKEN=token.key)
        assert response.status_code == 405

        response = self.client.post(url, params, HTTP_AUTH_TOKEN=token.key)
        assert response.status_code == 200
        assert json.loads(response.content) is True
Example #3
0
    def test_Reprocessing(self):
        def mocked_reprocess(crash_ids):
            assert crash_ids == ['xxxx']
            return True

        Reprocessing.implementation().reprocess = mocked_reprocess

        url = reverse('api:model_wrapper', args=('Reprocessing', ))
        response = self.client.get(url)
        assert response.status_code == 403

        params = {
            'crash_ids': 'xxxx',
        }
        response = self.client.get(url, params, HTTP_AUTH_TOKEN='somecrap')
        assert response.status_code == 403

        user = User.objects.create(username='******')
        self._add_permission(user, 'reprocess_crashes')

        perm = Permission.objects.get(codename='reprocess_crashes')
        # but make a token that only has the 'reprocess_crashes'
        # permission associated with it
        token = Token.objects.create(user=user, notes="Only reprocessing")
        token.permissions.add(perm)

        response = self.client.get(url, params, HTTP_AUTH_TOKEN=token.key)
        assert response.status_code == 405

        response = self.client.post(url, params, HTTP_AUTH_TOKEN=token.key)
        assert response.status_code == 200
        assert json.loads(response.content) is True
Example #4
0
def reprocessing(request):
    if request.method == 'POST':
        form = forms.ReprocessingForm(request.POST)
        if form.is_valid():
            crash_id = form.cleaned_data['crash_id']
            url = reverse('manage:reprocessing')
            worked = Reprocessing().post(crash_ids=[crash_id])
            if worked:
                url += '?crash_id={}'.format(crash_id)
                messages.success(
                    request,
                    '{} sent in for reprocessing.'.format(crash_id)
                )
            else:
                messages.error(
                    request,
                    'Currently unable to send in the crash ID '
                    'for reprocessing.'
                )
            log(request.user, 'reprocessing', {
                'crash_id': crash_id,
                'worked': worked,
            })

            return redirect(url)
    else:
        form = forms.ReprocessingForm()
    context = {
        'form': form,
        'crash_id': request.GET.get('crash_id'),
    }
    return render(request, 'manage/reprocessing.html', context)