Skip to content

Commit

Permalink
Add tests; push for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel2392 committed Apr 15, 2024
1 parent f39a1ea commit 43a7e65
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = wagtail_fedit
version = 1.4.8a4
version = 1.4.8
description = Frontend editing for your Wagtail site
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
110 changes: 110 additions & 0 deletions wagtail_fedit/test/core/tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from wagtail_fedit.utils import (
FEDIT_PREVIEW_VAR,
find_block,
)
from wagtail_fedit.templatetags.fedit import (
wrap_adapter,
Expand Down Expand Up @@ -39,7 +40,15 @@ def render_content(self, parent_context: dict = None) -> str:
return f"TestAdapter: {self.field_value}"


class TestBlockAdapter(BlockAdapter, TestAdapter):
identifier = "test_block"

class TestFieldAdapter(FieldAdapter, TestAdapter):
identifier = "test_field"

adapter_registry.register(TestAdapter)
adapter_registry.register(TestBlockAdapter)
adapter_registry.register(TestFieldAdapter)


class TestBaseAdapter(BaseFEditTest):
Expand Down Expand Up @@ -159,3 +168,104 @@ def test_adapter_editable(self):
)


class TestBlockAdapter(BaseFEditTest):

def test_render(self):
streamfield = self.basic_model.content
block = find_block(self.BLOCK_ID, streamfield)
request = self.request_factory.get(
self.get_editable_url(
self.basic_model.pk, self.basic_model._meta.app_label, self.basic_model._meta.model_name,
)
)
request.user = self.admin_user
setattr(
request,
FEDIT_PREVIEW_VAR,
True,
)
block_value, _ = block
template = Template(
"{% load fedit %}"
"{% fedit test_block object.content block=block block_id=block_id id=5 %}"
)

context = {
"object": self.basic_model,
"request": request,
"block": block_value,
"block_id": self.BLOCK_ID,
}

tpl = template.render(Context(context))

self.assertHTMLEqual(
tpl,
wrap_adapter(request, adapters[5], {})
)

def test_render_from_context(self):
streamfield = self.basic_model.content
block = find_block(self.BLOCK_ID, streamfield)
request = self.request_factory.get(
self.get_editable_url(
self.basic_model.pk, self.basic_model._meta.app_label, self.basic_model._meta.model_name,
)
)
request.user = self.admin_user
setattr(
request,
FEDIT_PREVIEW_VAR,
True,
)
block_value, _ = block
template = Template(
"{% load fedit %}"
"{% fedit test_block from_context block=block block_id=block_id id=6 %}"
)

context = {
"object": self.basic_model,
"request": request,
"block": block_value,
"block_id": self.BLOCK_ID,
"wagtail_fedit_field": "content",
"wagtail_fedit_instance": self.basic_model,
}

tpl = template.render(Context(context))

self.assertHTMLEqual(
tpl,
wrap_adapter(request, adapters[6], context)
)


def test_render_from_context_missing(self):
streamfield = self.basic_model.content
block = find_block(self.BLOCK_ID, streamfield)
request = self.request_factory.get(
self.get_editable_url(
self.basic_model.pk, self.basic_model._meta.app_label, self.basic_model._meta.model_name,
)
)
request.user = self.admin_user
block_value, _ = block
template = Template(
"{% load fedit %}"
"{% fedit test_block from_context block=block block_id=block_id id=6 %}"
)

context = {
"object": self.basic_model,
"request": request,
"block": block_value,
"block_id": self.BLOCK_ID,
}

tpl = template.render(Context(context))

self.assertHTMLEqual(
tpl,
block_value.render(context),
)

0 comments on commit 43a7e65

Please sign in to comment.