def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Use default URL shortener backend, to avoid networks errors
        self.original_shortener = shortener_settings.URL_SHORTENER_BACKEND
        shortener_settings.URL_SHORTENER_BACKEND = "zinnia.url_shortener." "backends.default"
        # Set up a stub around urlopen
        import zinnia.xmlrpc.pingback

        self.original_urlopen = zinnia.xmlrpc.pingback.urlopen
        zinnia.xmlrpc.pingback.urlopen = self.fake_urlopen
        # Set a short template for entry_detail to avoid rendering errors
        setup_test_template_loader(
            {
                "zinnia/entry_detail.html": "<html><head><title>{{ object.title }}</title></head>"
                "<body>{{ object.html_content|safe }}</body></html>",
                "404.html": "404",
            }
        )
        # Preparing site
        self.site = Site.objects.get_current()
        # Creating tests entries
        self.author = Author.objects.create_user(username="******", email="*****@*****.**")
        self.category = Category.objects.create(title="test", slug="test")
        params = {
            "title": "My first entry",
            "content": "My first content",
            "slug": "my-first-entry",
            "creation_date": datetime(2010, 1, 1, 12),
            "status": PUBLISHED,
        }
        self.first_entry = Entry.objects.create(**params)
        self.first_entry.sites.add(self.site)
        self.first_entry.categories.add(self.category)
        self.first_entry.authors.add(self.author)

        params = {
            "title": "My second entry",
            "content": "My second content with link "
            'to <a href="http://%s%s">first entry</a>'
            " and other links : %s %s."
            % (
                self.site.domain,
                self.first_entry.get_absolute_url(),
                "http://example.com/error-404/",
                "http://external/",
            ),
            "slug": "my-second-entry",
            "creation_date": datetime(2010, 1, 1, 12),
            "status": PUBLISHED,
        }
        self.second_entry = Entry.objects.create(**params)
        self.second_entry.sites.add(self.site)
        self.second_entry.categories.add(self.category)
        self.second_entry.authors.add(self.author)
        # Instanciating the server proxy
        self.server = ServerProxy("http://example.com/xmlrpc/", transport=TestTransport())
 def test_zinnia_trackback_on_entry_without_author(self):
     # Clear the cache of user flagger to avoid error on MySQL
     get_user_flagger.cache_clear()
     self.first_entry.authors.clear()
     response = self.client.post('/trackback/%s/' % self.first_entry.pk,
                                 {'url': 'http://example.com'})
     self.assertEqual(response['Content-Type'], 'text/xml')
     self.assertEqual('error' in response.context, False)
Exemple #3
0
 def test_zinnia_trackback_on_entry_without_author(self):
     # Clear the cache of user flagger to avoid error on MySQL
     get_user_flagger.cache_clear()
     self.first_entry.authors.clear()
     response = self.client.post('/trackback/%s/' % self.first_entry.pk,
                                 {'url': 'http://example.com'})
     self.assertEqual(response['Content-Type'], 'text/xml')
     self.assertEqual('error' in response.context, False)
Exemple #4
0
    def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Use default URL shortener backend, to avoid networks errors
        self.original_shortener = shortener_settings.URL_SHORTENER_BACKEND
        shortener_settings.URL_SHORTENER_BACKEND = 'zinnia.url_shortener.'\
                                                   'backends.default'
        # Set up a stub around urlopen
        import zinnia.xmlrpc.pingback
        self.original_urlopen = zinnia.xmlrpc.pingback.urlopen
        zinnia.xmlrpc.pingback.urlopen = self.fake_urlopen
        # Set up a stub around zinnia.spam_checker
        import zinnia.spam_checker
        self.original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []
        # Preparing site
        self.site = Site.objects.get_current()
        # Creating tests entries
        self.author = Author.objects.create_user(username='******',
                                                 email='*****@*****.**')
        self.category = Category.objects.create(title='test', slug='test')
        params = {
            'title': 'My first entry',
            'content': 'My first content',
            'slug': 'my-first-entry',
            'publication_date': datetime(2010, 1, 1, 12),
            'status': PUBLISHED
        }
        self.first_entry = Entry.objects.create(**params)
        self.first_entry.sites.add(self.site)
        self.first_entry.categories.add(self.category)
        self.first_entry.authors.add(self.author)

        params = {
            'title':
            'My second entry',
            'content':
            'My second content with link '
            'to <a href="http://%s%s">first entry</a>'
            ' and other links : %s %s.' %
            (self.site.domain, self.first_entry.get_absolute_url(),
             'http://example.com/error-404/', 'http://external/'),
            'slug':
            'my-second-entry',
            'publication_date':
            datetime(2010, 1, 1, 12),
            'status':
            PUBLISHED
        }
        self.second_entry = Entry.objects.create(**params)
        self.second_entry.sites.add(self.site)
        self.second_entry.categories.add(self.category)
        self.second_entry.authors.add(self.author)
        # Instanciating the server proxy
        self.server = ServerProxy('http://example.com/xmlrpc/',
                                  transport=TestTransport())
    def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Use default URL shortener backend, to avoid networks errors
        self.original_shortener = shortener_settings.URL_SHORTENER_BACKEND
        shortener_settings.URL_SHORTENER_BACKEND = 'zinnia.url_shortener.'\
                                                   'backends.default'
        # Set up a stub around urlopen
        import zinnia.xmlrpc.pingback
        self.original_urlopen = zinnia.xmlrpc.pingback.urlopen
        zinnia.xmlrpc.pingback.urlopen = self.fake_urlopen
        # Set up a stub around zinnia.spam_checker
        import zinnia.spam_checker
        self.original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []
        # Preparing site
        self.site = Site.objects.get_current()
        # Creating tests entries
        self.author = Author.objects.create_user(username='******',
                                                 email='*****@*****.**')
        self.category = Category.objects.create(title='test', slug='test')
        params = {'title': 'My first entry',
                  'content': 'My first content',
                  'slug': 'my-first-entry',
                  'publication_date': datetime(2010, 1, 1, 12),
                  'status': PUBLISHED}
        self.first_entry = Entry.objects.create(**params)
        self.first_entry.sites.add(self.site)
        self.first_entry.categories.add(self.category)
        self.first_entry.authors.add(self.author)

        params = {'title': 'My second entry',
                  'content': 'My second content with link '
                  'to <a href="http://%s%s">first entry</a>'
                  ' and other links : %s %s.' % (
                      self.site.domain,
                      self.first_entry.get_absolute_url(),
                      'http://example.com/error-404/',
                      'http://external/'),
                  'slug': 'my-second-entry',
                  'publication_date': datetime(2010, 1, 1, 12),
                  'status': PUBLISHED}
        self.second_entry = Entry.objects.create(**params)
        self.second_entry.sites.add(self.site)
        self.second_entry.categories.add(self.category)
        self.second_entry.authors.add(self.author)
        # Instanciating the server proxy
        self.server = ServerProxy('http://example.com/xmlrpc/',
                                  transport=TestTransport())
    def test_zinnia_trackback_on_entry_without_author(self):
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Disable spam-checkers
        import zinnia.spam_checker
        original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []

        self.first_entry.authors.clear()
        response = self.client.post('/trackback/%s/' % self.first_entry.pk,
                                    {'url': 'http://example.com'})
        self.assertEqual(response['Content-Type'], 'text/xml')
        self.assertEqual('error' in response.context, False)
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = original_scb
    def test_zinnia_trackback_on_entry_without_author(self):
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Disable spam-checkers
        import zinnia.spam_checker
        original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []

        self.first_entry.authors.clear()
        response = self.client.post('/trackback/%s/' % self.first_entry.pk,
                                    {'url': 'http://example.com'})
        self.assertEqual(response['Content-Type'], 'text/xml')
        self.assertEqual('error' in response.context, False)
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = original_scb
    def test_zinnia_trackback(self):
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Disable spam-checkers
        import zinnia.spam_checker
        original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []

        response = self.client.post('/trackback/404/')
        trackback_url = '/trackback/%s/' % self.first_entry.pk
        self.assertEqual(response.status_code, 404)
        self.assertEqual(self.client.post(trackback_url).status_code, 301)
        self.first_entry.trackback_enabled = False
        self.first_entry.save()
        self.assertEqual(self.first_entry.trackback_count, 0)
        response = self.client.post(trackback_url,
                                    {'url': 'http://example.com'})
        self.assertEqual(response['Content-Type'], 'text/xml')
        self.assertEqual(response.context['error'],
                         'Trackback is not enabled for Test 1')
        self.first_entry.trackback_enabled = True
        self.first_entry.save()
        connect_discussion_signals()
        get_user_flagger()  # Memoize user flagger for stable query number
        if comments.get_comment_app_name() == comments.DEFAULT_COMMENTS_APP:
            # If we are using the default comment app,
            # we can count the database queries executed.
            with self.assertNumQueries(8):
                response = self.client.post(trackback_url,
                                            {'url': 'http://example.com'})
        else:
            response = self.client.post(trackback_url,
                                        {'url': 'http://example.com'})
        self.assertEqual(response['Content-Type'], 'text/xml')
        self.assertEqual('error' in response.context, False)
        disconnect_discussion_signals()
        entry = Entry.objects.get(pk=self.first_entry.pk)
        self.assertEqual(entry.trackback_count, 1)
        response = self.client.post(trackback_url,
                                    {'url': 'http://example.com'})
        self.assertEqual(response.context['error'],
                         'Trackback is already registered')
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = original_scb
    def test_zinnia_trackback(self):
        # Clear the cache of user flagger to avoid error on MySQL
        get_user_flagger.cache_clear()
        # Disable spam-checkers
        import zinnia.spam_checker
        original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []

        response = self.client.post('/trackback/404/')
        trackback_url = '/trackback/%s/' % self.first_entry.pk
        self.assertEqual(response.status_code, 404)
        self.assertEqual(self.client.post(trackback_url).status_code, 301)
        self.first_entry.trackback_enabled = False
        self.first_entry.save()
        self.assertEqual(self.first_entry.trackback_count, 0)
        response = self.client.post(trackback_url,
                                    {'url': 'http://example.com'})
        self.assertEqual(response['Content-Type'], 'text/xml')
        self.assertEqual(response.context['error'],
                         'Trackback is not enabled for Test 1')
        self.first_entry.trackback_enabled = True
        self.first_entry.save()
        connect_discussion_signals()
        get_user_flagger()  # Memoize user flagger for stable query number
        if comments.get_comment_app_name() == comments.DEFAULT_COMMENTS_APP:
            # If we are using the default comment app,
            # we can count the database queries executed.
            with self.assertNumQueries(8):
                response = self.client.post(trackback_url,
                                            {'url': 'http://example.com'})
        else:
            response = self.client.post(trackback_url,
                                        {'url': 'http://example.com'})
        self.assertEqual(response['Content-Type'], 'text/xml')
        self.assertEqual('error' in response.context, False)
        disconnect_discussion_signals()
        entry = Entry.objects.get(pk=self.first_entry.pk)
        self.assertEqual(entry.trackback_count, 1)
        response = self.client.post(trackback_url,
                                    {'url': 'http://example.com'})
        self.assertEqual(response.context['error'],
                         'Trackback is already registered')
        zinnia.spam_checker.SPAM_CHECKER_BACKENDS = original_scb
 def test_zinnia_trackback_spam_check(self):
     # Clear the cache of user flagger to avoid error on MySQL
     get_user_flagger.cache_clear()
     import zinnia.spam_checker
     original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
     zinnia.spam_checker.SPAM_CHECKER_BACKENDS = (
         'zinnia.spam_checker.backends.all_is_spam',
     )
     response = self.client.post('/trackback/%s/' % self.first_entry.pk,
                                 {'url': 'http://example.com',
                                  'excerpt': 'Spam'})
     self.assertEqual(response['Content-Type'], 'text/xml')
     self.assertEqual(response.context['error'],
                      'Trackback considered like spam')
     zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []
     response = self.client.post('/trackback/%s/' % self.first_entry.pk,
                                 {'url': 'http://example.com',
                                  'excerpt': 'Spam'})
     self.assertEqual(response['Content-Type'], 'text/xml')
     self.assertEqual('error' in response.context, False)
     zinnia.spam_checker.SPAM_CHECKER_BACKENDS = original_scb
 def test_zinnia_trackback_spam_check(self):
     # Clear the cache of user flagger to avoid error on MySQL
     get_user_flagger.cache_clear()
     import zinnia.spam_checker
     original_scb = zinnia.spam_checker.SPAM_CHECKER_BACKENDS
     zinnia.spam_checker.SPAM_CHECKER_BACKENDS = (
         'zinnia.spam_checker.backends.all_is_spam', )
     response = self.client.post('/trackback/%s/' % self.first_entry.pk, {
         'url': 'http://example.com',
         'excerpt': 'Spam'
     })
     self.assertEqual(response['Content-Type'], 'text/xml')
     self.assertEqual(response.context['error'],
                      'Trackback considered like spam')
     zinnia.spam_checker.SPAM_CHECKER_BACKENDS = []
     response = self.client.post('/trackback/%s/' % self.first_entry.pk, {
         'url': 'http://example.com',
         'excerpt': 'Spam'
     })
     self.assertEqual(response['Content-Type'], 'text/xml')
     self.assertEqual('error' in response.context, False)
     zinnia.spam_checker.SPAM_CHECKER_BACKENDS = original_scb
Exemple #12
0
 def clear_user_flagger_cache(self):
     get_user_flagger.cache_clear()
 def clear_user_flagger_cache(self):
     get_user_flagger.cache_clear()