Skip to content

Commit

Permalink
alter type for Response
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair committed Mar 24, 2024
1 parent 55a5d88 commit 3618d70
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions InvenTree/InvenTree/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import re
from contextlib import contextmanager
from pathlib import Path
from typing import Any

from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.core.handlers.wsgi import WSGIRequest
from django.db import connections
from django.http.response import StreamingHttpResponse
from django.test import TestCase
Expand All @@ -20,6 +22,8 @@
from plugin import registry
from plugin.models import PluginConfig

MyResponse = Any | WSGIRequest


def addUserPermission(user, permission):
"""Shortcut function for adding a certain permission to a user."""
Expand Down Expand Up @@ -302,7 +306,7 @@ def get(self, url, data=None, expected_code=200, format='json', **kwargs):
if data is None:
data = {}

response = self.client.get(url, data, format=format, **kwargs)
response: MyResponse = self.client.get(url, data, format=format, **kwargs)

self.checkResponse(url, 'GET', expected_code, response)

Expand All @@ -314,7 +318,7 @@ def post(self, url, data=None, expected_code=None, format='json', **kwargs):
if data is None:
data = {}

response = self.client.post(url, data=data, format=format, **kwargs)
response: MyResponse = self.client.post(url, data=data, format=format, **kwargs)

self.checkResponse(url, 'POST', expected_code, response)

Expand All @@ -325,23 +329,27 @@ def delete(self, url, data=None, expected_code=None, format='json', **kwargs):
if data is None:
data = {}

response = self.client.delete(url, data=data, format=format, **kwargs)
response: MyResponse = self.client.delete(
url, data=data, format=format, **kwargs
)

self.checkResponse(url, 'DELETE', expected_code, response)

return response

def patch(self, url, data, expected_code=None, format='json', **kwargs):
"""Issue a PATCH request."""
response = self.client.patch(url, data=data, format=format, **kwargs)
response: MyResponse = self.client.patch(
url, data=data, format=format, **kwargs
)

self.checkResponse(url, 'PATCH', expected_code, response)

return response

def put(self, url, data, expected_code=None, format='json', **kwargs):
"""Issue a PUT request."""
response = self.client.put(url, data=data, format=format, **kwargs)
response: MyResponse = self.client.put(url, data=data, format=format, **kwargs)

self.checkResponse(url, 'PUT', expected_code, response)

Expand All @@ -359,7 +367,7 @@ def download_file(
self, url, data, expected_code=None, expected_fn=None, decode=True
):
"""Download a file from the server, and return an in-memory file."""
response = self.client.get(url, data=data, format='json')
response: MyResponse = self.client.get(url, data=data, format='json')

self.checkResponse(url, 'DOWNLOAD_FILE', expected_code, response)

Expand Down

0 comments on commit 3618d70

Please sign in to comment.