Commit 2630b503 authored by ale's avatar ale
Browse files

fix plugins that were using gevent.dns

Also get rid of os.system() calls in test teardowns.
parent ce2e8322
import gevent
import gevent.dns
import os
import re
import socket
from nospam.dbshelve import get_shelve
import urlparse
from nospam.plugin_base import BasePlugin
......@@ -36,9 +36,9 @@ class DBLPlugin(BasePlugin):
if domain not in self._cache:
try:
q = '%s.dbl.spamhaus.org' % domain
ttl, res = gevent.dns.resolve_ipv4(q, gevent.dns.QUERY_NO_SEARCH)
res = socket.gethostbyname(q)
self._cache[domain] = True
except gevent.dns.DNSError:
except socket.gaierror:
self._cache[domain] = False
results[domain] = self._cache[domain]
......
import gevent
import gevent.dns
import os
import re
import socket
from nospam.dbshelve import get_shelve
import urlparse
from nospam.plugin_base import BasePlugin
......@@ -37,9 +37,9 @@ class SURBLPlugin(BasePlugin):
if domain not in self._cache:
try:
q = '%s.multi.surbl.org' % domain
ttl, res = gevent.dns.resolve_ipv4(q, gevent.dns.QUERY_NO_SEARCH)
res = socket.gethostbyname(q)
self._cache[domain] = True
except gevent.dns.DNSError:
except socket.gaierror:
self._cache[domain] = False
results[domain] = self._cache[domain]
......
from nospam.api import NoSpam
import os
import shutil
import tempfile
import unittest
......@@ -15,7 +16,7 @@ class TestAPI(unittest.TestCase):
self.ns = NoSpam(self.config)
def tearDown(self):
os.system('rm -fr %s' % self.tmp_dir)
shutil.rmtree(self.tmp_dir)
def test_plugin_load(self):
self.assertEquals(1, len(self.ns._plugins))
......
import os
import shutil
import tempfile
import unittest
from nospam.plugins.classified import ClassifiedPlugin
......@@ -13,7 +14,7 @@ class ClassifiedPluginTest(unittest.TestCase):
self.cp = ClassifiedPlugin(config)
def tearDown(self):
os.system('rm -fr %s' % self.data_dir)
shutil.rmtree(self.data_dir)
def test_no_links(self):
comment = {'_urls': []}
......
import os
import shutil
import tempfile
import unittest
from nospam.plugins.dbl import DBLPlugin
class DBLPluginTest(unittest.TestCase):
def setUp(self):
self.data_dir = tempfile.mkdtemp()
config = {'data_dir': self.data_dir}
self.cp = DBLPlugin(config)
def tearDown(self):
shutil.rmtree(self.data_dir)
def test_no_links(self):
score, msg = self.cp.testComment({'_urls': []})
self.assertEquals(0, score)
def test_link(self):
score, msg = self.cp.testComment({'_urls': ['http://www.autistici.org/']})
self.assertEquals(0, score)
# URL normalization removes the www prefix.
self.assertTrue('autistici.org' in self.cp._cache)
import os
import shutil
import tempfile
import unittest
from nospam.plugins.surbl import SURBLPlugin
class SURBLPluginTest(unittest.TestCase):
def setUp(self):
self.data_dir = tempfile.mkdtemp()
config = {'data_dir': self.data_dir}
self.cp = SURBLPlugin(config)
def tearDown(self):
shutil.rmtree(self.data_dir)
def test_no_links(self):
score, msg = self.cp.testComment({'_urls': []})
self.assertEquals(0, score)
def test_link(self):
score, msg = self.cp.testComment({'_urls': ['http://www.autistici.org/']})
self.assertEquals(0, score)
# URL normalization removes the www prefix.
self.assertTrue('autistici.org' in self.cp._cache)
import os
import shutil
import tempfile
import unittest
from nospam.urls import *
......@@ -45,7 +46,7 @@ class TestDomains(unittest.TestCase):
init_urls({'config_dir': self.tmpdir, 'data_dir': self.tmpdir})
def tearDown(self):
os.system('rm -fr %s' % self.tmpdir)
shutil.rmtree(self.tmpdir)
def test_is_ipaddr(self):
self.assertTrue(is_ipaddr('10.0.0.1'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment