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))
 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_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_allow_tag_creation_after_the_bulk_deletion_of_another_tag_with_the_same_name_in_the_admin(self):
        # 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')
        r = 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_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()