[FIX] re-enable crawler tests
authorXavier Morel <xmo@openerp.com>
Mon, 17 Feb 2014 15:15:35 +0000 (16:15 +0100)
committerXavier Morel <xmo@openerp.com>
Mon, 17 Feb 2014 15:15:35 +0000 (16:15 +0100)
Move URLCase back out of the test module, otherwise loadTestFromModule
attempts to load it in the usual manner (~URLCase('runTest')). Which does not
work at all, because that's not what URLCase is for.

URLCase extends TestCase to benefit from the TestCase.run infrastructure
(running tests, filling result object, etc...)

bzr revid: xmo@openerp.com-20140217151535-alq7pq6qapski73x

addons/website/tests/__init__.py
addons/website/tests/cases.py [new file with mode: 0644]
addons/website/tests/test_requests.py

index f227a75..b7eb183 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
 import test_converter
-#import test_requests
+import test_requests
 import test_ui
 import test_views
diff --git a/addons/website/tests/cases.py b/addons/website/tests/cases.py
new file mode 100644 (file)
index 0000000..3e77729
--- /dev/null
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+import unittest2
+
+class URLCase(unittest2.TestCase):
+    """
+    URLCase moved out of test_requests, otherwise discovery attempts to
+    instantiate and run it
+    """
+    def __init__(self, user, url, source, result):
+        super(URLCase, self).__init__()
+        self.user = user
+        self.url = url
+        self.source = source
+        self.result = result
+
+    @property
+    def username(self):
+        return self.user or "Anonymous Coward"
+
+    def __str__(self):
+        if self.source:
+            return "%s (from %s, as %s)" % (self.url, self.source, self.username)
+        return "%s (as %s)" % (self.url, self.username)
+
+    __repr__ = __str__
+
+    def shortDescription(self):
+        return ""
+
+    def runTest(self):
+        code = self.result.getcode()
+        self.assertIn(
+            code, xrange(200, 300),
+            "Fetching %s as %s returned an error response (%d)" % (
+                self.url, self.username, code))
index 391eee5..9fb29b6 100644 (file)
@@ -1,5 +1,4 @@
 # -*- coding: utf-8 -*-
-import collections
 import urlparse
 import unittest2
 import urllib2
@@ -9,40 +8,9 @@ import lxml.html
 
 from openerp import tools
 
-__all__ = ['load_tests', 'CrawlSuite']
-
-class URLCase(unittest2.TestCase):
-    """
-    URLCase moved out of test_requests, otherwise discovery attempts to
-    instantiate and run it
-    """
-    def __init__(self, user, url, source, result):
-        super(URLCase, self).__init__()
-        self.user = user
-        self.url = url
-        self.source = source
-        self.result = result
-
-    @property
-    def username(self):
-        return self.user or "Anonymous Coward"
-
-    def __str__(self):
-        if self.source:
-            return "%s (from %s, as %s)" % (self.url, self.source, self.username)
-        return "%s (as %s)" % (self.url, self.username)
+import cases
 
-    __repr__ = __str__
-
-    def shortDescription(self):
-        return ""
-
-    def runTest(self):
-        code = self.result.getcode()
-        self.assertIn(
-            code, xrange(200, 300),
-            "Fetching %s as %s returned an error response (%d)" % (
-                self.url, self.username, code))
+__all__ = ['load_tests', 'CrawlSuite']
 
 class RedirectHandler(urllib2.HTTPRedirectHandler):
     """
@@ -96,12 +64,12 @@ class CrawlSuite(unittest2.TestSuite):
         # blow up in multidb situations
         self.opener.open('http://localhost:{port}/web/?db={db}'.format(
             port=tools.config['xmlrpc_port'],
-            db=werkzeug.url_quote_plus(tools.config['db_name']),
+            db=werkzeug.urls.url_quote_plus(tools.config['db_name']),
         ))
         if user is not None:
             url = 'http://localhost:{port}/login?{query}'.format(
                 port=tools.config['xmlrpc_port'],
-                query=werkzeug.url_encode({
+                query=werkzeug.urls.url_encode({
                     'db': tools.config['db_name'],
                     'login': user,
                     'key': password,
@@ -149,7 +117,7 @@ class URL(object):
         self.source = source
 
     def to_case(self, user, result):
-        return URLCase(user, self.url, self.source, result)
+        return cases.URLCase(user, self.url, self.source, result)
 
 def load_tests(loader, base, _):
     base.addTest(CrawlSuite())