cubicweb/dataimport/test/test_massive_store.py
changeset 11789 71df2811b422
parent 11781 4ebd968f364c
child 11792 f1911a4638af
equal deleted inserted replaced
11788:8e1fb9445d75 11789:71df2811b422
   117             store = MassiveObjectStore(cnx)
   117             store = MassiveObjectStore(cnx)
   118             timezone_eid = store.prepare_insert_entity('TimeZone')
   118             timezone_eid = store.prepare_insert_entity('TimeZone')
   119             store.prepare_insert_entity('Location', timezone=timezone_eid)
   119             store.prepare_insert_entity('Location', timezone=timezone_eid)
   120             store.flush()
   120             store.flush()
   121             store.commit()
   121             store.commit()
       
   122             store.finish()
   122             eid, etname = cnx.execute('Any X, TN WHERE X timezone TZ, X is T, '
   123             eid, etname = cnx.execute('Any X, TN WHERE X timezone TZ, X is T, '
   123                                       'T name TN')[0]
   124                                       'T name TN')[0]
   124             self.assertEqual(cnx.entity_from_eid(eid).cw_etype, etname)
   125             self.assertEqual(cnx.entity_from_eid(eid).cw_etype, etname)
   125 
   126 
   126     def test_index_not_dropped_by_init(self):
   127     def test_index_not_dropped_by_init(self):
   229 
   230 
   230     def test_on_rollback_callback(self):
   231     def test_on_rollback_callback(self):
   231         counter = itertools.count()
   232         counter = itertools.count()
   232         with self.admin_access.repo_cnx() as cnx:
   233         with self.admin_access.repo_cnx() as cnx:
   233             store = MassiveObjectStore(cnx, on_rollback_callback=lambda *_: next(counter))
   234             store = MassiveObjectStore(cnx, on_rollback_callback=lambda *_: next(counter))
   234             store.prepare_insert_entity('Location', nm='toto')
   235             # oversized attribute
   235             store.commit()  # commit modification to the database before flush
   236             store.prepare_insert_entity('Location', feature_class='toto')
   236             store.flush()
   237             store.flush()
   237         self.assertEqual(next(counter), 1)
   238         self.assertEqual(next(counter), 1)
   238 
       
   239     def test_slave_mode_exception(self):
       
   240         with self.admin_access.repo_cnx() as cnx:
       
   241             slave_store = MassiveObjectStore(cnx, slave_mode=True)
       
   242             self.assertRaises(RuntimeError, slave_store.finish)
       
   243 
   239 
   244     def test_simple_insert(self):
   240     def test_simple_insert(self):
   245         with self.admin_access.repo_cnx() as cnx:
   241         with self.admin_access.repo_cnx() as cnx:
   246             store = MassiveObjectStore(cnx)
   242             store = MassiveObjectStore(cnx)
   247             self.push_geonames_data(self.datapath('geonames.csv'), store)
   243             self.push_geonames_data(self.datapath('geonames.csv'), store)
   261             store.flush()
   257             store.flush()
   262 
   258 
   263             # Check index
   259             # Check index
   264             indexes = all_indexes(cnx)
   260             indexes = all_indexes(cnx)
   265             self.assertIn('entities_pkey', indexes)
   261             self.assertIn('entities_pkey', indexes)
   266             self.assertNotIn(build_index_name('owned_by_relation', ['eid_from', 'eid_to'], 'key_'),
   262             self.assertIn(build_index_name('owned_by_relation', ['eid_from', 'eid_to'], 'key_'),
   267                              indexes)
   263                           indexes)
   268             self.assertNotIn(build_index_name('owned_by_relation', ['eid_from'], 'idx_'),
   264             self.assertIn(build_index_name('owned_by_relation', ['eid_from'], 'idx_'),
   269                              indexes)
   265                           indexes)
   270 
   266 
   271             # Cleanup -> index
   267             # Cleanup -> index
   272             store.finish()
   268             store.finish()
   273 
   269 
   274             # Check index again
   270             # Check index again