def test_response_choice_relationships(session): # Creates a user for the the response user id for new_user in create_users(1): session.add(new_user) session.commit() # Creates a type of question to be used multiple_type = models.QuestionType('Multiple Choice') session.add(multiple_type) session.commit() # Creates a question for the poll multiple_question = models.Question(text='What is the meaning of life', question_type_id=multiple_type.id) session.add(multiple_question) session.commit() # Creates the choices for the question choice1 = models.Choice(text='42', question_id=multiple_question.id) choice2 = models.Choice(text='happiness', question_id=multiple_question.id) session.add(choice1) session.add(choice2) session.commit() # Creates a poll to be used in the response random_poll = models.Poll( creator_id=new_user.id, description='Super Random questions about life', questions=[multiple_question]) session.add(random_poll) session.commit() # Create a response chosen_choice = choice1 user_response = models.ResponseChoice(poll_id=random_poll.id, responder_user_id=new_user.id, question_id=multiple_question.id, choice_id=chosen_choice.id) session.add(user_response) session.commit() #Verify that there are relationships select_statement = select(models.ResponseChoice) response = session.execute(select_statement) queried_response = response.first()[0] assert queried_response.poll == random_poll assert queried_response.responder_user == new_user assert queried_response.question == multiple_question assert queried_response.choice == chosen_choice
def test_response_open_relationships(session): #Creates a user for the the response user id for new_user in create_users(1): session.add(new_user) session.commit() #Creates a type of question to be used open_type = models.QuestionType('Open Ended') session.add(open_type) session.commit() #Creates a question for the poll open_question = models.Question(text='What is the meaning of life', question_type_id=open_type.id) session.add(open_question) session.commit() #Creates a poll to be used in the response random_poll = models.Poll( creator_id=new_user.id, description='Super Random questions about life', questions=[open_question]) session.add(random_poll) session.commit() #Create a response user_response_text = "the meaning of life is 42" user_response = models.ResponseOpen(poll_id=random_poll.id, responder_user_id=new_user.id, question_id=open_question.id, open_response=user_response_text) session.add(user_response) session.commit() #Verify that there are relationships select_statement = select(models.ResponseOpen) response = session.execute(select_statement) queried_response = response.first()[0] assert queried_response.poll == random_poll assert queried_response.responder_user == new_user assert queried_response.question == open_question assert queried_response.open_response == user_response_text
def test_add_multiple_question_to_poll(session): #Creates a user for the the response user id for new_user in create_users(1): session.add(new_user) session.commit() # Creates a single type for questions multiple_type = models.QuestionType('Multiple Choice') session.add(multiple_type) session.commit() # Creates multiple questions using a single type first_question = models.Question(text='pizza', question_type_id=multiple_type.id) second_question = models.Question(text='sushi', question_type_id=multiple_type.id) third_question = models.Question(text='tacos', question_type_id=multiple_type.id) session.add(first_question) session.add(second_question) session.add(third_question) session.commit() # Creates a poll using the three questions made above food_poll = models.Poll( creator_id=new_user.id, description="What are your favorite foods?", questions=[first_question, second_question, third_question]) session.add(food_poll) session.commit() # Selects the poll from the database and asserts that it was assigned all three questions from above select_statement = select( models.Poll).where(models.Poll.id == food_poll.id) response = session.execute(select_statement) queried_poll = response.first()[0] assert queried_poll.questions == [ first_question, second_question, third_question ]
def find_all_multiple_choice_questions_in_poll(session): multiple_type = models.QuestionType('Multiple Choice') open_type = models.QuestionType('Open Ended') session.add(multiple_type) session.add(open_type) session.commit() multiple_question_first = models.Question( text='Minecraft', question_type_id=multiple_type.id) multiple_question_second = models.Question( text='Roblox', question_type_id=multiple_type.id) multiple_question_third = models.Question( text='Apex Legends', question_type_id=multiple_type.id) session.add(multiple_question_first) session.add(multiple_question_second) session.add(multiple_question_third) open_question_first = models.Question(text='What is the meaning of life', question_type_id=open_type.id) open_question_second = models.Question(text='what is love', question_type_id=open_type.id) session.add(open_question_first) session.add(open_question_second) session.commit() questions_list = [ multiple_question_first, multiple_question_second, multiple_question_third, open_question_first, open_question_second ] random_poll = models.Poll(description='Super Random questions about life', questions=questions_list) session.add(random_poll) session.commit() select_statement = select( models.Poll).where(models.Poll.question_type_id == multiple_type.id) response = session.execute(select_statement) queried_poll = response.first()[0]
def test_add_multiple_qestions_of_different_types_in_poll(session): #Creates a user for the the response user id for new_user in create_users(1): session.add(new_user) session.commit() # Creates multiple types for questions multiple_type = models.QuestionType('Multiple Choice') open_type = models.QuestionType('Open Ended') session.add(multiple_type) session.add(open_type) session.commit() # Creates Multiple question using the different types above multiple_question = models.Question(text='Minecraft', question_type_id=multiple_type.id) open_question = models.Question(text='What is the meaning of life', question_type_id=open_type.id) session.add(multiple_question) session.add(open_question) session.commit() # Creates a poll that includes the different question above random_poll = models.Poll(creator_id=new_user.id, description='Random questions about life', questions=[multiple_question, open_question]) session.add(random_poll) session.commit() # Checks that the poll includes both an open and multiple choice question select_statement = select( models.Poll).where(models.Poll.id == random_poll.id) response = session.execute(select_statement) queried_poll = response.first()[0] queried_poll.questions.should.contain(open_question) queried_poll.questions.should.contain(multiple_question)