def test_users(session): users = populate_users(n=10) session.add_all(users) session.commit() role_admin = Role.query.filter_by(name=RoleEnum.ADMIN).first() user_admin = User.query.order_by(func.random()).first() user_admin.roles.append(role_admin) session.add(user_admin) session.commit() for u in users: assert u.roles is not None, "role not added to user"
def user_reservations(session): """ Creates reservations for one user """ user = populate_users(n=1) session.add_all(user) session.commit() authors = populate_authors(n=2) session.add_all(authors) session.commit() books = populate_books(n=2, authors=authors) session.add_all(books) session.commit() magazines = populate_magazines(n=2) session.add_all(magazines) session.commit() copies = [] copies.append(populate_copies(books[0], n=1)[0]) copies.append(populate_copies(books[1], n=1)[0]) copies.append(populate_copies(magazines[0], n=1)[0]) copies.append(populate_copies(magazines[1], n=1)[0]) session.add_all(copies) session.commit() reservations = [] reservations.append(populate_rental_logs(copies[0].id, user[0].id, n=1)[0]) reservations.append(populate_rental_logs(copies[1].id, user[0].id, n=1)[0]) reservations.append(populate_rental_logs(copies[2].id, user[0].id, n=1)[0]) reservations.append(populate_rental_logs(copies[3].id, user[0].id, n=1)[0]) session.add_all(reservations) session.commit() reservations[0].book_status = BookStatus.RESERVED reservations[1].book_status = BookStatus.BORROWED reservations[2].book_status = BookStatus.RESERVED reservations[3].book_status = BookStatus.BORROWED yield user[0], (books[0], reservations[0]), (books[1], reservations[1]), \ (magazines[0], reservations[2]), (magazines[1], reservations[3]) for r in reservations: session.delete(r) for c in copies: session.delete(c) for b in books: session.delete(b) for m in magazines: session.delete(m) session.delete(user[0]) session.commit()
def test_07_delete_all_records(self): populate_users() expect_records(self, User, 20) delete_all_records() expect_records(self, User, 0) print("test_07_delete_all_records")
def test_05_populate_users(self): expect_records(self, User, 20) populate_users() expect_records(self, User, 20) print("test_05_repopulate_users")