Esempio n. 1
0
 def test_run(self):
     pinger = DirectoryPinger('http://localhost', [self.entry])
     pinger.run()
     self.assertEqual(
         pinger.results,
         [{'flerror': True,
           'message': 'http://localhost is an invalid directory.'}])
Esempio n. 2
0
 def test_ping_entry(self):
     pinger = DirectoryPinger('http://localhost', [self.entry])
     self.assertEqual(
         pinger.ping_entry(self.entry),
         {'message': 'http://localhost is an invalid directory.',
          'flerror': True})
     self.assertEqual(pinger.results, [])
Esempio n. 3
0
 def setUp(self):
     params = {'title': 'My entry',
               'content': 'My content',
               'tags': 'zinnia, test',
               'slug': 'my-entry'}
     self.entry = Entry.objects.create(**params)
     self.pinger = DirectoryPinger('http://localhost', [self.entry],
                                   start_now=False)
Esempio n. 4
0
 def ping_directories(self, request, queryset):
     """Ping Directories for selected entries"""
     success = 0
     for directory in PING_DIRECTORIES:
         pinger = DirectoryPinger(directory)
         for entry in queryset:
             response = pinger.ping(entry)
             if not response.get('flerror', True):
                 success += 1
     self.message_user(request, _('%i directories succesfully pinged.') % success)
Esempio n. 5
0
 def ping_directories(self, request, queryset):
     """Ping Directories for selected entries"""
     for directory in settings.PING_DIRECTORIES:
         pinger = DirectoryPinger(directory, queryset)
         pinger.join()
         success = 0
         for result in pinger.results:
             if not result.get('flerror', True):
                 success += 1
             else:
                 self.message_user(request, '%s : %s' % (directory, result['message']))
         if success:
             self.message_user(request, _('%s directory succesfully pinged %d entries.') % (directory, success))
Esempio n. 6
0
 def ping_directories(self, request, queryset):
     """Ping Directories for selected entries"""
     for directory in settings.PING_DIRECTORIES:
         pinger = DirectoryPinger(directory, queryset)
         pinger.join()
         success = 0
         for result in pinger.results:
             if not result.get("flerror", True):
                 success += 1
             else:
                 self.message_user(request, "%s : %s" % (directory, result["message"]))
         if success:
             self.message_user(
                 request,
                 _("%(directory)s directory succesfully " "pinged %(success)d entries.")
                 % {"directory": directory, "success": success},
             )
Esempio n. 7
0
def ping_directories_handler(sender, **kwargs):
    """Ping Directories when an entry is saved"""
    entry = kwargs['instance']

    if entry.is_visible and settings.SAVE_PING_DIRECTORIES:
        from zinnia.ping import DirectoryPinger

        for directory in settings.PING_DIRECTORIES:
            DirectoryPinger(directory, [entry])
Esempio n. 8
0
 def ping_directories(self, request, queryset, messages=True):
     """Ping Directories for selected entries"""
     for directory in settings.PING_DIRECTORIES:
         pinger = DirectoryPinger(directory, queryset)
         pinger.join()
         if messages:
             success = 0
             for result in pinger.results:
                 if not result.get('flerror', True):
                     success += 1
                 else:
                     self.message_user(
                         request,
                         '%s : %s' % (directory, result['message']))
             if success:
                 self.message_user(request,
                                   _('%(directory)s directory succesfully ' \
                                     'pinged %(success)d entries.') %
                                   {'directory': directory, 'success': success})
Esempio n. 9
0
 def ping_directories(self, request, queryset, messages=True):
     """
     Ping web directories for selected entries.
     """
     for directory in settings.PING_DIRECTORIES:
         pinger = DirectoryPinger(directory, queryset)
         pinger.join()
         if messages:
             success = 0
             for result in pinger.results:
                 if not result.get('flerror', True):
                     success += 1
                 else:
                     self.message_user(request,
                                       '%s : %s' % (directory,
                                                    result['message']))
             if success:
                 self.message_user(
                     request,
                     _('%(directory)s directory succesfully '
                       'pinged %(success)d entries.') %
                     {'directory': directory, 'success': success})
Esempio n. 10
0
class DirectoryPingerTestCase(TestCase):
    """Test cases for DirectoryPinger"""
    def setUp(self):
        params = {'title': 'My entry',
                  'content': 'My content',
                  'tags': 'zinnia, test',
                  'slug': 'my-entry'}
        self.entry = Entry.objects.create(**params)
        self.pinger = DirectoryPinger('http://localhost', [self.entry],
                                      start_now=False)

    def test_ping_entry(self):
        self.assertEquals(
            self.pinger.ping_entry(self.entry),
            {'message': 'http://localhost is an invalid directory.',
             'flerror': True})