Skip to content

Commit

Permalink
Merge pull request wagtail#276 from mope/snippets-unit-tests
Browse files Browse the repository at this point in the history
Added tests for snippets edit_handlers.py
  • Loading branch information
chrxr committed Jun 3, 2014
2 parents 8ce045b + 4887bb7 commit e144954
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions wagtail/wagtailsnippets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from wagtail.tests.utils import login, unittest
from wagtail.tests.models import Advert

from wagtail.wagtailsnippets.views.snippets import get_content_type_from_url_params, get_snippet_edit_handler
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel

class TestSnippetIndexView(TestCase):
def setUp(self):
Expand Down Expand Up @@ -137,3 +139,32 @@ def test_delete_post(self):

# Check that the page is gone
self.assertEqual(Advert.objects.filter(text='test_advert').count(), 0)


class TestSnippetChooserPanel(TestCase):
def setUp(self):
content_type = get_content_type_from_url_params('tests',
'advert')

test_snippet = Advert()
test_snippet.text = 'test_advert'
test_snippet.url = 'http://www.example.com/'
test_snippet.save()

edit_handler_class = get_snippet_edit_handler(Advert)
form_class = edit_handler_class.get_form_class(Advert)
form = form_class(instance=test_snippet)

self.snippet_chooser_panel_class = SnippetChooserPanel('text', content_type)
self.snippet_chooser_panel = self.snippet_chooser_panel_class(instance=test_snippet,
form=form)

def test_create_snippet_chooser_panel_class(self):
self.assertEqual(self.snippet_chooser_panel_class.__name__, '_SnippetChooserPanel')

def test_render_as_field(self):
self.assertTrue('test_advert' in self.snippet_chooser_panel.render_as_field())

def test_render_js(self):
self.assertTrue("createSnippetChooser(fixPrefix('id_text'), 'contenttypes/contenttype');"
in self.snippet_chooser_panel.render_js())

0 comments on commit e144954

Please sign in to comment.