mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
add simple API test
This commit is contained in:
parent
79405d4a2d
commit
a5a0975c3f
7 changed files with 75 additions and 2 deletions
BIN
categories/api/tests/.test_api.py.swp
Normal file
BIN
categories/api/tests/.test_api.py.swp
Normal file
Binary file not shown.
0
categories/api/tests/__init__.py
Normal file
0
categories/api/tests/__init__.py
Normal file
62
categories/api/tests/test_api.py
Normal file
62
categories/api/tests/test_api.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# import get_user_model
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.cache import cache
|
||||
from django.urls import reverse
|
||||
from model_bakery import baker
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from categories.models import Category
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class MeViewTests(APITestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_superuser("test-user", "foo@bar.baz", "test-password")
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
category = Category.tree.create(name="Foo category", slug="foo_category", active=True, order=0, parent=None)
|
||||
baker.make(
|
||||
"SimpleText",
|
||||
primary_category=category,
|
||||
)
|
||||
cache.clear()
|
||||
|
||||
def test_list(self):
|
||||
"""
|
||||
Test list
|
||||
"""
|
||||
url = reverse("categories-list")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertListEqual(
|
||||
response.json(),
|
||||
[
|
||||
{
|
||||
"name": "Foo category",
|
||||
"slug": "foo_category",
|
||||
"active": True,
|
||||
"thumbnail": None,
|
||||
"thumbnail_width": None,
|
||||
"thumbnail_height": None,
|
||||
"order": 0,
|
||||
"alternate_title": "",
|
||||
"alternate_url": "",
|
||||
"description": None,
|
||||
"meta_keywords": "",
|
||||
"meta_extra": "",
|
||||
"children": [],
|
||||
"flatpage_count": 0,
|
||||
"flatpage_count_cumulative": 0,
|
||||
"other_cats_count": 0,
|
||||
"other_cats_count_cumulative": 0,
|
||||
"more_cats_count": 0,
|
||||
"more_cats_count_cumulative": 0,
|
||||
"simpletext_count": 1,
|
||||
"simpletext_count_cumulative": 1,
|
||||
"simpletext_sec_cat_count": 0,
|
||||
"simpletext_sec_cat_count_cumulative": 0,
|
||||
}
|
||||
],
|
||||
)
|
||||
8
example/rest_urls.py
Normal file
8
example/rest_urls.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from categories.api.urls import router as category_router
|
||||
|
||||
router = DefaultRouter()
|
||||
router.registry.extend(category_router.registry)
|
||||
|
||||
urlpatterns = router.urls
|
||||
|
|
@ -28,4 +28,5 @@ urlpatterns = (
|
|||
# {'document_root': ROOT_PATH + '/editor/media/editor/',
|
||||
# 'show_indexes':True}),
|
||||
re_path(r"^static/(?P<path>.*)$", serve, {"document_root": os.path.join(ROOT_PATH, "example", "static")}),
|
||||
path("api/", include("example.rest_urls"), name="api"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
-r prod.txt
|
||||
django<4.0.0
|
||||
django
|
||||
django-rest-framework
|
||||
ghp-import
|
||||
linkify-it-py
|
||||
model-bakery
|
||||
myst-parser
|
||||
pydata-sphinx-theme
|
||||
Sphinx>=4.3.0
|
||||
|
|
|
|||
2
tox.ini
2
tox.ini
|
|
@ -32,7 +32,7 @@ deps=
|
|||
pillow
|
||||
ipdb
|
||||
codecov
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/requirements/test.txt
|
||||
|
||||
commands=
|
||||
coverage erase
|
||||
|
|
|
|||
Loading…
Reference in a new issue