Skip to content

Commit

Permalink
test: Replace django mptt with django tree queries for tests (#684)
Browse files Browse the repository at this point in the history
Co-authored-by: Thiago Bellini Ribeiro <[email protected]>
  • Loading branch information
kwongtn and bellini666 authored Jan 4, 2025
1 parent d55d956 commit 0b28264
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 218 deletions.
42 changes: 4 additions & 38 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ channels = { version = ">=3.0.5" }
django-choices-field = "^2.2.2"
django-debug-toolbar = "^4.4.6"
django-guardian = "^2.4.0"
django-mptt = "^0.14.0"
django-types = "^0.20.0"
factory-boy = "^3.2.1"
pillow = "^11.0.0"
Expand Down
25 changes: 0 additions & 25 deletions tests/relay/mptt/a.py

This file was deleted.

32 changes: 0 additions & 32 deletions tests/relay/mptt/b.py

This file was deleted.

File renamed without changes.
25 changes: 25 additions & 0 deletions tests/relay/treenode/a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import TYPE_CHECKING, Annotated

import strawberry
from strawberry import relay
from typing_extensions import TypeAlias

import strawberry_django
from strawberry_django.relay import ListConnectionWithTotalCount

from .models import TreeNodeAuthor

if TYPE_CHECKING:
from .b import TreeNodeBookConnection


@strawberry_django.type(TreeNodeAuthor)
class TreeNodeAuthorType(relay.Node):
name: str
books: Annotated[
"TreeNodeBookConnection", strawberry.lazy("tests.relay.treenode.b")
] = strawberry_django.connection()
children: "TreeNodeAuthorConnection" = strawberry_django.connection()


TreeNodeAuthorConnection: TypeAlias = ListConnectionWithTotalCount[TreeNodeAuthorType]
34 changes: 34 additions & 0 deletions tests/relay/treenode/b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import TYPE_CHECKING, Annotated

import strawberry
from strawberry import relay
from typing_extensions import TypeAlias

import strawberry_django
from strawberry_django.relay import ListConnectionWithTotalCount

from .models import TreeNodeBook

if TYPE_CHECKING:
from .a import TreeNodeAuthorType


@strawberry_django.filter(TreeNodeBook)
class TreeNodeBookFilter:
name: str


@strawberry_django.order(TreeNodeBook)
class TreeNodeBookOrder:
name: str


@strawberry_django.type(
TreeNodeBook, filters=TreeNodeBookFilter, order=TreeNodeBookOrder
)
class TreeNodeBookType(relay.Node):
name: str
author: Annotated["TreeNodeAuthorType", strawberry.lazy("tests.relay.treenode.a")]


TreeNodeBookConnection: TypeAlias = ListConnectionWithTotalCount[TreeNodeBookType]
6 changes: 3 additions & 3 deletions tests/relay/mptt/models.py → tests/relay/treenode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tree_queries.models import TreeNode


class MPTTAuthor(TreeNode):
class TreeNodeAuthor(TreeNode):
name = models.CharField(max_length=100)
parent = TreeNodeForeignKey(
to="self",
Expand All @@ -14,10 +14,10 @@ class MPTTAuthor(TreeNode):
)


class MPTTBook(models.Model):
class TreeNodeBook(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(
MPTTAuthor,
TreeNodeAuthor,
on_delete=models.CASCADE,
related_name="books",
)
Loading

0 comments on commit 0b28264

Please sign in to comment.