예제 #1
0
  def test_update_twitter_pictures(self):
    sources = []
    for screen_name in ('a', 'b', 'c'):
      auth_entity = oauth_twitter.TwitterAuth(
        id='id', token_key='key', token_secret='secret',
        user_json=json.dumps({'name': 'Ryan',
                              'screen_name': screen_name,
                              'profile_image_url': 'http://pi.ct/ure',
                              }))
      auth_entity.put()
      sources.append(Twitter.new(None, auth_entity=auth_entity).put())

    user_objs = [{'screen_name': sources[0].id(),
                  'profile_image_url': 'http://pi.ct/ure',
                  }, {'screen_name': sources[1].id(),
                      'profile_image_url_https': 'http://new/pic_normal.jpg',
                      'profile_image_url': 'http://bad/http',
                  }]

    cron.TWITTER_USERS_PER_LOOKUP = 2
    lookup_url = gr_twitter.API_BASE + cron.TWITTER_API_USER_LOOKUP
    self.expect_urlopen(lookup_url % 'a,c', json.dumps(user_objs))
    self.expect_urlopen(lookup_url % 'b', json.dumps(user_objs))
    self.mox.ReplayAll()

    resp = cron.application.get_response('/cron/update_twitter_pictures')
    self.assertEqual(200, resp.status_int)

    self.assertEquals('http://pi.ct/ure', sources[0].get().picture)
    self.assertEquals('http://new/pic.jpg', sources[1].get().picture)
예제 #2
0
 def setUp(self):
   super(TwitterTest, self).setUp()
   oauth_dropins.appengine_config.TWITTER_APP_KEY = 'my_app_key'
   oauth_dropins.appengine_config.TWITTER_APP_SECRET = 'my_app_secret'
   self.handler.messages = []
   self.auth_entity = oauth_twitter.TwitterAuth(
     id='my_string_id',
     token_key='my_key', token_secret='my_secret',
     user_json=json.dumps({'name': 'Ryan Barrett',
                           'screen_name': 'snarfed_org',
                           'description': 'something about me',
                           'profile_image_url': 'http://pi.ct/ure',
                           }))
   self.auth_entity.put()
   self.tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
예제 #3
0
  def test_update_twitter_picture_user_lookup_404s(self):
    auth_entity = oauth_twitter.TwitterAuth(
      id='id', token_key='key', token_secret='secret',
      user_json=json.dumps({'name': 'Bad',
                            'screen_name': 'bad',
                            'profile_image_url': 'http://pi.ct/ure',
                           }))
    auth_entity.put()
    source = Twitter.new(None, auth_entity=auth_entity).put()

    lookup_url = gr_twitter.API_BASE + cron.TWITTER_API_USER_LOOKUP
    self.expect_urlopen(lookup_url % 'bad', status=404)
    self.mox.ReplayAll()

    resp = cron.application.get_response('/cron/update_twitter_pictures')
    self.assertEqual(200, resp.status_int)

    self.assertEquals('http://pi.ct/ure', source.get().picture)