def test_render_js_init_with_tag_limit(self): """Chekcs that the 'initTagField' includes the correct value based on TAG_LIMIT in settings""" widget = widgets.AdminTagWidget() html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual(len(params), 4) self.assertEqual(params[2], 'true') # tag_spaces_allowed self.assertEqual(params[3], '5') # tag_limit
def test_render_js_init_no_spaces_allowed(self): """Checks that the 'initTagField' includes the correct value based on TAG_SPACES_ALLOWED in settings""" widget = widgets.AdminTagWidget() html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual(len(params), 4) self.assertEqual(params[2], 'false') # tag_spaces_allowed self.assertEqual(params[3], 'null') # tag_limit
def test_render_js_init_basic(self): """Checks that the 'initTagField' is correctly added to the inline script for tag widgets""" widget = widgets.AdminTagWidget() html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual( params, ['alpha', '/admin/tag-autocomplete/', {'allowSpaces': True, 'tagLimit': None, 'autocompleteOnly': False}] )
def test_render_with_free_tagging_true(self): """free_tagging=True on the widget can also override the tag model setting free_tagging=False""" widget = widgets.AdminTagWidget(tag_model=RestaurantTag, free_tagging=True) html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual( params, ['alpha', '/admin/tag-autocomplete/tests/restauranttag/', {'allowSpaces': True, 'tagLimit': None, 'autocompleteOnly': False}] )
def test_render_with_free_tagging_false(self): """Checks that free_tagging=False is passed to the inline script""" widget = widgets.AdminTagWidget(free_tagging=False) html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual( params, ['alpha', '/admin/tag-autocomplete/', {'allowSpaces': True, 'tagLimit': None, 'autocompleteOnly': True}] )
def test_render_js_init_with_tag_limit(self): """Checks that the 'initTagField' includes the correct value based on TAG_LIMIT in settings""" widget = widgets.AdminTagWidget() html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual( params, ['alpha', '/admin/tag-autocomplete/', {'allowSpaces': True, 'tagLimit': 5, 'autocompleteOnly': False}] )
def test_render_js_init_basic(self): """Chekcs that the 'initTagField' is correctly added to the inline script for tag widgets""" widget = widgets.AdminTagWidget() html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual(len(params), 4) self.assertEqual(params[0], "'alpha'") # id self.assertEqual(params[1], "'/admin/tag\\u002Dautocomplete/'") # autocomplete url self.assertEqual(params[2], 'true') # tag_spaces_allowed self.assertEqual(params[3], 'null') # tag_limit
def test_render_js_init_with_tag_model(self): """Checks that 'initTagField' is passed the correct autocomplete URL for the custom model""" widget = widgets.AdminTagWidget(tag_model=RestaurantTag) html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual(len(params), 4) self.assertEqual(params[0], "'alpha'") # id self.assertEqual(params[1], "'/admin/tag\\u002Dautocomplete/tests/restauranttag/'" ) # autocomplete url self.assertEqual(params[2], 'true') # tag_spaces_allowed self.assertEqual(params[3], 'null') # tag_limit
def test_render_js_init_with_tag_model(self): """ Checks that 'initTagField' is passed the correct autocomplete URL for the custom model, and sets autocompleteOnly according to that model's free_tagging attribute """ widget = widgets.AdminTagWidget(tag_model=RestaurantTag) html = widget.render('tags', None, attrs={'id': 'alpha'}) params = self.get_js_init_params(html) self.assertEqual( params, ['alpha', '/admin/tag-autocomplete/tests/restauranttag/', {'allowSpaces': True, 'tagLimit': None, 'autocompleteOnly': True}] )
def test_render_with_free_tagging_true(self): """free_tagging=True on the widget can also override the tag model setting free_tagging=False""" widget = widgets.AdminTagWidget(tag_model=RestaurantTag, free_tagging=True) html = widget.render("tags", None, attrs={"id": "alpha"}) params = self.get_js_init_params(html) self.assertEqual( params, [ "alpha", "/admin/tag-autocomplete/tests/restauranttag/", {"allowSpaces": True, "tagLimit": None, "autocompleteOnly": False}, ], )
def test_render_with_free_tagging_false(self): """Checks that free_tagging=False is passed to the inline script""" widget = widgets.AdminTagWidget(free_tagging=False) html = widget.render("tags", None, attrs={"id": "alpha"}) params = self.get_js_init_params(html) self.assertEqual( params, [ "alpha", "/admin/tag-autocomplete/", {"allowSpaces": True, "tagLimit": None, "autocompleteOnly": True}, ], )
def test_render_js_init_with_tag_limit(self): """Checks that the 'initTagField' includes the correct value based on TAG_LIMIT in settings""" widget = widgets.AdminTagWidget() html = widget.render("tags", None, attrs={"id": "alpha"}) params = self.get_js_init_params(html) self.assertEqual( params, [ "alpha", "/admin/tag-autocomplete/", {"allowSpaces": True, "tagLimit": 5, "autocompleteOnly": False}, ], )
def test_render_js_init_basic(self): """Checks that the 'initTagField' is correctly added to the inline script for tag widgets""" widget = widgets.AdminTagWidget() html = widget.render("tags", None, attrs={"id": "alpha"}) params = self.get_js_init_params(html) self.assertEqual( params, [ "alpha", "/admin/tag-autocomplete/", {"allowSpaces": True, "tagLimit": None, "autocompleteOnly": False}, ], )
def test_tags_help_text_no_spaces_allowed(self): """Checks that the tags help text html element content is correct when TAG_SPACES_ALLOWED is False""" widget = widgets.AdminTagWidget() help_text = widget.get_context(None, None, {})["widget"]["help_text"] html = widget.render("tags", None, {}) help_text_html_element = self.get_help_text_html_element(html) self.assertEqual( help_text, "Tags can only consist of a single word, no spaces allowed.") self.assertHTMLEqual( help_text_html_element, """<p class="help">%s</p>""" % help_text, )
def test_tags_help_text_spaces_allowed(self): """Checks that the tags help text html element content is correct when TAG_SPACES_ALLOWED is True""" widget = widgets.AdminTagWidget() help_text = widget.get_context(None, None, {})["widget"]["help_text"] html = widget.render("tags", None, {}) help_text_html_element = self.get_help_text_html_element(html) self.assertEqual( help_text, 'Multi-word tags with spaces will automatically be enclosed in double quotes (").', ) self.assertHTMLEqual( help_text_html_element, """<p class="help">%s</p>""" % help_text, )
def test_render_js_init_with_tag_model(self): """ Checks that 'initTagField' is passed the correct autocomplete URL for the custom model, and sets autocompleteOnly according to that model's free_tagging attribute """ widget = widgets.AdminTagWidget(tag_model=RestaurantTag) html = widget.render("tags", None, attrs={"id": "alpha"}) params = self.get_js_init_params(html) self.assertEqual( params, [ "alpha", "/admin/tag-autocomplete/tests/restauranttag/", {"allowSpaces": True, "tagLimit": None, "autocompleteOnly": True}, ], )
def _get_tag_field_overrides(db_field): return {'widget': widgets.AdminTagWidget(tag_model=db_field.related_model)}