[test] fix test to follow recent changes
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 22 Oct 2010 16:01:54 +0200
changeset 6595 00cd0b273cf5
parent 6594 e10468a23291
child 6596 9717122d5e06
[test] fix test to follow recent changes
devtools/fake.py
etwist/test/unittest_server.py
server/test/unittest_migractions.py
test/unittest_req.py
web/test/unittest_web.py
--- a/devtools/fake.py	Fri Oct 22 15:01:54 2010 +0200
+++ b/devtools/fake.py	Fri Oct 22 16:01:54 2010 +0200
@@ -127,6 +127,16 @@
     def validate_cache(self):
         pass
 
+    def build_url_params(self, **kwargs):
+        # overriden to get predictable resultts
+        args = []
+        for param, values in sorted(kwargs.iteritems()):
+            if not isinstance(values, (list, tuple)):
+                values = (values,)
+            for value in values:
+                assert value is not None
+                args.append(u'%s=%s' % (param, self.url_quote(value)))
+        return '&'.join(args)
 
 class FakeUser(object):
     login = 'toto'
--- a/etwist/test/unittest_server.py	Fri Oct 22 15:01:54 2010 +0200
+++ b/etwist/test/unittest_server.py	Fri Oct 22 16:01:54 2010 +0200
@@ -15,9 +15,6 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""
-
-"""
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.etwist.server import host_prefixed_baseurl
 
@@ -25,9 +22,9 @@
 class HostPrefixedBaseURLTC(CubicWebTC):
 
     def _check(self, baseurl, host, waited):
-        self.assertEquals(host_prefixed_baseurl(baseurl, host), waited,
-                          'baseurl %s called through host %s should be considered as %s'
-                          % (baseurl, host, waited))
+        self.assertEqual(host_prefixed_baseurl(baseurl, host), waited,
+                         'baseurl %s called through host %s should be considered as %s'
+                         % (baseurl, host, waited))
 
     def test1(self):
         self._check('http://www.cubicweb.org/hg/', 'code.cubicweb.org',
--- a/server/test/unittest_migractions.py	Fri Oct 22 15:01:54 2010 +0200
+++ b/server/test/unittest_migractions.py	Fri Oct 22 16:01:54 2010 +0200
@@ -15,8 +15,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""unit tests for module cubicweb.server.migractions
-"""
+"""unit tests for module cubicweb.server.migractions"""
 
 from __future__ import with_statement
 
@@ -51,9 +50,11 @@
         cls.origschema = deepcopy(cls.repo.schema)
         # hack to read the schema from data/migrschema
         config.appid = join('data', 'migratedapp')
+        config._apphome = cls.datapath('migratedapp')
         global migrschema
         migrschema = config.load_schema()
         config.appid = 'data'
+        config._apphome = cls.datadir
         assert 'Folder' in migrschema
 
     @classmethod
--- a/test/unittest_req.py	Fri Oct 22 15:01:54 2010 +0200
+++ b/test/unittest_req.py	Fri Oct 22 16:01:54 2010 +0200
@@ -40,7 +40,7 @@
         self.assertEqual(req.build_url('one'), u'http://testing.fr/cubicweb/one')
         self.assertEqual(req.build_url(param='ok'), u'http://testing.fr/cubicweb/view?param=ok')
         self.assertRaises(AssertionError, req.build_url, 'one', 'two not allowed')
-        self.assertRaises(ValueError, req.build_url, 'view', test=None)
+        self.assertRaises(AssertionError, req.build_url, 'view', test=None)
 
 
 if __name__ == '__main__':
--- a/web/test/unittest_web.py	Fri Oct 22 15:01:54 2010 +0200
+++ b/web/test/unittest_web.py	Fri Oct 22 16:01:54 2010 +0200
@@ -21,15 +21,25 @@
 
 class AjaxReplaceUrlTC(TestCase):
 
-    def test_ajax_replace_url(self):
+    def test_ajax_replace_url_1(self):
+        self._test_arurl("fname=view&rql=Person%20P&vid=list",
+                         rql='Person P', vid='list')
+
+    def test_ajax_replace_url_2(self):
+        self._test_arurl("age=12&fname=view&name=bar&rql=Person%20P&vid=oneline",
+                         rql='Person P', vid='oneline', name='bar', age=12)
+
+    def _test_arurl(self, qs, **kwargs):
         req = FakeRequest()
         arurl = req.ajax_replace_url
         # NOTE: for the simplest use cases, we could use doctest
-        self.assertEqual(arurl('foo', rql='Person P', vid='list'),
-                          """javascript: $('#foo').loadxhtml("http://testing.fr/cubicweb/json?rql=Person%20P&fname=view&vid=list",null,"get","replace"); noop()""")
-        self.assertEqual(arurl('foo', rql='Person P', vid='oneline', name='bar', age=12),
-                          """javascript: $('#foo').loadxhtml("http://testing.fr/cubicweb/json?name=bar&age=12&rql=Person%20P&fname=view&vid=oneline",null,"get","replace"); noop()""")
-
+        url = arurl('foo', **kwargs)
+        self.failUnless(url.startswith('javascript:'))
+        self.failUnless(url.endswith('()'))
+        cbname = url.split()[1][:-2]
+        self.assertMultiLineEqual(
+            'function %s() { $("#foo").loadxhtml("http://testing.fr/cubicweb/json?%s",null,"get","replace"); }' % (cbname, qs),
+            req.html_headers.post_inlined_scripts[0])
 
 if __name__ == '__main__':
     unittest_main()