[test] fix unit tests
authorDavid Douard <david.douard@logilab.fr>
Thu, 10 Jul 2014 10:27:16 +0200
changeset 1549 46be4dfc1070
parent 1548 4dbaf65f8cd1
child 1550 d77b516a8f00
[test] fix unit tests - fix the narval-cw-sources.ini (token_id+secret instead of user+password), - update MockConnection which should not pretend to be a pyro repository any more, but a http connection handler, - code cleanup.
test/data/narval-cw-sources.ini
test/unittest_task.py
test/unittest_writer.py
testutils.py
--- a/test/data/narval-cw-sources.ini	Wed Jul 09 10:25:30 2014 +0200
+++ b/test/data/narval-cw-sources.ini	Thu Jul 10 10:27:16 2014 +0200
@@ -1,4 +1,4 @@
 [narval]
 url=http://testing.fr/cubicweb/
-user=narval
-password=narval0
+token_id=Narval token
+secret=123456
\ No newline at end of file
--- a/test/unittest_task.py	Wed Jul 09 10:25:30 2014 +0200
+++ b/test/unittest_task.py	Thu Jul 10 10:27:16 2014 +0200
@@ -10,7 +10,7 @@
 
 # import this first will set import machinery on
 import cubicweb.devtools
-from cubes.apycot.testutils import MockTestWriter, MockRepository, MockConnection, MockVCSFile
+from cubes.apycot.testutils import MockTestWriter, MockRepository, MockVCSFile
 
 from apycotlib import SetupException
 from apycotlib import SUCCESS, FAILURE, PARTIAL, SKIPPED
--- a/test/unittest_writer.py	Wed Jul 09 10:25:30 2014 +0200
+++ b/test/unittest_writer.py	Thu Jul 10 10:27:16 2014 +0200
@@ -5,7 +5,7 @@
 from logilab.common.testlib import TestCase, unittest_main
 
 import cubicweb.devtools
-import cubes.apycot.testutils
+from cubes.apycot.testutils import MockConnection
 
 from apycotlib.writer import BaseDataWriter
 
@@ -13,7 +13,7 @@
 class BaseDataWriterTC(TestCase):
 
     def setUp(self):
-        self.writer = BaseDataWriter(None, 1)
+        self.writer = BaseDataWriter(MockConnection('narval0'), 1)
 
     def test__msg_info_01(self):
         path, line, msg = self.writer._msg_info('bonjour %s', 'vous')
--- a/testutils.py	Wed Jul 09 10:25:30 2014 +0200
+++ b/testutils.py	Thu Jul 10 10:27:16 2014 +0200
@@ -6,6 +6,7 @@
 
 from logilab.common.testlib import mock_object
 
+from cubicweb.devtools import BASE_URL
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubes.vcsfile.testutils import init_vcsrepo
@@ -49,7 +50,7 @@
 class MockBaseWriter(BaseDataWriter):
 
     def __init__(self):
-        super(MockBaseWriter, self).__init__( MockConnection, None)
+        super(MockBaseWriter, self).__init__(MockConnection('narval0'), None)
 
     def skip(self, *args, **kwargs):
         pass
@@ -130,15 +131,20 @@
 
 
 class MockConnection(object):
-    """fake pyro connexion"""
-    def close(self):
+    """fake HTTP handler"""
+    def __init__(self, instance_id):
+        self.instance_id = instance_id
+        self.instance_url = BASE_URL
+
+    def http_get(self, url, **params):
         pass
-    def execute(*args, **kwargs):
+    def http_post(self, url, **params):
         pass
-    def commit(self):
+    def pending_plans(self):
+        return ()
+    def plan(self, eid):
         pass
 
-
 class ApycotBaseTC(NarvalBaseTC):
 
     recipescript = quick_script