def test_should_allow_tag_creation_after_the_bulk_deletion_of_another_tag_with_the_same_name_in_the_admin(
            self):  # noqa
        # Setup
        tag_dict = {
            'tag_definition': '[pr2]{TEXT}[/pr2]',
            'html_replacement': '<pre>{TEXT}</pre>'
        }
        tag = BBCodeTag(**tag_dict)
        tag.save()

        admin_user = User.objects.create_user('admin', '*****@*****.**',
                                              'adminpass')
        admin_user.is_staff = True
        admin_user.is_superuser = True
        admin_user.save()
        client = Client()
        client.login(username='******', password='******')
        url = reverse('admin:precise_bbcode_bbcodetag_changelist')
        client.post(url,
                    data={
                        'action': 'delete_selected',
                        '_selected_action': [
                            tag.pk,
                        ],
                        'post': 'yes'
                    })

        new_tag = BBCodeTag(**tag_dict)
        # Run & check
        try:
            new_tag.clean()
        except ValidationError:
            self.fail(
                'The following BBCode failed to validate: {}'.format(tag_dict))
 def test_should_save_default_bbcode_tags_rewrites(self):
     # Setup
     tag = BBCodeTag(tag_definition='[b]{TEXT1}[/b]', html_replacement='<b>{TEXT1}</b>')
     # Run & check
     try:
         tag.clean()
     except ValidationError:
         self.fail('The following BBCode failed to validate: {}'.format(tag))
示例#3
0
 def test_can_be_rendered(self):
     # Setup
     tag = BBCodeTag(**{'tag_definition': '[mail]{EMAIL}[/mail]',
                     'html_replacement': '<a href="mailto:{EMAIL}">{EMAIL}</a>', 'swallow_trailing_newline': True})
     tag.save()
     _init_custom_bbcode_tags(self.parser)
     # Run & check
     self.assertEqual(self.parser.render('[mail][email protected][/mail]'), '<a href="mailto:[email protected]">[email protected]</a>')
 def test_should_save_valid_tags(self):
     # Run & check
     for tag_dict in self.VALID_TAG_TESTS:
         tag = BBCodeTag(**tag_dict)
         try:
             tag.clean()
         except ValidationError:
             self.fail('The following BBCode failed to validate: {}'.format(tag_dict))
 def test_can_be_rendered_by_the_bbcode_parser(self):
     # Setup
     parser_loader = BBCodeParserLoader(parser=self.parser)
     tag = BBCodeTag(**{'tag_definition': '[mail]{EMAIL}[/mail]',
                     'html_replacement': '<a href="mailto:{EMAIL}">{EMAIL}</a>', 'swallow_trailing_newline': True})
     tag.save()
     parser_loader.init_custom_bbcode_tags()
     # Run & check
     assert self.parser.render('[mail][email protected][/mail]') == '<a href="mailto:[email protected]">[email protected]</a>'
 def test_should_provide_the_required_parser_bbcode_tag_class(self):
     # Setup
     tag = BBCodeTag(**{'tag_definition': '[io]{TEXT}[/io]', 'html_replacement': '<b>{TEXT}</b>'})
     tag.save()
     # Run & check
     parser_tag_klass = tag.parser_tag_klass
     assert issubclass(parser_tag_klass, ParserBBCodeTag)
     assert parser_tag_klass.name == 'io'
     assert parser_tag_klass.definition_string == '[io]{TEXT}[/io]'
     assert parser_tag_klass.format_string == '<b>{TEXT}</b>'
 def test_should_provide_the_required_parser_bbcode_tag_class(self):
     # Setup
     tag = BBCodeTag(**{'tag_definition': '[io]{TEXT}[/io]', 'html_replacement': '<b>{TEXT}</b>'})
     tag.save()
     # Run & check
     parser_tag_klass = tag.parser_tag_klass
     self.assertTrue(issubclass(parser_tag_klass, ParserBBCodeTag))
     self.assertEqual(parser_tag_klass.name, 'io')
     self.assertEqual(parser_tag_klass.definition_string, '[io]{TEXT}[/io]')
     self.assertEqual(parser_tag_klass.format_string, '<b>{TEXT}</b>')
示例#8
0
 def test_should_provide_the_required_parser_args(self):
     # Setup
     tag = BBCodeTag(**{'tag_definition': '[io]{TEXT}[/io]', 'html_replacement': '<b>{TEXT}</b>'})
     tag.save()
     # Run & check
     self.assertEqual(tag.parser_args, (['io', '[io]{TEXT}[/io]', '<b>{TEXT}</b>'],
                      {'display_on_editor': True, 'end_tag_closes': False, 'escape_html': True,
                       'helpline': None, 'newline_closes': False, 'render_embedded': True,
                       'replace_links': True, 'same_tag_closes': False, 'standalone': False, 'strip': False,
                       'swallow_trailing_newline': False, 'transform_newlines': True}))
 def test_should_allow_tag_updates_if_the_name_does_not_change(self):
     # Setup
     tag_dict = {'tag_definition': '[pr]{TEXT}[/pr]', 'html_replacement': '<pre>{TEXT}</pre>'}
     tag = BBCodeTag(**tag_dict)
     tag.save()
     # Run
     tag.html_replacement = '<span>{TEXT}</span>'
     # Check
     try:
         tag.clean()
     except ValidationError:
         self.fail('The following BBCode failed to validate: {}'.format(tag_dict))
示例#10
0
 def test_should_allow_tag_creation_after_the_deletion_of_another_tag_with_the_same_name(self):
     # Setup
     tag_dict = {'tag_definition': '[pr]{TEXT}[/pr]', 'html_replacement': '<pre>{TEXT}</pre>'}
     tag = BBCodeTag(**tag_dict)
     tag.save()
     tag.delete()
     new_tag = BBCodeTag(**tag_dict)
     # Run & check
     try:
         new_tag.clean()
     except ValidationError:
         self.fail('The following BBCode failed to validate: {}'.format(tag_dict))
 def test_should_allow_tag_updates_if_the_name_does_not_change(self):
     # Setup
     tag_dict = {
         'tag_definition': '[pr]{TEXT}[/pr]',
         'html_replacement': '<pre>{TEXT}</pre>'
     }
     tag = BBCodeTag(**tag_dict)
     tag.save()
     # Run
     tag.html_replacement = '<span>{TEXT}</span>'
     # Check
     try:
         tag.clean()
     except ValidationError:
         self.fail(
             'The following BBCode failed to validate: {}'.format(tag_dict))
 def test_should_allow_tag_creation_after_the_deletion_of_another_tag_with_the_same_name(
         self):
     # Setup
     tag_dict = {
         'tag_definition': '[pr]{TEXT}[/pr]',
         'html_replacement': '<pre>{TEXT}</pre>'
     }
     tag = BBCodeTag(**tag_dict)
     tag.save()
     tag.delete()
     new_tag = BBCodeTag(**tag_dict)
     # Run & check
     try:
         new_tag.clean()
     except ValidationError:
         self.fail(
             'The following BBCode failed to validate: {}'.format(tag_dict))
 def test_should_save_valid_tags(self):
     # Run & check
     for tag_dict in self.VALID_TAG_TESTS:
         tag = BBCodeTag(**tag_dict)
         try:
             tag.clean()
         except ValidationError:
             self.fail('The following BBCode failed to validate: {}'.format(
                 tag_dict))
 def test_should_save_default_bbcode_tags_rewrites(self):
     # Setup
     tag = BBCodeTag(tag_definition='[b]{TEXT1}[/b]',
                     html_replacement='<b>{TEXT1}</b>')
     # Run & check
     try:
         tag.clean()
     except ValidationError:
         self.fail(
             'The following BBCode failed to validate: {}'.format(tag))
示例#15
0
    def test_should_allow_tag_creation_after_the_bulk_deletion_of_another_tag_with_the_same_name_in_the_admin(self):  # noqa
        # Setup
        tag_dict = {'tag_definition': '[pr2]{TEXT}[/pr2]', 'html_replacement': '<pre>{TEXT}</pre>'}
        tag = BBCodeTag(**tag_dict)
        tag.save()

        admin_user = User.objects.create_user('admin', '*****@*****.**', 'adminpass')
        admin_user.is_staff = True
        admin_user.is_superuser = True
        admin_user.save()
        client = Client()
        client.login(username='******', password='******')
        url = reverse('admin:precise_bbcode_bbcodetag_changelist')
        client.post(url, data={
            'action': 'delete_selected', '_selected_action': [tag.pk, ], 'post': 'yes'})

        new_tag = BBCodeTag(**tag_dict)
        # Run & check
        try:
            new_tag.clean()
        except ValidationError:
            self.fail('The following BBCode failed to validate: {}'.format(tag_dict))
 def test_can_be_rendered_by_the_bbcode_parser(self):
     # Setup
     parser_loader = BBCodeParserLoader(parser=self.parser)
     tag = BBCodeTag(
         **{
             'tag_definition': '[mail]{EMAIL}[/mail]',
             'html_replacement': '<a href="mailto:{EMAIL}">{EMAIL}</a>',
             'swallow_trailing_newline': True
         })
     tag.save()
     parser_loader.init_custom_bbcode_tags()
     # Run & check
     assert (self.parser.render('[mail][email protected][/mail]') ==
             '<a href="mailto:[email protected]">[email protected]</a>')
 def test_should_provide_the_required_parser_bbcode_tag_class(self):
     # Setup
     tag = BBCodeTag(
         **{
             'tag_definition': '[io]{TEXT}[/io]',
             'html_replacement': '<b>{TEXT}</b>'
         })
     tag.save()
     # Run & check
     parser_tag_klass = tag.parser_tag_klass
     assert issubclass(parser_tag_klass, ParserBBCodeTag)
     assert parser_tag_klass.name == 'io'
     assert parser_tag_klass.definition_string == '[io]{TEXT}[/io]'
     assert parser_tag_klass.format_string == '<b>{TEXT}</b>'
 def test_should_not_save_invalid_tags(self):
     # Run & check
     for tag_dict in self.ERRONEOUS_TAGS_TESTS:
         with pytest.raises(ValidationError):
             tag = BBCodeTag(**tag_dict)
             tag.clean()
 def test_should_not_save_invalid_tags(self):
     # Run & check
     for tag_dict in self.ERRONEOUS_TAGS_TESTS:
         with pytest.raises(ValidationError):
             tag = BBCodeTag(**tag_dict)
             tag.clean()