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_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_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_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_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_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_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))