Skip to content

Commit 9965c34

Browse files
committed
Add JSON-based methods to TestClient utils
1 parent d9ad639 commit 9965c34

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

django_utils_lib/testing/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import List, Tuple, Union, cast
4+
from typing import Dict, List, Tuple, Union, cast
55
from unittest import TestCase
66

77
import pytest
@@ -110,6 +110,15 @@ def login(self, client_ip="127.0.0.1", **credentials) -> bool:
110110
return True
111111
return False
112112

113+
def post_json(self, path: str, data: Dict):
114+
return self.post(path, data=data, content_type="application/json")
115+
116+
def patch_json(self, path: str, data: Dict):
117+
return self.patch(path, data=data, content_type="application/json")
118+
119+
def get_json(self, path: str, *args, **kwargs):
120+
return self.get(path, *args, **kwargs).json()
121+
113122

114123
class TestDataManager(TestCase):
115124
'''

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-utils-lib"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "A utility library for working with Django"
55
authors = ["Innolitics"]
66
readme = "README.md"

0 commit comments

Comments
 (0)