cubicweb/dataimport/test/test_sqlgenstore.py
changeset 12169 dfb5ba8518ee
parent 11057 0b59724cb3f2
child 12170 faacf884777a
equal deleted inserted replaced
12168:2ff5b8955f3f 12169:dfb5ba8518ee
    13 # details.
    13 # details.
    14 #
    14 #
    15 # You should have received a copy of the GNU Lesser General Public License along
    15 # You should have received a copy of the GNU Lesser General Public License along
    16 # with this program. If not, see <http://www.gnu.org/licenses/>.
    16 # with this program. If not, see <http://www.gnu.org/licenses/>.
    17 """SQL object store test case"""
    17 """SQL object store test case"""
    18 
       
    19 import itertools
       
    20 
    18 
    21 from cubicweb.dataimport import ucsvreader
    19 from cubicweb.dataimport import ucsvreader
    22 from cubicweb.devtools import testlib, PostgresApptestConfiguration
    20 from cubicweb.devtools import testlib, PostgresApptestConfiguration
    23 from cubicweb.devtools import startpgcluster, stoppgcluster
    21 from cubicweb.devtools import startpgcluster, stoppgcluster
    24 from cubicweb.dataimport.pgstore import SQLGenObjectStore
    22 from cubicweb.dataimport.pgstore import SQLGenObjectStore
    46         # Push timezones
    44         # Push timezones
    47         cnx = store._cnx
    45         cnx = store._cnx
    48         for code, gmt, dst, raw_offset in ucsvreader(open(self.datapath('timeZones.txt'), 'rb'),
    46         for code, gmt, dst, raw_offset in ucsvreader(open(self.datapath('timeZones.txt'), 'rb'),
    49                                                      delimiter='\t'):
    47                                                      delimiter='\t'):
    50             cnx.create_entity('TimeZone', code=code, gmt=float(gmt),
    48             cnx.create_entity('TimeZone', code=code, gmt=float(gmt),
    51                                     dst=float(dst), raw_offset=float(raw_offset))
    49                               dst=float(dst), raw_offset=float(raw_offset))
    52         timezone_code = dict(cnx.execute('Any C, X WHERE X is TimeZone, X code C'))
    50         timezone_code = dict(cnx.execute('Any C, X WHERE X is TimeZone, X code C'))
    53         cnx.commit()
    51         cnx.commit()
    54         # Push data
    52         # Push data
    55         for ind, infos in enumerate(ucsvreader(open(dumpname, 'rb'),
    53         for ind, infos in enumerate(ucsvreader(open(dumpname, 'rb'),
    56                                                delimiter='\t',
    54                                                delimiter='\t',
    68             entity = {'name': infos[1],
    66             entity = {'name': infos[1],
    69                       'asciiname': infos[2],
    67                       'asciiname': infos[2],
    70                       'alternatenames': infos[3],
    68                       'alternatenames': infos[3],
    71                       'latitude': latitude, 'longitude': longitude,
    69                       'latitude': latitude, 'longitude': longitude,
    72                       'feature_class': feature_class,
    70                       'feature_class': feature_class,
    73                       'alternate_country_code':infos[9],
    71                       'alternate_country_code': infos[9],
    74                       'admin_code_3': infos[12],
    72                       'admin_code_3': infos[12],
    75                       'admin_code_4': infos[13],
    73                       'admin_code_4': infos[13],
    76                       'population': population, 'elevation': elevation,
    74                       'population': population, 'elevation': elevation,
    77                       'gtopo30': gtopo, 'timezone': timezone_code.get(infos[17]),
    75                       'gtopo30': gtopo, 'timezone': timezone_code.get(infos[17]),
    78                       'cwuri':  u'http://sws.geonames.org/%s/' % int(infos[0]),
    76                       'cwuri': u'http://sws.geonames.org/%s/' % int(infos[0]),
    79                       'geonameid': int(infos[0]),
    77                       'geonameid': int(infos[0]),
    80                       }
    78                       }
    81             store.prepare_insert_entity('Location', **entity)
    79             store.prepare_insert_entity('Location', **entity)
    82 
    80 
    83     def test_autoflush_metadata(self):
    81     def test_autoflush_metadata(self):