# HG changeset patch # User dclinton@b35c0ba3-1128-0410-9219-0b39014e361d # Date 1244737392 0 # Branch dclinton # Node ID c867b935f947c1ce6f815e6706d807058b467a33 # Parent 056bb4e69e8955edeedd10b2d23a8d57a07db852 Added tests for 140 and 140+ character status updates in ascii and unicode. diff -r 056bb4e69e8955edeedd10b2d23a8d57a07db852 -r c867b935f947c1ce6f815e6706d807058b467a33 twitter.py --- a/twitter.py Tue Jun 09 13:45:19 2009 +0000 +++ b/twitter.py Thu Jun 11 16:23:12 2009 +0000 @@ -559,9 +559,11 @@ url = 'http://twitter.com/statuses/update.json' - if len(status) > CHARACTER_LIMIT: + status_length = len(status) + if status_length > CHARACTER_LIMIT: raise TwitterError("Text must be less than or equal to %d characters. " - "Consider using PostUpdates." % CHARACTER_LIMIT) + "Was %d. Consider using PostUpdates." % + (CHARACTER_LIMIT, status_length)) data = {'status': status} if in_reply_to_status_id: diff -r 056bb4e69e8955edeedd10b2d23a8d57a07db852 -r c867b935f947c1ce6f815e6706d807058b467a33 twitter_test.py --- a/twitter_test.py Tue Jun 09 13:45:19 2009 +0000 +++ b/twitter_test.py Thu Jun 11 16:23:12 2009 +0000 @@ -375,6 +375,35 @@ # This is rather arbitrary, but spot checking is better than nothing self.assertEqual(u'Моё судно на воздушной подушке полно угрей', status.text) + def testAciiStatusLength(self): + '''Test the length check of ascii status updates''' + self._AddHandler('http://twitter.com/statuses/update.json', + curry(self._OpenTestData, 'update.json')) + # Post 140 characters of ascii text + status = self._api.PostUpdate('abcdefghij' * 14) + # Post 141 characters of ascii text + try: + status = self._api.PostUpdate(('abcdefghij' * 14) + 'k') + except twitter.TwitterError: + pass # expected + else: + self.fail('TwitterError expected') + + def testUnicodeStatusLength(self): + '''Test the length check of ascii status updates''' + self._AddHandler('http://twitter.com/statuses/update.json', + curry(self._OpenTestData, 'update.json')) + # Post 140 characters of unicode text + status = self._api.PostUpdate(u'абвгдежзий' * 14) + # Post 141 characters of unicode text + try: + status = self._api.PostUpdate((u'абвгдежзий' * 14) + u'к') + except twitter.TwitterError: + pass # expected + else: + self.fail('TwitterError expected') + + def testGetReplies(self): '''Test the twitter.Api GetReplies method''' self._AddHandler('http://twitter.com/statuses/replies.json?page=1',