def test_no_allow_delete_on_conflict(self): rows = [ {"username": "******", "work_id": 1, "edition_id": 1, "notes": "Jimmeny"}, {"username": "******", "work_id": 2, "edition_id": 1, "notes": "Cricket"}, ] self.db.multiple_insert("booknotes", rows) resp = Booknotes.update_work_id("1", "2") assert resp == {'rows_changed': 0, 'rows_deleted': 0, 'failed_deletes': 1} assert [dict(row) for row in self.db.select("booknotes")] == rows
def main(self, test=False): params = web.input(key='', test='') # Provide an escape hatch to let POST requests preview if test is False and params.test: test = True summary = {'key': params.key, 'redirect_chain': [], 'resolved_key': None} if params.key: redirect_chain = Work.get_redirect_chain(params.key) summary['redirect_chain'] = [ { "key": thing.key, "occurrences": {}, "updates": {} } for thing in redirect_chain ] summary['resolved_key'] = redirect_chain[-1].key for r in summary['redirect_chain']: olid = r['key'].split('/')[-1][2:-1] new_olid = summary['resolved_key'].split('/')[-1][2:-1] # count reading log entries r['occurrences']['readinglog'] = len( Bookshelves.get_works_shelves(olid)) r['occurrences']['ratings'] = len( Ratings.get_all_works_ratings(olid)) r['occurrences']['booknotes'] = len( Booknotes.get_booknotes_for_work(olid)) r['occurrences']['observations'] = len( Observations.get_observations_for_work(olid)) # track updates r['updates']['readinglog'] = Bookshelves.update_work_id( olid, new_olid, _test=test ) r['updates']['ratings'] = Ratings.update_work_id( olid, new_olid, _test=test ) r['updates']['booknotes'] = Booknotes.update_work_id( olid, new_olid, _test=test ) r['updates']['observations'] = Observations.update_work_id( olid, new_olid, _test=test ) return delegate.RawText( json.dumps(summary), content_type="application/json")
def resolve_redirect_chain(cls, work_key: str, test: bool = False) -> dict[str, Any]: summary: dict[str, Any] = { 'key': work_key, 'redirect_chain': [], 'resolved_key': None, } redirect_chain = cls.get_redirect_chain(work_key) summary['redirect_chain'] = [{ "key": thing.key, "occurrences": {}, "updates": {} } for thing in redirect_chain] summary['resolved_key'] = redirect_chain[-1].key for r in summary['redirect_chain']: olid = r['key'].split('/')[-1][2:-1] # 'OL1234x' --> '1234' new_olid = summary['resolved_key'].split('/')[-1][2:-1] # count reading log entries r['occurrences']['readinglog'] = len( Bookshelves.get_works_shelves(olid)) r['occurrences']['ratings'] = len( Ratings.get_all_works_ratings(olid)) r['occurrences']['booknotes'] = len( Booknotes.get_booknotes_for_work(olid)) r['occurrences']['observations'] = len( Observations.get_observations_for_work(olid)) # track updates r['updates']['readinglog'] = Bookshelves.update_work_id(olid, new_olid, _test=test) r['updates']['ratings'] = Ratings.update_work_id(olid, new_olid, _test=test) r['updates']['booknotes'] = Booknotes.update_work_id(olid, new_olid, _test=test) r['updates']['observations'] = Observations.update_work_id( olid, new_olid, _test=test) return summary