34 |
34 |
35 from cubicweb import (BadConnectionId, RepositoryError, ValidationError, |
35 from cubicweb import (BadConnectionId, RepositoryError, ValidationError, |
36 UnknownEid, AuthenticationError, Unauthorized, QueryError) |
36 UnknownEid, AuthenticationError, Unauthorized, QueryError) |
37 from cubicweb.predicates import is_instance |
37 from cubicweb.predicates import is_instance |
38 from cubicweb.schema import CubicWebSchema, RQLConstraint |
38 from cubicweb.schema import CubicWebSchema, RQLConstraint |
39 from cubicweb.dbapi import connect, multiple_connections_unfix |
39 from cubicweb.dbapi import connect, multiple_connections_unfix, ConnectionProperties |
40 from cubicweb.devtools.testlib import CubicWebTC |
40 from cubicweb.devtools.testlib import CubicWebTC |
41 from cubicweb.devtools.repotest import tuplify |
41 from cubicweb.devtools.repotest import tuplify |
42 from cubicweb.server import repository, hook |
42 from cubicweb.server import repository, hook |
43 from cubicweb.server.sqlutils import SQL_PREFIX |
43 from cubicweb.server.sqlutils import SQL_PREFIX |
44 from cubicweb.server.hook import Hook |
44 from cubicweb.server.hook import Hook |
377 done.append(True) |
377 done.append(True) |
378 finally: |
378 finally: |
379 # connect monkey patch some method by default, remove them |
379 # connect monkey patch some method by default, remove them |
380 multiple_connections_unfix() |
380 multiple_connections_unfix() |
381 |
381 |
|
382 |
|
383 def test_zmq(self): |
|
384 try: |
|
385 import zmq |
|
386 except ImportError: |
|
387 self.skipTest("zmq in not available") |
|
388 done = [] |
|
389 from cubicweb.devtools import TestServerConfiguration as ServerConfiguration |
|
390 from cubicweb.server.cwzmq import ZMQRepositoryServer |
|
391 # the client part has to be in a thread due to sqlite limitations |
|
392 t = threading.Thread(target=self._zmq_client, args=(done,)) |
|
393 t.start() |
|
394 |
|
395 zmq_server = ZMQRepositoryServer(self.repo) |
|
396 zmq_server.connect('tcp://127.0.0.1:41415') |
|
397 |
|
398 t2 = threading.Thread(target=self._zmq_quit, args=(done, zmq_server,)) |
|
399 t2.start() |
|
400 |
|
401 zmq_server.run() |
|
402 |
|
403 t2.join(1) |
|
404 t.join(1) |
|
405 |
|
406 if t.isAlive(): |
|
407 self.fail('something went wrong, thread still alive') |
|
408 |
|
409 def _zmq_quit(self, done, srv): |
|
410 while not done: |
|
411 time.sleep(0.1) |
|
412 srv.quit() |
|
413 |
|
414 def _zmq_client(self, done): |
|
415 cnxprops = ConnectionProperties('zmq') |
|
416 cnx = connect(self.repo.config.appid, u'admin', password=u'gingkow', |
|
417 host='tcp://127.0.0.1:41415', |
|
418 cnxprops=cnxprops, |
|
419 initlog=False) # don't reset logging configuration |
|
420 try: |
|
421 cnx.load_appobjects(subpath=('entities',)) |
|
422 # check we can get the schema |
|
423 schema = cnx.get_schema() |
|
424 self.assertTrue(cnx.vreg) |
|
425 self.assertTrue('etypes'in cnx.vreg) |
|
426 cu = cnx.cursor() |
|
427 rset = cu.execute('Any U,G WHERE U in_group G') |
|
428 user = iter(rset.entities()).next() |
|
429 self.assertTrue(user._cw) |
|
430 self.assertTrue(user._cw.vreg) |
|
431 from cubicweb.entities import authobjs |
|
432 self.assertIsInstance(user._cw.user, authobjs.CWUser) |
|
433 cnx.close() |
|
434 done.append(True) |
|
435 finally: |
|
436 # connect monkey patch some method by default, remove them |
|
437 multiple_connections_unfix() |
|
438 |
382 def test_internal_api(self): |
439 def test_internal_api(self): |
383 repo = self.repo |
440 repo = self.repo |
384 cnxid = repo.connect(self.admlogin, password=self.admpassword) |
441 cnxid = repo.connect(self.admlogin, password=self.admpassword) |
385 session = repo._get_session(cnxid, setcnxset=True) |
442 session = repo._get_session(cnxid, setcnxset=True) |
386 self.assertEqual(repo.type_and_source_from_eid(2, session), |
443 self.assertEqual(repo.type_and_source_from_eid(2, session), |