def test_delete(db): from dlx import DB from dlx.marc import Bib from datetime import datetime bib = Bib().set('245', 'a', 'This record will self-destruct') bib.commit() bib.delete() assert Bib.match_id(bib.id) == None history = DB.handle['bib_history'].find_one({'_id': bib.id}) assert history['deleted']['user'] == 'admin' assert isinstance(history['deleted']['time'], datetime)
def test_4_5_6(self): for rtype, code, tag in [('bib', 'UND', '191'), ('speech', 'ITS', '791'), ('vote', 'VOT', '791')]: report = ReportList.get_by_name('{}_incorrect_session_{}'.format( rtype, tag)) args = {} args['authority'] = 1 Bib({ '_id': 1 }).set_values( (tag, 'a', 'A/SESSION_1/GOOD'), (tag, 'b', 1), (tag, 'c', 1), (tag, 'r', 'ASESSION_1'), ('930', 'a', code), ).commit() Bib({ '_id': 2 }).set_values( (tag, 'a', 'A/SESSION_1/BAD'), (tag, 'b', 1), (tag, 'c', 1), (tag, 'r', 'x'), ('930', 'a', code), ).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'A/SESSION_1/BAD') for x in ['C.1', 'RES', 'INF', 'BUR']: Bib({ '_id': 1 }).set_values((tag, 'a', 'A/{}/SESSION_1/GOOD'.format(x)), (tag, 'b', 1), (tag, 'c', 1), (tag, 'r', 'ASESSION_1'), ('930', 'a', code), ('991', 'a', 3)).commit() Bib({ '_id': 2 }).set_values((tag, 'a', 'A/{}/SESSION_1/BAD'.format(x)), (tag, 'b', 1), (tag, 'c', 1), (tag, 'r', 'x'), ('930', 'a', code), ('991', 'a', 4)).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertRegex(results[0][1], r'^A/.+/SESSION_1/BAD') Bib.match_id(1).set(tag, 'a', 'S/2018/GOOD').set(tag, 'r', 'S73').commit() Bib.match_id(2).set(tag, 'a', 'S/2018/BAD').set(tag, 'r', 'x').commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'S/2018/BAD') Bib.match_id(1).set(tag, 'a', 'S/RES/GOOD(2018)').commit() Bib.match_id(2).set(tag, 'a', 'S/RES/BAD(2018)').commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'S/RES/BAD(2018)') Bib.match_id(1).set(tag, 'a', 'S/PRST/2018/GOOD').commit() Bib.match_id(2).set(tag, 'a', 'S/PRST/2018/BAD').commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'S/PRST/2018/BAD') Bib.match_id(1).set(tag, 'a', 'E/RES/SESSION_1').set(tag, 'r', 'ESESSION_1').commit() Bib.match_id(2).set(tag, 'a', 'E/RES/SESSION_1/BAD').set(tag, 'r', 'x').commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'E/RES/SESSION_1/BAD')
def test_10(self): report = ReportList.get_by_name('speech_incorrect_991') args = {} args['authority'] = 1 Bib({ '_id': 1 }).set_values(('791', 'a', 'A/SESSION_1/GOOD'), ('791', 'b', 1), ('791', 'c', 1), ('930', 'a', 'ITS'), ('991', 'a', 3)).commit() Bib({ '_id': 2 }).set_values(('791', 'a', 'A/SESSION_1/BAD'), ('791', 'b', 1), ('791', 'c', 1), ('930', 'a', 'ITS'), ('991', 'a', 4)).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'A/SESSION_1/BAD') for x in ['C.1', 'RES', 'INF', 'BUR']: Bib({ '_id': 1 }).set_values(('791', 'a', 'A/{}/SESSION_1/GOOD'.format(x)), ('791', 'b', 1), ('791', 'c', 1), ('930', 'a', 'ITS'), ('991', 'a', 3)).commit() Bib({ '_id': 2 }).set_values(('791', 'a', 'A/{}/SESSION_1/BAD'.format(x)), ('791', 'b', 1), ('791', 'c', 1), ('930', 'a', 'ITS'), ('991', 'a', 4)).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertRegex(results[0][1], r'^A/.+/SESSION_1/BAD') Bib.match_id(1).set('791', 'a', 'S/2018/GOOD').set('991', 'a', 5).commit() Bib.match_id(2).set('791', 'a', 'S/2018/BAD').set('991', 'a', 4).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'S/2018/BAD') Bib.match_id(1).set('791', 'a', 'S/RES/GOOD(2018)').set('991', 'a', 5).commit() Bib.match_id(2).set('791', 'a', 'S/RES/BAD(2018)').set('991', 'a', 4).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'S/RES/BAD(2018)') Bib.match_id(1).set('791', 'a', 'S/PRST/2018/GOOD').set('991', 'a', 5).commit() Bib.match_id(2).set('791', 'a', 'S/PRST/2018/BAD').set('991', 'a', 4).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'S/PRST/2018/BAD') Bib.match_id(1).set('791', 'a', 'E/RES/SESSION_1').set('991', 'a', 4).commit() Bib.match_id(2).set('791', 'a', 'E/RES/SESSION_1/BAD').set('991', 'a', 5).commit() results = report.execute(args) self.assertEqual(len(results), 1) self.assertEqual(results[0][1], 'E/RES/SESSION_1/BAD')