def test_model_question(self): # Load fixtures load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions.json', kind={'Question': Question,'State': State}) question_entity = Question.get_current_question() # Check current question assert question_entity.key.id() == "q2" State.update_state_scores_for_completed_question(question_entity) Question.tally_college_and_vote_scores(question_entity) # NY and TX was a draw so random 2 votes will be added assert question_entity.vote_score[0] == (505 + 120 + 100 + 150) or \ (505 + 120 + 100 + 150) + 1 or \ (505 + 120 + 100 + 150) + 2 assert question_entity.vote_score[1] == (510 + 240 + 100 + 150) or \ (510 + 240 + 100 + 150) +1 or \ (510 + 240 + 100 + 150) +2 # NY and TX was a draw so could go either way (29, 38) assert question_entity.college_score[0] == 0 or 29 or 38 or (29 + 38) assert question_entity.college_score[1] == (55 + 12) + 0 or \ (55 + 12) + 29 or \ (55 + 12) + 38 or \ (55 + 12) + (29 + 38) # Check get next questions question_entity = Question.get_next_question() assert question_entity.key.id() == "q3" # Check get last question start time current_question_start_time = Question.get_current_question_start_time() current_question_start_time_string = str(current_question_start_time) assert current_question_start_time_string == "2016-01-23 00:00:00"
def test_model_question_complete(self): # Load fixtures load_fixture('tests/questions_complete.json', kind={'Question': Question}) # Check get next questions question_entity = Question.get_next_question() assert question_entity == None # Check get current question start time current_question_start_time = Question.get_current_question_start_time() assert current_question_start_time == None
def test_model_question_unstarted(self): # Load fixtures load_fixture('tests/questions_unstarted.json', kind={'Question': Question}) # Check get next questions question_entity = Question.get_next_question() assert question_entity.key.id() == "q1" # Check get current question start time current_question_start_time = Question.get_current_question_start_time() assert current_question_start_time == None
def test_model_question_complete(self): # Load fixtures load_fixture('tests/questions_complete.json', kind={'Question': Question}) # Check get next questions question_entity = Question.get_next_question() assert question_entity == None # Check get current question start time current_question_start_time = Question.get_current_question_start_time( ) assert current_question_start_time == None
def test_model_question_unstarted(self): # Load fixtures load_fixture('tests/questions_unstarted.json', kind={'Question': Question}) # Check get next questions question_entity = Question.get_next_question() assert question_entity.key.id() == "q1" # Check get current question start time current_question_start_time = Question.get_current_question_start_time( ) assert current_question_start_time == None
def twitter_post_status(): """ Potentially post a new status to Twitter """ # Can be overriden in GET request question_cadence_minutes = \ int(request.args.get('question_cadence_minutes', 60 * 6)) post_to_twitter = request.args.get('post_to_twitter', False) next_question = Question.get_next_question() if next_question is not None \ and __is_time_for_new_question(question_cadence_minutes): current_question = Question.get_current_question() if post_to_twitter != False: try: twitter_api = TwitterAPI() status = twitter_api.update_status(next_question.question_text) next_question.twitterid = str(status.id) next_question.put() except TweepError as e: pass #TODO: do something - message to monitoring? if current_question is not None: # Update overall state scores State.update_state_scores_for_completed_question(current_question) # Update overall question scores Question.tally_college_and_vote_scores(current_question) # Update end of question user sway scores users = User.get_all() for user in users: __attribute_sway_points_for_user(current_question, user) current_question.end_time = datetime.datetime.now() current_question.put() next_question.start_time = datetime.datetime.now() next_question.put() return 'Posted new status [%s]' % next_question.question_text, 200 return 'New question not ready', 200
def twitter_post_status(): """ Potentially post a new status to Twitter """ # Can be overriden in GET request question_cadence_minutes = \ int(request.args.get('question_cadence_minutes', 60 * 6)) post_to_twitter = request.args.get('post_to_twitter', False) next_question = Question.get_next_question() if next_question is not None \ and __is_time_for_new_question(question_cadence_minutes): current_question = Question.get_current_question() if post_to_twitter != False: try: twitter_api = TwitterAPI() status = twitter_api.update_status(next_question.question_text) next_question.twitterid = str(status.id) next_question.put() except TweepError as e: pass #TODO: do something - message to monitoring? if current_question is not None: # Update overall state scores State.update_state_scores_for_completed_question(current_question) # Update overall question scores Question.tally_college_and_vote_scores(current_question) # Update end of question user sway scores users = User.get_all() for user in users: __attribute_sway_points_for_user(current_question, user) current_question.end_time = datetime.datetime.now() current_question.put() next_question.start_time = datetime.datetime.now() next_question.put() return 'Posted new status [%s]' % next_question.question_text, 200 return 'New question not ready', 200
def test_model_question(self): # Load fixtures load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions.json', kind={ 'Question': Question, 'State': State }) question_entity = Question.get_current_question() # Check current question assert question_entity.key.id() == "q2" State.update_state_scores_for_completed_question(question_entity) Question.tally_college_and_vote_scores(question_entity) # NY and TX was a draw so random 2 votes will be added assert question_entity.vote_score[0] == (505 + 120 + 100 + 150) or \ (505 + 120 + 100 + 150) + 1 or \ (505 + 120 + 100 + 150) + 2 assert question_entity.vote_score[1] == (510 + 240 + 100 + 150) or \ (510 + 240 + 100 + 150) +1 or \ (510 + 240 + 100 + 150) +2 # NY and TX was a draw so could go either way (29, 38) assert question_entity.college_score[0] == 0 or 29 or 38 or (29 + 38) assert question_entity.college_score[1] == (55 + 12) + 0 or \ (55 + 12) + 29 or \ (55 + 12) + 38 or \ (55 + 12) + (29 + 38) # Check get next questions question_entity = Question.get_next_question() assert question_entity.key.id() == "q3" # Check get last question start time current_question_start_time = Question.get_current_question_start_time( ) current_question_start_time_string = str(current_question_start_time) assert current_question_start_time_string == "2016-01-23 00:00:00"