コード例 #1
0
    def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        self.site = Site.objects.get_current()
        self.author = Author.objects.create_user(username='******',
                                                 email='*****@*****.**',
                                                 password='******')
        self.category = Category.objects.create(title='Tests', slug='tests')
        params = {
            'title': 'Test 1',
            'content': 'First test entry published',
            'slug': 'test-1',
            'tags': 'tests',
            'creation_date': datetime(2010, 1, 1, 23, 00),
            'status': PUBLISHED
        }
        entry = Entry.objects.create(**params)
        entry.sites.add(self.site)
        entry.categories.add(self.category)
        entry.authors.add(self.author)
        self.first_entry = entry

        params = {
            'title': 'Test 2',
            'content': 'Second test entry published',
            'slug': 'test-2',
            'tags': 'tests',
            'creation_date': datetime(2010, 5, 31, 23, 00),
            'status': PUBLISHED
        }
        entry = Entry.objects.create(**params)
        entry.sites.add(self.site)
        entry.categories.add(self.category)
        entry.authors.add(self.author)
        self.second_entry = entry
コード例 #2
0
ファイル: test_moderator.py プロジェクト: dx150717/newton-www
    def test_integrity_error_on_duplicate_spam_comments(self):
        class AllIsSpamModerator(EntryCommentModerator):
            spam_checker_backends = [
                'events.spam_checker.backends.all_is_spam'
            ]

        moderator_stack.unregister(Entry)
        moderator_stack.register(Entry, AllIsSpamModerator)

        datas = {
            'name': 'Jim Bob',
            'email': '*****@*****.**',
            'url': '',
            'comment': 'This is my comment'
        }

        f = CommentForm(self.entry)
        datas.update(f.initial)
        url = reverse('comments-post-comment')
        self.assertEqual(self.entry.comment_count, 0)
        connect_discussion_signals()
        self.client.post(url, datas)
        self.client.post(url, datas)
        disconnect_discussion_signals()
        self.assertEqual(comments.get_model().objects.count(), 1)
        entry_reloaded = Entry.objects.get(pk=self.entry.pk)
        self.assertEqual(entry_reloaded.comment_count, 0)
コード例 #3
0
 def setUp(self):
     disconnect_entry_signals()
     disconnect_discussion_signals()
     params = {'title': 'My entry',
               'content': 'My content',
               'slug': 'my-entry'}
     self.entry = Entry.objects.create(**params)
コード例 #4
0
    def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        # Clean the memoization of user flagger to avoid error on MySQL
        try:
            del user_flagger_[()]
        except KeyError:
            pass
        # Use default URL shortener backend, to avoid networks errors
        self.original_shortener = shortener_settings.URL_SHORTENER_BACKEND
        shortener_settings.URL_SHORTENER_BACKEND = 'events.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(
            {'events/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())
コード例 #5
0
 def __init__(self):
     """
     Init the Command and add custom styles.
     """
     super(Command, self).__init__()
     self.style.TITLE = self.style.SQL_FIELD
     self.style.STEP = self.style.SQL_COLTYPE
     self.style.ITEM = self.style.HTTP_INFO
     disconnect_entry_signals()
     disconnect_discussion_signals()
コード例 #6
0
    def test_pingback_ping(self):
        target = 'http://%s%s' % (
            self.site.domain, self.first_entry.get_absolute_url())
        source = 'http://%s%s' % (
            self.site.domain, self.second_entry.get_absolute_url())

        # Error code 0 : A generic fault code
        response = self.server.pingback.ping('toto', 'titi')
        self.assertEqual(response, 0)
        response = self.server.pingback.ping('http://%s/' % self.site.domain,
                                             'http://%s/' % self.site.domain)
        self.assertEqual(response, 0)

        # Error code 16 : The source URI does not exist.
        response = self.server.pingback.ping('http://external/', target)
        self.assertEqual(response, 16)

        # Error code 17 : The source URI does not contain a link to
        # the target URI and so cannot be used as a source.
        response = self.server.pingback.ping(source, 'toto')
        self.assertEqual(response, 17)

        # Error code 32 : The target URI does not exist.
        response = self.server.pingback.ping(
            source, 'http://example.com/error-404/')
        self.assertEqual(response, 32)
        response = self.server.pingback.ping(source, 'http://external/')
        self.assertEqual(response, 32)

        # Error code 33 : The target URI cannot be used as a target.
        response = self.server.pingback.ping(source, 'http://example.com/')
        self.assertEqual(response, 33)
        self.first_entry.pingback_enabled = False
        self.first_entry.save()
        response = self.server.pingback.ping(source, target)
        self.assertEqual(response, 33)

        # Validate pingback
        self.assertEqual(self.first_entry.pingback_count, 0)
        self.first_entry.pingback_enabled = True
        self.first_entry.save()
        connect_discussion_signals()
        response = self.server.pingback.ping(source, target)
        disconnect_discussion_signals()
        self.assertEqual(
            response,
            'Pingback from %s to %s registered.' % (source, target))
        first_entry_reloaded = Entry.objects.get(pk=self.first_entry.pk)
        self.assertEqual(first_entry_reloaded.pingback_count, 1)
        self.assertTrue(self.second_entry.title in
                        self.first_entry.pingbacks[0].user_name)

        # Error code 48 : The pingback has already been registered.
        response = self.server.pingback.ping(source, target)
        self.assertEqual(response, 48)
コード例 #7
0
ファイル: test_feeds.py プロジェクト: englandbaron/newton-www
 def setUp(self):
     disconnect_entry_signals()
     disconnect_discussion_signals()
     activate('en')
     self.site = Site.objects.get_current()
     self.author = Author.objects.create(username='******',
                                         first_name='Root',
                                         last_name='Bloody',
                                         email='*****@*****.**')
     self.category = Category.objects.create(title='Tests', slug='tests')
     self.entry_ct_id = ContentType.objects.get_for_model(Entry).pk
コード例 #8
0
    def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        self.site = Site.objects.get_current()
        self.author = Author.objects.create(username='******',
                                            email='*****@*****.**')

        params = {
            'title': 'My test entry',
            'content': 'My test entry',
            'slug': 'my-test-entry',
            'status': PUBLISHED
        }
        self.entry = Entry.objects.create(**params)
        self.entry.sites.add(self.site)
        self.entry.authors.add(self.author)
コード例 #9
0
 def test_pingback_ping_on_entry_without_author(self):
     target = 'http://%s%s' % (
         self.site.domain, self.first_entry.get_absolute_url())
     source = 'http://%s%s' % (
         self.site.domain, self.second_entry.get_absolute_url())
     self.first_entry.pingback_enabled = True
     self.first_entry.save()
     self.first_entry.authors.clear()
     connect_discussion_signals()
     response = self.server.pingback.ping(source, target)
     disconnect_discussion_signals()
     self.assertEqual(
         response,
         'Pingback from %s to %s registered.' % (source, target))
     first_entry_reloaded = Entry.objects.get(pk=self.first_entry.pk)
     self.assertEqual(first_entry_reloaded.pingback_count, 1)
     self.assertTrue(self.second_entry.title in
                     self.first_entry.pingbacks[0].user_name)
コード例 #10
0
ファイル: test_moderator.py プロジェクト: dx150717/newton-www
    def test_comment_count_denormalization(self):
        class AllIsSpamModerator(EntryCommentModerator):
            spam_checker_backends = [
                'events.spam_checker.backends.all_is_spam'
            ]

        class NoMailNoSpamModerator(EntryCommentModerator):
            def email(self, *ka, **kw):
                pass

            def moderate(self, *ka, **kw):
                return False

        datas = {
            'name': 'Jim Bob',
            'email': '*****@*****.**',
            'url': '',
            'comment': 'This is my comment'
        }

        f = CommentForm(self.entry)
        datas.update(f.initial)
        url = reverse('comments-post-comment')

        moderator_stack.unregister(Entry)
        moderator_stack.register(Entry, AllIsSpamModerator)

        self.assertEqual(self.entry.comment_count, 0)
        connect_discussion_signals()
        self.client.post(url, datas)
        entry_reloaded = Entry.objects.get(pk=self.entry.pk)
        self.assertEqual(entry_reloaded.comment_count, 0)

        moderator_stack.unregister(Entry)
        moderator_stack.register(Entry, NoMailNoSpamModerator)

        datas['comment'] = 'This a published comment'
        self.client.post(url, datas)
        disconnect_discussion_signals()
        entry_reloaded = Entry.objects.get(pk=self.entry.pk)
        self.assertEqual(entry_reloaded.comment_count, 1)
コード例 #11
0
 def test_zinnia_trackback(self):
     # Clean the memoization of user flagger to avoid error on MySQL
     try:
         del user_flagger_[()]
     except KeyError:
         pass
     self.inhibit_templates('events/entry_trackback.xml', '404.html')
     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')
コード例 #12
0
ファイル: test_moderator.py プロジェクト: dx150717/newton-www
    def setUp(self):
        disconnect_entry_signals()
        disconnect_discussion_signals()
        setup_test_template_loader({
            'comments/comment_authors_email.txt': '',
            'comments/comment_notification_email.txt': '',
            'comments/comment_reply_email.txt': ''
        })

        self.site = Site.objects.get_current()
        self.author = Author.objects.create(username='******',
                                            email='*****@*****.**')
        params = {
            'title': 'My test entry',
            'content': 'My test entry',
            'slug': 'my-test-entry',
            'status': PUBLISHED
        }
        self.entry = Entry.objects.create(**params)
        self.entry.sites.add(self.site)
        self.entry.authors.add(self.author)
コード例 #13
0
 def setUp(self):
     disconnect_entry_signals()
     disconnect_discussion_signals()