35 self.assertNotIn(dfsource, self.repo.sources) |
35 self.assertNotIn(dfsource, self.repo.sources) |
36 self.assertEqual(dfsource.latest_retrieval, None) |
36 self.assertEqual(dfsource.latest_retrieval, None) |
37 self.assertEqual(dfsource.synchro_interval, timedelta(seconds=60)) |
37 self.assertEqual(dfsource.synchro_interval, timedelta(seconds=60)) |
38 self.assertFalse(dfsource.fresh()) |
38 self.assertFalse(dfsource.fresh()) |
39 |
39 |
|
40 |
40 class AParser(datafeed.DataFeedParser): |
41 class AParser(datafeed.DataFeedParser): |
41 __regid__ = 'testparser' |
42 __regid__ = 'testparser' |
42 def process(self, url, raise_on_error=False): |
43 def process(self, url, raise_on_error=False): |
43 entity = self.extid2entity('http://www.cubicweb.org/', 'Card', |
44 entity = self.extid2entity('http://www.cubicweb.org/', 'Card', |
44 item={'title': u'cubicweb.org', |
45 item={'title': u'cubicweb.org', |
45 'content': u'the cw web site'}) |
46 'content': u'the cw web site'}) |
46 if not self.created_during_pull(entity): |
47 if not self.created_during_pull(entity): |
47 self.notify_updated(entity) |
48 self.notify_updated(entity) |
48 def before_entity_copy(self, entity, sourceparams): |
49 def before_entity_copy(self, entity, sourceparams): |
49 entity.cw_edited.update(sourceparams['item']) |
50 entity.cw_edited.update(sourceparams['item']) |
50 |
51 |
51 with self.temporary_appobjects(AParser): |
52 with self.temporary_appobjects(AParser): |
52 stats = dfsource.pull_data(self.session, force=True) |
53 session = self.repo.internal_session() |
|
54 stats = dfsource.pull_data(session, force=True) |
53 self.commit() |
55 self.commit() |
54 # test import stats |
56 # test import stats |
55 self.assertEqual(sorted(stats.keys()), ['created', 'updated']) |
57 self.assertEqual(sorted(stats.keys()), ['created', 'updated']) |
56 self.assertEqual(len(stats['created']), 1) |
58 self.assertEqual(len(stats['created']), 1) |
57 entity = self.execute('Card X').get_entity(0, 0) |
59 entity = self.execute('Card X').get_entity(0, 0) |
72 self.assertEqual(self.repo._type_source_cache[entity.eid], |
74 self.assertEqual(self.repo._type_source_cache[entity.eid], |
73 ('Card', 'system', 'http://www.cubicweb.org/', 'myfeed')) |
75 ('Card', 'system', 'http://www.cubicweb.org/', 'myfeed')) |
74 self.assertEqual(self.repo._extid_cache[('http://www.cubicweb.org/', 'system')], |
76 self.assertEqual(self.repo._extid_cache[('http://www.cubicweb.org/', 'system')], |
75 entity.eid) |
77 entity.eid) |
76 # test repull |
78 # test repull |
77 stats = dfsource.pull_data(self.session, force=True) |
79 session.set_cnxset() |
|
80 stats = dfsource.pull_data(session, force=True) |
78 self.assertEqual(stats['created'], set()) |
81 self.assertEqual(stats['created'], set()) |
79 self.assertEqual(stats['updated'], set((entity.eid,))) |
82 self.assertEqual(stats['updated'], set((entity.eid,))) |
80 # test repull with caches reseted |
83 # test repull with caches reseted |
81 self.repo._type_source_cache.clear() |
84 self.repo._type_source_cache.clear() |
82 self.repo._extid_cache.clear() |
85 self.repo._extid_cache.clear() |
83 stats = dfsource.pull_data(self.session, force=True) |
86 session.set_cnxset() |
|
87 stats = dfsource.pull_data(session, force=True) |
84 self.assertEqual(stats['created'], set()) |
88 self.assertEqual(stats['created'], set()) |
85 self.assertEqual(stats['updated'], set((entity.eid,))) |
89 self.assertEqual(stats['updated'], set((entity.eid,))) |
86 self.assertEqual(self.repo._type_source_cache[entity.eid], |
90 self.assertEqual(self.repo._type_source_cache[entity.eid], |
87 ('Card', 'system', 'http://www.cubicweb.org/', 'myfeed')) |
91 ('Card', 'system', 'http://www.cubicweb.org/', 'myfeed')) |
88 self.assertEqual(self.repo._extid_cache[('http://www.cubicweb.org/', 'system')], |
92 self.assertEqual(self.repo._extid_cache[('http://www.cubicweb.org/', 'system')], |