def test_clear_cache(self): mock_site = MagicMock() dp = BetterDataProvider( site=mock_site, db=MagicMock(), ia_db=MagicMock(), ) mock_site.get_many.return_value = [ Thing( mock_site, '/works/OL1W', { 'key': '/works/OL1W', 'type': { 'key': '/type/work' }, }, ) ] assert mock_site.get_many.call_count == 0 dp.get_document('/works/OL1W') assert mock_site.get_many.call_count == 1 dp.clear_cache() dp.get_document('/works/OL1W') assert mock_site.get_many.call_count == 2
def mk_author(a,ak): class Pseudo_thing(Thing): def _get(self, key, revision=None): return self def __setattr__(self, a, v): self.__dict__[a] = v authortype = Thing(web.ctx.site,u'/type/author') d = Pseudo_thing(web.ctx.site, six.text_type(ak)) d.name = a d.type = authortype # print >> web.debug, ('mk_author made', d) # experimentally try db retrieval to compare with our test object # dba = web.ctx.site.get(ak) # print >> web.debug, ('mk_author db retrieval', dba) return d