def tc5_inside(): inf = tc4_inside() l3 = inf[0][2] if l3.has_permission(Permission.delete_document): docs_set = inf[1] log('l3', 'deleted', '1 copy d1') db.session.delete(docs_set[0].copies[0]) db.session.commit() return inf[0], docs_set, inf[2], inf[3], inf[4], inf[5]
def tc6_inside(): inf = tc4_inside() l1 = inf[0][0] p1 = inf[2][0] p2 = inf[2][1] p3 = inf[2][2] s = inf[3][0] v = inf[4][0] d3 = inf[1][2] copies_d3 = inf[1][5] loan_p1_d3 = p1.checkout(copies_d3[0]) loan_p1_d3.status = Loan.Status.approved log('p1', 'checkouted', '1 copy d3') loan_p2_d3 = p2.checkout(copies_d3[1]) loan_p2_d3.status = Loan.Status.approved log('p2', 'checkouted', '1 copy d3') loan_s_d3 = s.checkout(copies_d3[2]) loan_s_d3.status = Loan.Status.approved log('s', 'checkouted', '1 copy d3') loans = [loan_p1_d3, loan_p2_d3, loan_s_d3] qr_v_d3 = QueuedRequest( patron=v, document=d3) log('v','checkout','1 copy d3') db.session.add(qr_v_d3) qr_p3_d3 = QueuedRequest( patron=p3, document=d3 ) log('p3', 'checkout','1 copy d3') db.session.add(qr_p3_d3) flag_l1_no_out_req = False db.session.commit() response = client.post('/login', data={ 'login': '******', 'password': '******' }) db.session.commit() response = client.get('/admin/documents/3/outstanding_request') if response.status == '302 FOUND' and response.location == 'http://localhost/login': flag_l1_no_out_req = True # if not l1.has_permission(Permission.outstanding_request): # flag_l1_no_out_req = True # log('l1','outst req','d3') # if not flag_l1_no_out_req: # log('l1', 'fail outst req', 'd3') return inf[0], inf[1], loans, inf[3], inf[4], inf[5], flag_l1_no_out_req
def state_of_system_librarians(): reload_db() l1 = register_test_account(Librarian, login='******', password='******') l1.access_level = 1 log('admin', 'created', 'librarian1') l2 = register_test_account(Librarian, login='******', password='******') l2.access_level = 2 log('admin', 'created', 'librarian2') l3 = register_test_account(Librarian, login='******', password='******') l3.access_level = 3 log('admin', 'created', 'librarian3') db.session.add(l1) db.session.add(l2) db.session.add(l3) db.session.commit() sys_librarians = Librarian.query return sys_librarians
def tc4_inside(): librs = state_of_system_librarians() l1 = librs.filter(Librarian.login == 'librarian1').first() l2 = librs.filter(Librarian.login == 'librarian2').first() l3 = librs.filter(Librarian.login == 'librarian3').first() if (l2.has_permission(Permission.create_document)): d1 = create_instance(Book, title='Introduction to Algorithms', authors=['Thomas H. Cormen', 'Charles E. Leiserson', 'Ronald L. Rivest', 'Clifford Stein'], publisher='MIT Press', publishment_year=2009, edition=3, reference=False, price=5000, keywords=['Algorithms', 'Data Structures', 'Complexity', 'Computational Theory']) log('l2', 'created', 'd1') d2 = create_instance(Book, title='Algorithms + Data Structures = Programs', authors=['Niklaus Wirth'], publisher='Prentice Hall PTR', publishment_year=1978, edition=1, reference=False, price=5000, keywords=['Algorithms', 'Data Structures', 'Search Algorithms', 'Pascal']) log('l2', 'created', 'd2') d3 = create_instance(Book, title='The Art of Computer Programming', authors=['Donald E. Knuth'], publisher='Addison Wesley Longman Publishing Co., Inc.', publishment_year=1997, edition=3, price=5000, keywords=['Algorithms', 'Combinatorial Algorithms', 'Recursion']) log('l2', 'created', 'd3') copies_d1 = [create_instance(DocumentCopy, document=d1) for i in range(3)] log('l2', 'created', '3 copy d1') copies_d2 = [create_instance(DocumentCopy, document=d2) for i in range(3)] log('l2', 'created', '3 copy d2') copies_d3 = [create_instance(DocumentCopy, document=d3) for i in range(3)] log('l2', 'created', '3 copy d3') docs_created = True if (l2.has_permission(Permission.create_patron)): p1 = register_test_account(Professor, name='Sergey Afonso', address='Via Margutta, 3', phone='30001', card_number=1010) log('l2', 'created', 'p1') p2 = register_test_account(Professor, name='Nadia Teixeira', address='Via Sacra, 13', phone='30002', card_number=1011) log('l2', 'created', 'p2') p3 = register_test_account(Professor, name='Elvira Espindola', address='Via del Corso, 22', phone='30003', card_number=1100) log('l2', 'created', 'p3') s = register_test_account(StudentPatron, name='Andrey Velo', address=': Avenida Mazatlan 250', phone='30004', card_number=1101) log('l2', 'created', 's') v = register_test_account(VisitingProfessorPatron, name='Veronika Rama', address='Stret Atocha, 27', phone='30005', card_number=1110) log('l2', 'created', 'v') patrons_created = True librarians = [l1, l2, l3] flags = [docs_created, patrons_created] docs_set = [d1, d2, d3, copies_d1, copies_d2, copies_d3] users_set_patrons = [p1, p2, p3] users_set_students = [s] users_set_visiting_profs = [v] return librarians, docs_set, users_set_patrons, users_set_students, users_set_visiting_profs, flags
def tc7_inside(): inf = tc4_inside() l3 = inf[0][2] p1 = inf[2][0] p2 = inf[2][1] p3 = inf[2][2] s = inf[3][0] v = inf[4][0] copies_d3 = inf[1][5] d3 = inf[1][2] loan_p1_d3 = p1.checkout(copies_d3[0]) loan_p1_d3.status = Loan.Status.approved db.session.add(loan_p1_d3) log('p1', 'checkouted', '1 copy d3') loan_p2_d3 = p2.checkout(copies_d3[1]) loan_p2_d3.status = Loan.Status.approved db.session.add(loan_p2_d3) log('p2', 'checkouted', '1 copy d3') loan_s_d3 = s.checkout(copies_d3[2]) loan_s_d3.status = Loan.Status.approved db.session.add(loan_p2_d3) log('s', 'checkouted', '1 copy d3') qr_v_d3 = QueuedRequest( patron=v, document=d3) log('v', 'checkout', '1 copy d3') db.session.add(qr_v_d3) qr_p3_d3 = QueuedRequest( patron=p3, document=d3 ) log('p3', 'checkout', '1 copy d3') db.session.add(qr_p3_d3) db.session.commit() if (l3.has_permission(Permission.outstanding_request)): log('l3','outst req','d3') d3.outstanding_request() waiting_list = QueuedRequest.query.order_by(QueuedRequest.created_at).all() waiting_list = sorted(waiting_list, key=lambda x: (x.priority, x.created_at)) if waiting_list == []: flag_waiting_list_empty = True if v.queued_documents == [] and p3.queued_documents == []: flag_v_and_p3_no_docs = True loans = [] flags = flag_waiting_list_empty and flag_v_and_p3_no_docs return inf[0], inf[1], loans, inf[3], inf[4], inf[5], flags