Ejemplo n.º 1
0
    def test_update_instagram_pictures_batch(self):
        self.setup_instagram(weekday=3)
        self.expect_instagram_profile_fetch('d')
        self.mox.ReplayAll()

        sources = []
        auth_entity = indieauth.IndieAuth(id='http://foo.com/', user_json='{}')
        for username in 'a', 'b', 'c', 'd', 'e', 'f', 'g':
            source = Instagram.new(None,
                                   auth_entity=auth_entity,
                                   features=['listen'],
                                   actor={
                                       'username': username,
                                       'image': {
                                           'url': 'http://old/pic'
                                       }
                                   })
            sources.append(source.put())

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

        for i, source in enumerate(sources):
            self.assertEqual('http://new/pic' if i == 3 else 'http://old/pic',
                             source.get().picture)
Ejemplo n.º 2
0
    def test_update_instagram_picture_profile_404s(self):
        self.setup_instagram(batch_size=1)

        auth_entity = indieauth.IndieAuth(id='http://foo.com/', user_json='{}')
        source = Instagram.new(None,
                               auth_entity=auth_entity,
                               features=['listen'],
                               actor={
                                   'username': '******',
                                   'image': {
                                       'url': 'http://old/pic'
                                   }
                               })
        source.put()

        super(HandlerTest,
              self).expect_requests_get(gr_instagram.HTML_BASE_URL + 'x/',
                                        status_code=404,
                                        allow_redirects=False)
        self.mox.ReplayAll()

        resp = tasks.application.get_response(
            '/cron/update_instagram_pictures')
        self.assertEqual(200, resp.status_int)
        self.assertEqual('http://old/pic', source.key.get().picture)
Ejemplo n.º 3
0
    def test_update_instagram_pictures(self):
        self.setup_instagram(batch_size=1)
        for username in 'a', 'b':
            self.expect_instagram_profile_fetch(username)
        self.mox.ReplayAll()

        sources = []
        auth_entity = indieauth.IndieAuth(id='http://foo.com/', user_json='{}')
        for username in 'a', 'b', 'c', 'd':
            source = Instagram.new(None,
                                   auth_entity=auth_entity,
                                   features=['listen'],
                                   actor={
                                       'username': username,
                                       'image': {
                                           'url': 'http://old/pic'
                                       }
                                   })
            # test that we skip disabled and deleted sources
            if username == 'c':
                source.status = 'disabled'
            elif username == 'd':
                source.features = []
            sources.append(source.put())

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

        self.assertEquals('http://new/pic', sources[0].get().picture)
        self.assertEquals('http://new/pic', sources[1].get().picture)
        self.assertEquals('http://old/pic', sources[2].get().picture)
        self.assertEquals('http://old/pic', sources[3].get().picture)
Ejemplo n.º 4
0
  def setUp(self):
    super(InstagramTest, self).setUp()
    self.handler.messages = []
    self.auth_entity = indieauth.IndieAuth(id='http://foo.com', user_json=json_dumps({
      'me': 'https://snarfed.org/',
      'rel-me': ['http://instagram.com/snarfed'],
      'h-card': {
        # ...
      },
    }))
    self.inst = instagram.Instagram.new(
      self.handler, auth_entity=self.auth_entity, actor={
        'objectType': 'person',
        'id': 'tag:instagram.com,2013:420973239',
        'username': '******',
        'displayName': 'Ryan Barrett',
        'url': 'https://snarfed.org/',
        'image': {'url': 'http://pic.ture/url'},
        # ...
      })

    self.bridgy_api_state = {
      # dash in this URL is regression test for
      # https://console.cloud.google.com/errors/8827591112854923168
      'callback': 'http://my.site/call-back',
      'feature': 'listen,publish',
      'operation': 'add',
      'user_url': 'http://snarfed.org',
    }
Ejemplo n.º 5
0
  def test_update_instagram_pictures(self):
    for username in 'a', 'b':
      profile = copy.deepcopy(test_instagram.HTML_PROFILE)
      profile['entry_data']['ProfilePage'][0]['user'].update({
        'username': username,
        'profile_pic_url': 'http://new/pic',
        })
      super(HandlerTest, self).expect_requests_get(
        gr_instagram.HTML_BASE_URL + '%s/' % username,
        test_instagram.HTML_HEADER + json.dumps(profile) + test_instagram.HTML_FOOTER,
        allow_redirects=False)
    self.mox.ReplayAll()

    sources = []
    auth_entity = indieauth.IndieAuth(id='http://foo.com/', user_json='{}')
    for username in 'a', 'b', 'c', 'd':
      source = Instagram.new(
        None, auth_entity=auth_entity, features=['listen'],
        actor={'username': username, 'image': {'url': 'http://old/pic'}})
      # test that we skip disabled and deleted sources
      if username == 'c':
        source.status = 'disabled'
      elif username == 'd':
        source.features = []
      sources.append(source.put())

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

    self.assertEquals('http://new/pic', sources[0].get().picture)
    self.assertEquals('http://new/pic', sources[1].get().picture)
    self.assertEquals('http://old/pic', sources[2].get().picture)
    self.assertEquals('http://old/pic', sources[3].get().picture)
Ejemplo n.º 6
0
 def setUp(self):
     super(InstagramTest, self).setUp()
     self.handler.messages = []
     self.auth_entity = indieauth.IndieAuth(
         id='http://foo.com',
         user_json=json.dumps({
             'rel-me': ['http://instagram.com/snarfed'],
         }))
     self.inst = instagram.Instagram.new(self.handler,
                                         auth_entity=self.auth_entity,
                                         actor={
                                             'username': '******',
                                             'displayName': 'Ryan Barrett',
                                             'image': {
                                                 'url':
                                                 'http://pic.ture/url'
                                             },
                                         })
Ejemplo n.º 7
0
 def setUp(self):
     super(IndieAuthTest, self).setUp()
     self.handler.messages = []
     self.auth_entity = indieauth.IndieAuth(id='http://snarfed.org')
Ejemplo n.º 8
0
 def setUp(self):
     super().setUp()
     self.auth_entity = indieauth.IndieAuth(id='http://snarfed.org')