예제 #1
0
 def test_one_mark_2(self):
     "Marking tweets as seen adds the missing ones to the db"
     with _all_mocked():
         t2m.one('tw2', only_mark_as_seen=True)
     db = self.read_db()
     self.assertEqual(set(range(10)), set(db['tw2']['done']))
     self.assertEqual({1, 4}, set(db['tw1']['done']))  # check unchanged
예제 #2
0
 def test_one_send_4_toots(self):
     self.new_db()
     with _all_mocked() as (status_post, media_post):
         t2m.one('tw1', wait_seconds=0, number=4)
     self.assertEqual(4, status_post.call_count)
     # 1 and 4 were already there and 0, 2, 3, 5 have just been sent:
     self.assertEqual({1, 4, 0, 2, 3, 5},
                      set(self.read_db()['tw1']['done']))
예제 #3
0
 def test_one_mark_1(self):
     "Marking tweets as seen adds them to the db"
     with _all_mocked() as (status_post, media_post):
         t2m.one('tw1', only_mark_as_seen=True)
     self.assertEqual(0, status_post.call_count)
     db = self.read_db()
     self.assertEqual(set(range(10)), set(db['tw1']['done']))
     self.assertNotIn('done', db['tw2'])  # check unchanged
예제 #4
0
 def test_strip(self):
     tweet = _fake_tweet(
         full_text=('Tweet with a normal short url https://t.co/dummy'
                    ' and an extra at the end, to be stripped:'
                    ' https://t.co/0123456789'),
         urls=[
             mock.Mock(url='https://t.co/dummy',
                       expanded_url='https://example.com/dummy')
         ],
     )
     with _all_mocked([tweet]) as (status_post, media_post):
         t2m.one('tw2', wait_seconds=0, strip_trailing_url=True)
         self.assertEqual(1, status_post.call_count)
     args, kwargs = status_post.call_args
     expected = ('Tweet with a normal short url https://example.com/dummy'
                 ' and an extra at the end, to be stripped:')
     self.assertEqual((expected, ), args)
예제 #5
0
 def test_retweet(self):
     tweet = _fake_tweet(retweeted_status=mock.Mock(
         id='retweeted',
         full_text='retweeted text',
         urls=(),
         media=(),
         user=mock.Mock(screen_name='retweeted_user')), )
     with _all_mocked([tweet]) as (status_post, media_post):
         t2m.one('tw2', wait_seconds=0)
         self.assertEqual(0, status_post.call_count)
     with _all_mocked([tweet]) as (status_post, media_post):
         t2m.one('tw2', wait_seconds=0, retweets=True)
     self.assertEqual(1, status_post.call_count)
     args, kwargs = status_post.call_args
     self.assertEqual(
         (u'« retweeted text »\n\n— Retweet '
          u'https://twitter.com/retweeted_user/status/retweeted', ), args)
예제 #6
0
 def test_complete_tweet(self):
     tweet = _fake_tweet(
         full_text='normal with urls and medias',
         urls=[
             mock.Mock(url='http://short_url/index.html',
                       expanded_url='http://expanded_url/index.html')
         ],
         media=[
             mock.Mock(media_url=self.data_url + 'media1.txt'),
             mock.Mock(media_url=self.data_url + 'media2.txt')
         ])
     with _all_mocked([tweet]) as (status_post, media_post):
         t2m.one('tw2', wait_seconds=0)
         self.assertEqual(1, status_post.call_count)
     args, kwargs = status_post.call_args
     self.assertEqual(('normal with urls and medias', ), args)
     self.assertEqual(
         {
             'media_ids': ['media1 content\n', 'media2 content\n'],
             'spoiler_text': None
         }, kwargs)
예제 #7
0
 def test_private_tweet(self):
     tweet = _fake_tweet(full_text='@private_response')
     with _all_mocked([tweet]) as (status_post, media_post):
         t2m.one('tw2', wait_seconds=0)
     self.assertEqual(0, status_post.call_count)