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.'}])
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, [])
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 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)
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))
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}, )
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])
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})
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})
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})