def test_mix_response(self): moxer = mox.Mox() moxer.StubOutWithMock(ArtifactAccessor, "search") inquiry = "how many elephants are in pakistan during winter" # queries from longest word to shortest until target results are reached ArtifactAccessor.search("elephants").AndReturn(create_content_list(5)) ArtifactAccessor.search("pakistan").AndReturn(create_content_list(5)) moxer.ReplayAll() sources, text = new_default_mixer().mix_response(inquiry) print text moxer.VerifyAll()
def test_act_responds_to_first_non_ignored_public_message(self): moxer = Mox() bundle = _create_api_actor_and_selector(moxer) api = bundle.api actor = bundle.actor selector = bundle.selector analyzer = bundle.analyzer _no_direct_messages(api) # this message should not be responded to. livelock doesn't respond to retweets msg1 = _create_message(moxer, 1, "mhawthorne", "RT @livelock some random ass shit") # this message obviously warrants a response msg2 = _create_message(moxer, 2, "mmattozzi", "@livelock why is blood spattered all over @mhawthorne's car?") # messages are returned in reverse chronological order _mentions(api, msg2, msg1) # not responding and responding as appropriate _should_respond(analyzer, msg1, False) _should_respond(analyzer, msg2, True) _no_response_found(msg2) _search_results("spattered", create_content_list(1)) response = _post_response_to(moxer, api, msg2) _save_response(msg2, response) _format(response) moxer.ReplayAll() actor.act() moxer.VerifyAll()
def test_act_direct_message(self): moxer = Mox() api = _create_default_mocks(moxer) _build_standard_config(moxer) bundle = _create_actor_and_delegates(api, moxer) actor = bundle.actor direct_id = 1 direct = moxer.CreateMock(twitter.DirectMessage) user = moxer.CreateMock(twitter.User) direct.id = direct_id direct.sender_screen_name = "mikemattozzi" direct.text = "why is blood spattered all over your car?" _return_direct_messages(api, [direct]) post = moxer.CreateMockAnything() post.id = 101 _return_replies(api, ()) TwitterResponseAccessor.get_by_message_id(str(direct_id)) ArtifactAccessor.search("spattered").AndReturn(create_content_list(10)) # response api.PostDirectMessage(direct.sender_screen_name, IgnoreArg()).AndReturn(post) TwitterResponseAccessor.create(str(direct.id), response_id=str(post.id), user=direct.sender_screen_name) post.AsDict().AndReturn({}) moxer.ReplayAll() actor.act() moxer.VerifyAll()
def test_act_public_message(self): moxer = Mox() bundle = _create_api_actor_and_selector(moxer) api = bundle.api actor = bundle.actor analyzer = bundle.analyzer _no_direct_messages(api) msg = _create_message( moxer, 1, "mmattozzi", "@livelock why is blood spattered all over @mhawthorne's car?") _mentions(api, msg) _should_respond(analyzer, msg, True) _no_response_found(msg) _search_results("spattered", create_content_list(1)) response = _post_response_to(moxer, api, msg) _save_response(msg, response) _format(response) moxer.ReplayAll() actor.act() moxer.VerifyAll()
def test_act_public_message(self): moxer = Mox() bundle = _create_api_actor_and_selector(moxer) api = bundle.api actor = bundle.actor analyzer = bundle.analyzer _no_direct_messages(api) msg = _create_message(moxer, 1, "mmattozzi", "@livelock why is blood spattered all over @mhawthorne's car?") _mentions(api, msg) _should_respond(analyzer, msg, True) _no_response_found(msg) _search_results("spattered", create_content_list(1)) response = _post_response_to(moxer, api, msg) _save_response(msg, response) _format(response) moxer.ReplayAll() actor.act() moxer.VerifyAll()
def test_act_responds_to_first_non_ignored_public_message(self): moxer = Mox() bundle = _create_api_actor_and_selector(moxer) api = bundle.api actor = bundle.actor selector = bundle.selector analyzer = bundle.analyzer _no_direct_messages(api) # this message should not be responded to. livelock doesn't respond to retweets msg1 = _create_message(moxer, 1, "mhawthorne", "RT @livelock some random ass shit") # this message obviously warrants a response msg2 = _create_message( moxer, 2, "mmattozzi", "@livelock why is blood spattered all over @mhawthorne's car?") # messages are returned in reverse chronological order _mentions(api, msg2, msg1) # not responding and responding as appropriate _should_respond(analyzer, msg1, False) _should_respond(analyzer, msg2, True) _no_response_found(msg2) _search_results("spattered", create_content_list(1)) response = _post_response_to(moxer, api, msg2) _save_response(msg2, response) _format(response) moxer.ReplayAll() actor.act() moxer.VerifyAll()