def test_timeline_command_paginated(self): status1 = self._tweet('igorsobreira', 'Just a simple tweet') status2 = self._tweet('somebody', 'Just another tweet') api = self.mocker.mock() api.home_timeline(page=1) self.mocker.result([status1]) api.home_timeline(page=2) self.mocker.result([status2]) self.mocker.replay() commands = TwitterCommands(api) text1, html1 = commands.home_timeline() text2, html2 = commands.home_timeline(page=2) self.mocker.verify() expected_html1 = '<a href="http://twitter.com/igorsobreira">@igorsobreira</a>: ' expected_html1 += 'Just a simple tweet' assert "@igorsobreira: Just a simple tweet" == text1 assert expected_html1 == html1 expected_html2 = '<a href="http://twitter.com/somebody">@somebody</a>: ' expected_html2 += 'Just another tweet' assert "@somebody: Just another tweet" == text2 assert expected_html2 == html2
def test_timeline_command(self): author1 = self.mocker.mock() author1.name self.mocker.result("igorsobreira") status1 = self.mocker.mock() status1.author self.mocker.result(author1) status1.text self.mocker.result("Just a simple tweet") author2 = self.mocker.mock() author2.name self.mocker.result("somebody") status2 = self.mocker.mock() status2.author self.mocker.result(author2) status2.text self.mocker.result("Just another tweet") api = self.mocker.mock() api.home_timeline() self.mocker.result([status1, status2]) self.mocker.replay() commands = TwitterCommands(api) result = commands.home_timeline() self.mocker.verify() assert "@igorsobreira: Just a simple tweet\n\n@somebody: Just another tweet" == result
def test_tweet_command_validate_length(self): api = self.mocker.mock() self.mocker.replay() commands = TwitterCommands(api) result = commands.update_status(u"o"*141) self.mocker.verify() assert u"Tweet too long, 141 characters. Must be up to 140." == result
def test_tweet_command(self): api = self.mocker.mock() api.update_status(u"this is a tweet to test the api") self.mocker.replay() commands = TwitterCommands(api) result = commands.update_status(u"this is a tweet to test the api") self.mocker.verify() assert u"Tweet sent" == result
def test_direct_message_command(self): api = self.mocker.mock() api.send_direct_message(screen_name="igorsobreira", text="hello") self.mocker.replay() commands = TwitterCommands(api) result = commands.send_direct_message(screen_name='igorsobreira', text='hello') self.mocker.verify() assert u"Message sent" == result
def test_direct_message_error_when_trying_to_send_to_non_friends(self): api = self.mocker.mock() api.send_direct_message(screen_name="unknown", text="hello") self.mocker.throw(TweepError(u"You cannot send messages to users who are not following you.")) self.mocker.replay() commands = TwitterCommands(api) result = commands.send_direct_message(screen_name='unknown', text='hello') self.mocker.verify() assert u"You cannot send messages to users who are not following you." == result
def test_timeline_command(self): status1 = self._tweet('igorsobreira', 'Just a simple tweet') status2 = self._tweet('somebody', 'Just another tweet') api = self.mocker.mock() api.home_timeline(page=1) self.mocker.result([status1, status2]) self.mocker.replay() commands = TwitterCommands(api) text, html = commands.home_timeline() self.mocker.verify() assert '@igorsobreira: Just a simple tweet\n\n@somebody: Just another tweet' == text expected_html = '<a href="http://twitter.com/igorsobreira">@igorsobreira</a>: ' expected_html += 'Just a simple tweet<br/><br/>' expected_html += '<a href="http://twitter.com/somebody">@somebody</a>: ' expected_html += 'Just another tweet' assert expected_html == html
def test_tweet_command_ignores_empty_tweets(self): commands = TwitterCommands("api") result = commands.update_status(" ") assert u"Empty tweet" == result
def test_not_found(self): commands = TwitterCommands("api") result = commands.resolve("command not found") assert (commands.not_found, {}) == result assert u"Command not found" == commands.not_found()
def test_resolve_direct_message_command(self): commands = TwitterCommands("api") result = commands.resolve(u"dm @igorsobreira hello") params = {'screen_name': 'igorsobreira', 'text': 'hello'} assert (commands.send_direct_message, params) == result
def test_resolve_tweet_comamnd(self): commands = TwitterCommands("api") result = commands.resolve(u"tweet this is a tweet") assert (commands.update_status, {'tweet': 'this is a tweet'}) == result
def test_resolve_timeline_command_paginated(self): commands = TwitterCommands("api") result = commands.resolve(u"timeline 2") assert (commands.home_timeline, {'page': '2'}) == result
def test_ignore_extra_spaces(self): commands = TwitterCommands("api") result = commands.resolve(u" timeline ") assert (commands.home_timeline, {}) == result
def test_resolve_timeline_command(self): commands = TwitterCommands("api") result = commands.resolve(u"timeline") assert (commands.home_timeline, {}) == result