server/test/unittest_multisources.py
changeset 6724 24bf6f181d0e
parent 6631 26c303c3f1aa
child 6762 812445504835
equal deleted inserted replaced
6723:a2ccbcbb08a6 6724:24bf6f181d0e
     1  # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    33 
    33 
    34 EXTERN_SOURCE_CFG = u'''
    34 EXTERN_SOURCE_CFG = u'''
    35 pyro-ns-id = extern
    35 pyro-ns-id = extern
    36 cubicweb-user = admin
    36 cubicweb-user = admin
    37 cubicweb-password = gingkow
    37 cubicweb-password = gingkow
    38 mapping-file = extern_mapping.py
       
    39 base-url=http://extern.org/
    38 base-url=http://extern.org/
    40 '''
    39 '''
    41 
    40 
    42 # hi-jacking
    41 # hi-jacking
    43 from cubicweb.server.sources.pyrorql import PyroRQLSource
    42 from cubicweb.server.sources.pyrorql import PyroRQLSource
    44 from cubicweb.dbapi import Connection
    43 from cubicweb.dbapi import Connection
    45 
    44 
    46 PyroRQLSource_get_connection = PyroRQLSource.get_connection
    45 PyroRQLSource_get_connection = PyroRQLSource.get_connection
    47 Connection_close = Connection.close
    46 Connection_close = Connection.close
       
    47 
       
    48 def add_extern_mapping(source):
       
    49     execute = source._cw.execute
       
    50     for etype in ('Card', 'Affaire', 'State'):
       
    51         assert execute('SET S cw_support ET WHERE ET name %(etype)s, ET is CWEType, S eid %(s)s',
       
    52                        {'etype': etype, 's': source.eid})
       
    53     for rtype in ('in_state', 'documented_by', 'multisource_inlined_rel'):
       
    54         assert execute('SET S cw_support RT WHERE RT name %(rtype)s, RT is CWRType, S eid %(s)s',
       
    55                        {'rtype': rtype, 's': source.eid})
       
    56 
    48 
    57 
    49 def setup_module(*args):
    58 def setup_module(*args):
    50     global repo2, cnx2, repo3, cnx3
    59     global repo2, cnx2, repo3, cnx3
    51     cfg1 = ExternalSource1Configuration('data', apphome=TwoSourcesTC.datadir)
    60     cfg1 = ExternalSource1Configuration('data', apphome=TwoSourcesTC.datadir)
    52     repo2, cnx2 = init_test_database(config=cfg1)
    61     repo2, cnx2 = init_test_database(config=cfg1)
    53     cfg2 = ExternalSource2Configuration('data', apphome=TwoSourcesTC.datadir)
    62     cfg2 = ExternalSource2Configuration('data', apphome=TwoSourcesTC.datadir)
    54     repo3, cnx3 = init_test_database(config=cfg2)
    63     repo3, cnx3 = init_test_database(config=cfg2)
    55     cnx3.request().create_entity('CWSource', name=u'extern', type=u'pyrorql',
    64     src = cnx3.request().create_entity('CWSource', name=u'extern',
    56                                  config=EXTERN_SOURCE_CFG)
    65                                        type=u'pyrorql', config=EXTERN_SOURCE_CFG)
       
    66     add_extern_mapping(src)
    57     cnx3.commit()
    67     cnx3.commit()
    58 
    68 
    59     TestServerConfiguration.no_sqlite_wrap = True
    69     TestServerConfiguration.no_sqlite_wrap = True
    60     # hi-jack PyroRQLSource.get_connection to access existing connection (no
    70     # hi-jack PyroRQLSource.get_connection to access existing connection (no
    61     # pyro connection)
    71     # pyro connection)
   104         for uri, config in [('extern', EXTERN_SOURCE_CFG),
   114         for uri, config in [('extern', EXTERN_SOURCE_CFG),
   105                             ('extern-multi', '''
   115                             ('extern-multi', '''
   106 pyro-ns-id = extern-multi
   116 pyro-ns-id = extern-multi
   107 cubicweb-user = admin
   117 cubicweb-user = admin
   108 cubicweb-password = gingkow
   118 cubicweb-password = gingkow
   109 mapping-file = extern_mapping.py
       
   110 ''')]:
   119 ''')]:
   111             self.request().create_entity('CWSource', name=unicode(uri),
   120             source = self.request().create_entity(
   112                                          type=u'pyrorql',
   121                 'CWSource', name=unicode(uri), type=u'pyrorql',
   113                                          config=unicode(config))
   122                 config=unicode(config))
       
   123             add_extern_mapping(source)
   114         self.commit()
   124         self.commit()
   115         # trigger discovery
   125         # trigger discovery
   116         self.sexecute('Card X')
   126         self.sexecute('Card X')
   117         self.sexecute('Affaire X')
   127         self.sexecute('Affaire X')
   118         self.sexecute('State X')
   128         self.sexecute('State X')