Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
    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
Esempio n. 7
0
    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
Esempio n. 8
0
 def test_tweet_command_ignores_empty_tweets(self):
     commands = TwitterCommands("api")
     result = commands.update_status("  ")
     
     assert u"Empty tweet" == result
Esempio n. 9
0
    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()
Esempio n. 10
0
 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 
Esempio n. 11
0
 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
Esempio n. 12
0
 def test_resolve_timeline_command_paginated(self):
     commands = TwitterCommands("api")
     result = commands.resolve(u"timeline 2")
     
     assert (commands.home_timeline, {'page': '2'}) == result
Esempio n. 13
0
    def test_ignore_extra_spaces(self):
        commands = TwitterCommands("api")
        result = commands.resolve(u"  timeline   ")

        assert (commands.home_timeline, {}) == result
Esempio n. 14
0
 def test_resolve_timeline_command(self):
     commands = TwitterCommands("api")
     result = commands.resolve(u"timeline")
     
     assert (commands.home_timeline, {}) == result