def test_view_tasks_twitter_stream_listener_get_state(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions_no_votes.json', kind={'Question': Question,'State': State}) twitter_stream_listener = TwitterStreamListener() test_text = "#AL #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == "AL" test_text = "#no I agree #AL" result = twitter_stream_listener.get_state_from_string(test_text) assert result == "AL" test_text = "#ALAL #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None test_text = "AL #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None test_text = "#AL #AK #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None test_text = "#no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None
def test_view_tasks_twitter_stream_listener_get_sway(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions_no_votes.json', kind={'Question': Question,'State': State}) twitter_stream_listener = TwitterStreamListener() test_text = "#SWAY20 #SWAY10" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "NO #SWAY MAN" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "NO SWAY MAN" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "NO #SWAY20 #SWAY MAN" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "#SWAY2 Testing" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 2 test_text = "Testing #SWAY200" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 200
def test_view_tasks_twitter_stream_listener_add_vote_for_question(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions_no_votes.json', kind={'Question': Question,'State': State}) current_question = Question.get_current_question() assert len(current_question.state_scores) == 0 twitter_stream_listener = TwitterStreamListener() twitter_stream_listener.add_vote_for_question(0, 30, "CA", current_question) current_question = Question.get_current_question() assert len(current_question.state_scores) == 1 assert current_question.state_scores[0].state_abbreviation == "CA" assert current_question.state_scores[0].party_score_votes[0] == 1 assert current_question.state_scores[0].party_score_votes[1] == 0 assert current_question.state_scores[0].party_score_sway[0] == 30 assert current_question.state_scores[0].party_score_sway[1] == 0 twitter_stream_listener.add_vote_for_question(0, 50, "CA", current_question) twitter_stream_listener.add_vote_for_question(1, 20, "CA", current_question) assert current_question.state_scores[0].party_score_votes[0] == 2 assert current_question.state_scores[0].party_score_votes[1] == 1 assert current_question.state_scores[0].party_score_sway[0] == 80 assert current_question.state_scores[0].party_score_sway[1] == 20 twitter_stream_listener.add_vote_for_question(1, 30, "WA", current_question) assert len(current_question.state_scores) == 2 assert current_question.state_scores[1].state_abbreviation == "WA" assert current_question.state_scores[1].party_score_votes[0] == 0 assert current_question.state_scores[1].party_score_votes[1] == 1 assert current_question.state_scores[1].party_score_sway[0] == 0 assert current_question.state_scores[1].party_score_sway[1] == 30
def test_view_tasks_twitter_stream_listener_get_sway(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions_no_votes.json", kind={"Question": Question, "State": State}) twitter_stream_listener = TwitterStreamListener() test_text = "#SWAY20 #SWAY10" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "NO #SWAY MAN" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "NO SWAY MAN" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "NO #SWAY20 #SWAY MAN" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 0 test_text = "#SWAY2 Testing" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 2 test_text = "Testing #SWAY200" result = twitter_stream_listener.get_sway_from_string(test_text) assert result == 200
def test_view_tasks_twitter_stream_listener_get_state(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions_no_votes.json", kind={"Question": Question, "State": State}) twitter_stream_listener = TwitterStreamListener() test_text = "#AL #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == "AL" test_text = "#no I agree #AL" result = twitter_stream_listener.get_state_from_string(test_text) assert result == "AL" test_text = "#ALAL #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None test_text = "AL #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None test_text = "#AL #AK #no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None test_text = "#no I agree" result = twitter_stream_listener.get_state_from_string(test_text) assert result == None
def test_view_tasks_twitter_stream_listener_add_vote_for_question(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions_no_votes.json", kind={"Question": Question, "State": State}) current_question = Question.get_current_question() assert len(current_question.state_scores) == 0 twitter_stream_listener = TwitterStreamListener() twitter_stream_listener.add_vote_for_question(0, 30, "CA", current_question) current_question = Question.get_current_question() assert len(current_question.state_scores) == 1 assert current_question.state_scores[0].state_abbreviation == "CA" assert current_question.state_scores[0].party_score_votes[0] == 1 assert current_question.state_scores[0].party_score_votes[1] == 0 assert current_question.state_scores[0].party_score_sway[0] == 30 assert current_question.state_scores[0].party_score_sway[1] == 0 twitter_stream_listener.add_vote_for_question(0, 50, "CA", current_question) twitter_stream_listener.add_vote_for_question(1, 20, "CA", current_question) assert current_question.state_scores[0].party_score_votes[0] == 2 assert current_question.state_scores[0].party_score_votes[1] == 1 assert current_question.state_scores[0].party_score_sway[0] == 80 assert current_question.state_scores[0].party_score_sway[1] == 20 twitter_stream_listener.add_vote_for_question(1, 30, "WA", current_question) assert len(current_question.state_scores) == 2 assert current_question.state_scores[1].state_abbreviation == "WA" assert current_question.state_scores[1].party_score_votes[0] == 0 assert current_question.state_scores[1].party_score_votes[1] == 1 assert current_question.state_scores[1].party_score_sway[0] == 0 assert current_question.state_scores[1].party_score_sway[1] == 30
def test_view_tasks_twitter_stream_listener_get_party(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions_no_votes.json', kind={'Question': Question,'State': State}) twitter_stream_listener = TwitterStreamListener() # party from string extraction current_question = Question.get_current_question() current_question_party = current_question.party test_text = "#NO #no I disagree" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == 1 - current_question_party # Inverse current party test_text = "I disagree #no" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == 1 - current_question_party # Inverse current party test_text = "#YeS I agree" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == current_question_party test_text = "#YeSssir I agree" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == None test_text = "#nobody agree(s)" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == None test_text = "NO no I disagree" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == None test_text = "#Yes #Yes #no I agree" result = twitter_stream_listener. \ get_party_from_string_using_question(test_text, current_question) assert result == None
def test_view_tasks_twitter_stream_listener_get_party(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions_no_votes.json", kind={"Question": Question, "State": State}) twitter_stream_listener = TwitterStreamListener() # party from string extraction current_question = Question.get_current_question() current_question_party = current_question.party test_text = "#NO #no I disagree" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == 1 - current_question_party # Inverse current party test_text = "I disagree #no" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == 1 - current_question_party # Inverse current party test_text = "#YeS I agree" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == current_question_party test_text = "#YeSssir I agree" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == None test_text = "#nobody agree(s)" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == None test_text = "NO no I disagree" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == None test_text = "#Yes #Yes #no I agree" result = twitter_stream_listener.get_party_from_string_using_question(test_text, current_question) assert result == None
def test_view_tasks_twitter_stream_listener_on_data(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions_no_votes.json', kind={'Question': Question,'State': State}) twitter_stream = open(os.path.join(os.path.dirname(__file__), 'twitter_stream.json')) twitter_stream = json.load(twitter_stream) twitter_stream_listener = TwitterStreamListener() twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_old"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_old"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_current_invalid"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_post"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_mention"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_favourite"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_favourite_reply"])) users = User.get_all() assert len(users) == 0 current_question = Question.get_current_question() assert len(current_question.state_scores) == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_current_valid_user1"])) users = User.get_all() assert len(users) == 1 assert "https" in users[0].profile_image_url current_question = Question.get_current_question() assert len(current_question.state_scores) == 1 assert current_question.state_scores[0].state_abbreviation == "CA" assert current_question.state_scores[0].party_score_votes[0] == 0 assert current_question.state_scores[0].party_score_votes[1] == 1 assert current_question.state_scores[0].party_score_sway[0] == 0 assert current_question.state_scores[0].party_score_sway[1] == \ User.get_starting_sway_points() assert users[0].sway_points == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_current_valid_user1"])) users = User.get_all() assert len(users) == 1 assert len(users[0].votes) == 1 assert users[0].sway_points == 0 current_question = Question.get_current_question() assert len(current_question.state_scores) == 1 assert current_question.state_scores[0].state_abbreviation == "CA" assert current_question.state_scores[0].party_score_votes[0] == 0 assert current_question.state_scores[0].party_score_votes[1] == 1 assert current_question.state_scores[0].party_score_sway[0] == 0 assert current_question.state_scores[0].party_score_sway[1] == \ User.get_starting_sway_points() assert users[0].sway_points == 0 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_current_valid_user2"])) users = User.get_all() assert len(users) == 2 assert "https" in users[1].profile_image_url current_question = Question.get_current_question() assert len(current_question.state_scores) == 2 assert current_question.state_scores[1].state_abbreviation == "WA" assert current_question.state_scores[1].party_score_votes[0] == 1 assert current_question.state_scores[1].party_score_votes[1] == 0 assert current_question.state_scores[1].party_score_sway[0] == 20 assert current_question.state_scores[1].party_score_sway[1] == 0 assert users[1].sway_points == User.get_starting_sway_points() - 20 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_reply_current_valid_user2"])) users = User.get_all() assert len(users) == 2 assert current_question.state_scores[1].state_abbreviation == "WA" assert current_question.state_scores[1].party_score_votes[0] == 1 assert current_question.state_scores[1].party_score_votes[1] == 0 assert current_question.state_scores[1].party_score_sway[0] == 20 assert current_question.state_scores[1].party_score_sway[1] == 0 assert users[1].sway_points == User.get_starting_sway_points() - 20 twitter_stream_listener.on_data( json.dumps(twitter_stream["twitter_retweet"])) users = User.get_all() assert len(users) == 3 assert users[2].sway_points == User.get_starting_sway_points() + \ sway_points_backend["rewteet_poll"] assert "https" in users[2].profile_image_url
def test_view_tasks_twitter_stream_listener_add_vote_for_screenname(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions.json', kind={'Question': Question,'State': State}) twitter_stream_listener = TwitterStreamListener() current_question = Question.get_current_question() result = twitter_stream_listener.\ add_vote_for_screenname(current_question, "Vote text #yes", "123", None, # Invalid state 1, 0, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") assert result == False result = twitter_stream_listener.\ add_vote_for_screenname(current_question, "Vote text #CA", "123", "CA", None, # Invalid party 0, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") assert result == False # First valid user result = twitter_stream_listener.\ add_vote_for_screenname(current_question, "Vote text #CA #yes", "123", "CA", 0, 100, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") assert result == True user = User.query_by_userid("jrgrafton").get() assert user != None assert len(user.votes) == 1 assert user.votes[0].question.get().key == current_question.key assert user.votes[0].vote_text == "Vote text #CA #yes" assert user.votes[0].replyid == "123" assert user.votes[0].state_abbreviation == "CA" assert user.votes[0].party == 0 assert user.votes[0].sway_points == 100 # Second vote for user on same question result = twitter_stream_listener.\ add_vote_for_screenname(current_question, "Vote text #WA #no", "123", "WA", 1, 0, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") assert result == False # Second valid user result = twitter_stream_listener.\ add_vote_for_screenname(current_question, "Vote text for user 2 #WA #no", "123", "WA", 1, 50, "jrgrafton_test", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") assert result == True users = User.get_all() assert len(users) == 2 user = users[1] assert len(user.votes) == 1 assert user.votes[0].question.get().key == current_question.key assert user.votes[0].vote_text == "Vote text for user 2 #WA #no" assert user.votes[0].replyid == "123" assert user.votes[0].state_abbreviation == "WA" assert user.votes[0].party == 1 assert user.votes[0].sway_points == 50 # Go to new question and test valid votes reponse = self.app.get('/tasks/twitter_post_status' \ '?question_cadence_minutes=1') current_question = Question.get_current_question() # Second vote for new question should work result = twitter_stream_listener.\ add_vote_for_screenname(current_question, "Vote second question text #WA #no", "124", "WA", 1, 10, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") assert result == True user = User.query_by_userid("jrgrafton").get() assert user != None assert len(user.votes) == 2 assert user.votes[1].vote_text == "Vote second question text #WA #no" assert user.votes[1].question.get().key == current_question.key assert user.votes[1].replyid == "124" assert user.votes[1].state_abbreviation == "WA" assert user.votes[1].party == 1 assert user.votes[1].sway_points == 10
def test_view_tasks_twitter_stream_listener_process_retweet_from_screename(self): load_fixture('tests/states.json', kind={'State': State}) load_fixture('tests/questions.json', kind={'Question': Question,'State': State}) twitter_stream_listener = TwitterStreamListener() current_question = Question.get_current_question() # Invalid retweet id twitter_stream_listener.\ process_retweet_from_screename(current_question, -1, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") users = User.get_all() assert len(users) == 0 # Valid retweet id - new user twitter_stream_listener.\ process_retweet_from_screename(current_question, current_question.twitterid, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") users = User.get_all() assert len(users) == 1 assert users[0].sway_points == User.get_starting_sway_points() + \ sway_points_backend["rewteet_poll"] assert "https" in users[0].profile_image_url # Ensure no extra sway given for retweet twitter_stream_listener.\ process_retweet_from_screename(current_question, current_question.twitterid, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") users = User.get_all() assert len(users) == 1 assert users[0].sway_points == User.get_starting_sway_points() + \ sway_points_backend["rewteet_poll"] # Test existing user reweet user = User( userid = "jrgrafton2", sway_points = 30 ) user.put() # Valid retweet id - new user twitter_stream_listener.\ process_retweet_from_screename(current_question, current_question.twitterid, "jrgrafton2", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg") users = User.get_all() assert len(users) == 2 assert users[1].sway_points == 30 + sway_points_backend["rewteet_poll"]
def test_view_tasks_twitter_stream_listener_on_data(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions_no_votes.json", kind={"Question": Question, "State": State}) twitter_stream = open(os.path.join(os.path.dirname(__file__), "twitter_stream.json")) twitter_stream = json.load(twitter_stream) twitter_stream_listener = TwitterStreamListener() twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_old"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_old"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_current_invalid"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_post"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_mention"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_favourite"])) users = User.get_all() assert len(users) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_favourite_reply"])) users = User.get_all() assert len(users) == 0 current_question = Question.get_current_question() assert len(current_question.state_scores) == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_current_valid_user1"])) users = User.get_all() assert len(users) == 1 assert "https" in users[0].profile_image_url current_question = Question.get_current_question() assert len(current_question.state_scores) == 1 assert current_question.state_scores[0].state_abbreviation == "CA" assert current_question.state_scores[0].party_score_votes[0] == 0 assert current_question.state_scores[0].party_score_votes[1] == 1 assert current_question.state_scores[0].party_score_sway[0] == 0 assert current_question.state_scores[0].party_score_sway[1] == User.get_starting_sway_points() assert users[0].sway_points == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_current_valid_user1"])) users = User.get_all() assert len(users) == 1 assert len(users[0].votes) == 1 assert users[0].sway_points == 0 current_question = Question.get_current_question() assert len(current_question.state_scores) == 1 assert current_question.state_scores[0].state_abbreviation == "CA" assert current_question.state_scores[0].party_score_votes[0] == 0 assert current_question.state_scores[0].party_score_votes[1] == 1 assert current_question.state_scores[0].party_score_sway[0] == 0 assert current_question.state_scores[0].party_score_sway[1] == User.get_starting_sway_points() assert users[0].sway_points == 0 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_current_valid_user2"])) users = User.get_all() assert len(users) == 2 assert "https" in users[1].profile_image_url current_question = Question.get_current_question() assert len(current_question.state_scores) == 2 assert current_question.state_scores[1].state_abbreviation == "WA" assert current_question.state_scores[1].party_score_votes[0] == 1 assert current_question.state_scores[1].party_score_votes[1] == 0 assert current_question.state_scores[1].party_score_sway[0] == 20 assert current_question.state_scores[1].party_score_sway[1] == 0 assert users[1].sway_points == User.get_starting_sway_points() - 20 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_reply_current_valid_user2"])) users = User.get_all() assert len(users) == 2 assert current_question.state_scores[1].state_abbreviation == "WA" assert current_question.state_scores[1].party_score_votes[0] == 1 assert current_question.state_scores[1].party_score_votes[1] == 0 assert current_question.state_scores[1].party_score_sway[0] == 20 assert current_question.state_scores[1].party_score_sway[1] == 0 assert users[1].sway_points == User.get_starting_sway_points() - 20 twitter_stream_listener.on_data(json.dumps(twitter_stream["twitter_retweet"])) users = User.get_all() assert len(users) == 3 assert users[2].sway_points == User.get_starting_sway_points() + sway_points_backend["rewteet_poll"] assert "https" in users[2].profile_image_url
def test_view_tasks_twitter_stream_listener_add_vote_for_screenname(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions.json", kind={"Question": Question, "State": State}) twitter_stream_listener = TwitterStreamListener() current_question = Question.get_current_question() result = twitter_stream_listener.add_vote_for_screenname( current_question, "Vote text #yes", "123", None, # Invalid state 1, 0, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) assert result == False result = twitter_stream_listener.add_vote_for_screenname( current_question, "Vote text #CA", "123", "CA", None, # Invalid party 0, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) assert result == False # First valid user result = twitter_stream_listener.add_vote_for_screenname( current_question, "Vote text #CA #yes", "123", "CA", 0, 100, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) assert result == True user = User.query_by_userid("jrgrafton").get() assert user != None assert len(user.votes) == 1 assert user.votes[0].question.get().key == current_question.key assert user.votes[0].vote_text == "Vote text #CA #yes" assert user.votes[0].replyid == "123" assert user.votes[0].state_abbreviation == "CA" assert user.votes[0].party == 0 assert user.votes[0].sway_points == 100 # Second vote for user on same question result = twitter_stream_listener.add_vote_for_screenname( current_question, "Vote text #WA #no", "123", "WA", 1, 0, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) assert result == False # Second valid user result = twitter_stream_listener.add_vote_for_screenname( current_question, "Vote text for user 2 #WA #no", "123", "WA", 1, 50, "jrgrafton_test", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) assert result == True users = User.get_all() assert len(users) == 2 user = users[1] assert len(user.votes) == 1 assert user.votes[0].question.get().key == current_question.key assert user.votes[0].vote_text == "Vote text for user 2 #WA #no" assert user.votes[0].replyid == "123" assert user.votes[0].state_abbreviation == "WA" assert user.votes[0].party == 1 assert user.votes[0].sway_points == 50 # Go to new question and test valid votes reponse = self.app.get("/tasks/twitter_post_status" "?question_cadence_minutes=1") current_question = Question.get_current_question() # Second vote for new question should work result = twitter_stream_listener.add_vote_for_screenname( current_question, "Vote second question text #WA #no", "124", "WA", 1, 10, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) assert result == True user = User.query_by_userid("jrgrafton").get() assert user != None assert len(user.votes) == 2 assert user.votes[1].vote_text == "Vote second question text #WA #no" assert user.votes[1].question.get().key == current_question.key assert user.votes[1].replyid == "124" assert user.votes[1].state_abbreviation == "WA" assert user.votes[1].party == 1 assert user.votes[1].sway_points == 10
def test_view_tasks_twitter_stream_listener_process_retweet_from_screename(self): load_fixture("tests/states.json", kind={"State": State}) load_fixture("tests/questions.json", kind={"Question": Question, "State": State}) twitter_stream_listener = TwitterStreamListener() current_question = Question.get_current_question() # Invalid retweet id twitter_stream_listener.process_retweet_from_screename( current_question, -1, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) users = User.get_all() assert len(users) == 0 # Valid retweet id - new user twitter_stream_listener.process_retweet_from_screename( current_question, current_question.twitterid, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) users = User.get_all() assert len(users) == 1 assert users[0].sway_points == User.get_starting_sway_points() + sway_points_backend["rewteet_poll"] assert "https" in users[0].profile_image_url # Ensure no extra sway given for retweet twitter_stream_listener.process_retweet_from_screename( current_question, current_question.twitterid, "jrgrafton", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) users = User.get_all() assert len(users) == 1 assert users[0].sway_points == User.get_starting_sway_points() + sway_points_backend["rewteet_poll"] # Test existing user reweet user = User(userid="jrgrafton2", sway_points=30) user.put() # Valid retweet id - new user twitter_stream_listener.process_retweet_from_screename( current_question, current_question.twitterid, "jrgrafton2", "https://pbs.twimg.com// \ profile_images//440698495// \ 9929_128442162134_504357134_ \ 2556732_5649977_n_bigger.jpg", ) users = User.get_all() assert len(users) == 2 assert users[1].sway_points == 30 + sway_points_backend["rewteet_poll"]