def test_should_sleep_for_length_of_interval_after_each_query( self, m_time, m_query_twitter): ct = Chantweep(Mock(), Mock(), '#foo', 'foo', search_interval=30) ct._execute() m_time.sleep.assert_called_with(30)
def test_should_post_status_to_irc(self, m_create_irc_message): m_create_irc_message.return_value = 'foobar' srv = Mock() status = Mock() status.text = 'Foo bar' ct = Chantweep(srv, Mock(), '#foo', 'foo') ct._post_to_irc(status) srv.privmsg.assert_called_with('#foo', 'foobar')
def test_should_query_twitter_with_keyword(self, m_time): api = Mock() status = Mock() status.id = 1 api.GetSearch.return_value = [status] ct = Chantweep(Mock(), api, '#foo', 'foo') ct._query_twitter() api.GetSearch.assert_called_with('foo', lang=None, since_id=None)
def test_should_create_irc_message(self): status = Mock() status.user.name = 'Name' status.user.screen_name = 'screenname' status.text = 'Text' status.id = 123 ct = Chantweep(Mock(), Mock(), '#foo', 'foo') msg = ct._create_irc_message(status) self.assertEqual(msg, ('Twitter: "Text" -- Name. http://twitter.com/' 'screenname/status/123'))
def test_should_post_only_first_status_on_first_query(self, m_time, m_post): api = Mock() status = Mock() status.id = 2 status2 = Mock() status2.id = 1 api.GetSearch.return_value = [status, status2] ct = Chantweep(Mock(), api, '#foo', 'foo', search_interval=30) ct._query_twitter() m_post.assert_called_with(status) self.assertEqual(m_post.call_count, 1)
def test_should_join_the_channel(self): srv = Mock() ct = Chantweep(srv, Mock(), '#foo', sentinel.search_keyword) ct._join() srv.join.assert_called_with('#foo')