def test_get_user_for_user_id(app): with app.app_context(): g.user_id = 'test' service = AuthService('secret') user = service.get_user_for_user_id(1) assert user.id == 1 with app.app_context(): g.user_id = 'test' service = AuthService('secret') user = service.get_user_for_user_id(100) assert user is None
def test_create_thread(app): with app.app_context(): auth_service = AuthService('secret') thread_service = ThreadService() user1 = auth_service.get_user_for_user_id(100) user2 = auth_service.get_user_for_user_id(101) # test runtime error for users that do not exist with pytest.raises(RuntimeError): thread = thread_service.create_thread(user1, user2) assert thread is None with app.app_context(): auth_service = AuthService('secret') thread_service = ThreadService() user1 = auth_service.get_user_for_user_id(1) user2 = auth_service.get_user_for_user_id(2) # test not creating duplicate thread for thread that already exists thread = thread_service.create_thread(user1, user2) assert thread is None with app.app_context(): auth_service = AuthService('secret') thread_service = ThreadService() user1 = auth_service.get_user_for_user_id(1) user2 = auth_service.get_user_for_user_id(2) # test overriding thread for thread that already exists thread = thread_service.create_thread(user1, user2, force=True) assert thread is not None and thread.is_active is True with app.app_context(): auth_service = AuthService('secret') thread_service = ThreadService() user3 = auth_service.get_user_for_user_id(3) user4 = auth_service.get_user_for_user_id(4) # test new thread creation thread = thread_service.create_thread(user3, user4, force=True) assert thread