def _test_list_owner(self, user_key): from openlibrary.mocks.mock_infobase import MockSite site = MockSite() list_key = user_key + "/lists/OL1L" self.save_doc(site, "/type/user", user_key) self.save_doc(site, "/type/list", list_key) list = site.get(list_key) assert list is not None assert isinstance(list, models.List) assert list.get_owner() is not None assert list.get_owner().key == user_key
def test_url(self): data = {"key": "/authors/OL1A", "type": {"key": "/type/author"}, "name": "foo"} e = models.Author(MockSite(), "/authors/OL1A", data=data) assert e.url() == "/authors/OL1A/foo" assert e.url(v=1) == "/authors/OL1A/foo?v=1" assert e.url(suffix="/add-photo") == "/authors/OL1A/foo/add-photo" data = { "key": "/authors/OL1A", "type": {"key": "/type/author"}, } e = models.Author(MockSite(), "/authors/OL1A", data=data) assert e.url() == "/authors/OL1A/unnamed"
def _monkeypatch_web(monkeypatch): monkeypatch.setattr(web, "ctx", web.storage(x=1)) monkeypatch.setattr(web.webapi, "ctx", web.ctx) _load_fake_context() web.ctx.lang = 'en' web.ctx.site = MockSite()
def mock_edition(self, edition_class): data = { "key": "/books/OL1M", "type": {"key": "/type/edition"}, "title": "foo" } return edition_class(MockSite(), "/books/OL1M", data=data)
def setup_monkeypatch(self, monkeypatch): ctx = web.storage() monkeypatch.setattr(web, "ctx", ctx) monkeypatch.setattr(web.webapi, "ctx", web.ctx) self._load_fake_context() web.ctx.lang = 'en' web.ctx.site = MockSite()
def _monkeypatch_web(self, monkeypatch): monkeypatch.setattr(web, "ctx", web.storage(x=1)) monkeypatch.setattr(web.webapi, "ctx", web.ctx) self._load_fake_context() web.ctx.site = MockSite() def setcookie(name, value, expires): self.cookie = dict(name=name, value=value, expires=expires) monkeypatch.setattr(web, "setcookie", setcookie)
def setup_monkeypatch(self, monkeypatch): self.d = MockLoadTranslations() ctx = web.storage() monkeypatch.setattr(i18n, "load_translations", self.d) monkeypatch.setattr(web, "ctx", ctx) monkeypatch.setattr(web.webapi, "ctx", web.ctx) self._load_fake_context() web.ctx.lang = 'en' web.ctx.site = MockSite()
def test_get_ebook_info(self): data = { "key": "/books/OL1M", "type": { "key": "/type/edition" }, "title": "foo" } e = models.Edition(MockSite(), "/books/OL1M", data=data) assert e.get_ebook_info() == {}
def test_url(self): e = self.mock_edition(models.Edition) assert e.url() == "/books/OL1M/foo" assert e.url(v=1) == "/books/OL1M/foo?v=1" assert e.url(suffix="/add-cover") == "/books/OL1M/foo/add-cover" data = { "key": "/books/OL1M", "type": {"key": "/type/edition"}, } e = models.Edition(MockSite(), "/books/OL1M", data=data) assert e.url() == "/books/OL1M/untitled"
def test_try_merge_full(): web.ctx.site = MockSite() bpl = { 'authors': [{ 'birth_date': u'1897', 'db_name': u'Green, Constance McLaughlin 1897-', 'entity_type': 'person', 'name': u'Green, Constance McLaughlin', 'personal_name': u'Green, Constance McLaughlin' }], 'full_title': u'Eli Whitney and the birth of American technology', 'isbn': [u'188674632X'], 'normalized_title': u'eli whitney and the birth of american technology', 'number_of_pages': 215, 'publish_date': '1956', 'publishers': [u'HarperCollins', u'[distributed by Talman Pub.]'], 'short_title': u'eli whitney and the birth', 'source_record_loc': 'bpl101.mrc:0:1226', 'titles': [ u'Eli Whitney and the birth of American technology', u'eli whitney and the birth of american technology' ] } # This existing needs to be an Edition Thing object. existing = { 'authors': [{ 'birth_date': u'1897', 'db_name': u'Green, Constance McLaughlin 1897-', 'entity_type': 'person', 'name': u'Green, Constance McLaughlin', 'personal_name': u'Green, Constance McLaughlin' }], 'full_title': u'Eli Whitney and the birth of American technology.', 'isbn': [], 'normalized_title': u'eli whitney and the birth of american technology', 'number_of_pages': 215, 'publish_date': '1956', 'publishers': ['Little, Brown'], 'short_title': u'eli whitney and the birth', 'source_record_loc': 'marc_records_scriblio_net/part04.dat:119539872:591', 'title': 'Eli Whitney and the birth of American technology.', 'type': { 'key': '/type/edition' }, 'key': '/books/OL1M' } web.ctx.site.save_many([existing]) ed = web.ctx.site.get('/books/OL1M') assert try_merge(bpl, '/books/OL1M', ed) is True
def setup_method(self, method): web.ctx.site = MockSite()