password = "******" reg = api.register("testSessionStatus", password) tokenMod = reg["token"] idMod = reg["idModerator"] pollTitle = "Test de poll" poll = api.postPoll(tokenMod, idMod, pollTitle) idPoll = poll["idPoll"] code = api.putSessionWithId(tokenMod, idMod, idPoll, "open")["code"] # Switch to user view tokenUser = api.connectUser(code)["token"] session = api.getSession(tokenUser) user_idMod = session["idModerator"] user_idPoll = session["idPoll"] user_poll = api.getPollWithId(tokenUser, user_idMod, user_idPoll) if user_poll != poll: print("[FAILED] The polls are not similar") sys.exit(1) api.putSessionWithId(tokenMod, idMod, idPoll, "quarantined") user_poll2 = api.getPollWithId(tokenUser, user_idMod, user_idPoll)
pollTitle = "Test de poll" poll = api.postPoll(tokenMod, idMod, pollTitle) idPoll = poll["idPoll"] q1 = api.postQuestion(tokenMod, idMod, idPoll, "Question 1", "visible", 1, 0, 0) ans1 = ["haha", "Réponse 2"] api.postAnswer(tokenMod, idMod, idPoll, q1["idQuestion"], ans1[0], "") api.postAnswer(tokenMod, idMod, idPoll, q1["idQuestion"], ans1[1], "") code = api.putSessionWithId(tokenMod, idMod, idPoll, "open")["code"] # Switch to user view tokenUser = api.connectUser(code)["token"] session = api.getSession(tokenUser) user_idMod = session["idModerator"] user_idPoll = session["idPoll"] all_questions = api.getQuestion(tokenUser, user_idMod, user_idPoll) idQuestion1 = all_questions[0]["idQuestion"] answer1 = api.getAnswer(tokenUser, user_idMod, user_idPoll, idQuestion1)[0] vote1 = api.vote(tokenUser, user_idMod, user_idPoll, idQuestion1, answer1["idAnswer"], True) if vote1["code"] != 200:
"visible", 1, 1, 1) questionId = question["idQuestion"] # Insert two different answers in the poll. At least one must be selected, at # most one. answer1 = api.postAnswer(moderatorToken, moderatorId, pollId, questionId, "A1", "") answer2 = api.postAnswer(moderatorToken, moderatorId, pollId, questionId, "A2", "") # Open the poll code = api.putSessionWithId(moderatorToken, moderatorId, pollId, "open")["code"] # Connect with a user participantToken = api.connectUser(code)["token"] # Ensure there are no votes now votes = api.statistics_poll(moderatorToken, moderatorId, pollId) if votes[0]["answers"][0]["positive"] != 0: print("[FAILED] No votes yet") sys.exit(1) if votes[0]["answers"][1]["positive"] != 0: print("[FAILED] No votes yet") sys.exit(1) # Let the user vote once api.vote(participantToken, moderatorId, pollId, questionId, answer1["idAnswer"], True) # Ensure there is exactly one vote now.