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
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
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