Example #1
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)
Example #2
0
  def test_update_instagram_pictures(self):
    for username in 'a', 'b':
      self.expect_urlopen(
        'https://api.instagram.com/v1/users/self?access_token=token',
        json.dumps({'data': {'id': username,
                             'username': username,
                             'full_name': 'Ryan Barrett',
                             'profile_picture': 'http://new/pic',
                           }}))
    self.mox.ReplayAll()

    sources = []
    for username in 'a', 'b', 'c', 'd':
      auth_entity = oauth_instagram.InstagramAuth(
        id=username, auth_code='code', access_token_str='token',
        user_json=json.dumps({'username': username,
                              'full_name': 'Ryan Barrett',
                              'profile_picture': 'http://old/pic',
                            }))
      auth_entity.put()
      source = Instagram.new(None, auth_entity=auth_entity, features=['listen'])
      # 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)
Example #3
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)
Example #4
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)
Example #5
0
 def test_get_activities_response(self):
   """Check that min_id is discarded."""
   inst = Instagram.new(self.handler, auth_entity=self.auth_entity)
   self.mox.StubOutWithMock(inst.as_source.api, 'user_recent_media')
   inst.as_source.api.user_recent_media('self').AndReturn(([], {}))
   self.mox.ReplayAll()
   assert inst.get_activities_response(min_id='123')
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
0
 def test_get_activities_response(self):
   """Check that min_id is discarded."""
   inst = Instagram.new(self.handler, auth_entity=self.auth_entity)
   self.expect_urlopen(
     'https://api.instagram.com/v1/users/self/media/recent?access_token=my_token',
     '{"data":[]}')
   self.mox.ReplayAll()
   assert inst.get_activities_response(min_id='123')
Example #10
0
 def test_new(self):
   inst = Instagram.new(self.handler, auth_entity=self.auth_entity)
   self.assertEqual(self.auth_entity, inst.auth_entity.get())
   self.assertEqual('my_token', inst.as_source.access_token)
   self.assertEqual('snarfed', inst.key.string_id())
   self.assertEqual('http://pic.ture/url', inst.picture)
   self.assertEqual('http://instagram.com/snarfed', inst.url)
   self.assertEqual('http://instagram.com/snarfed', inst.silo_url())
   self.assertEqual('Ryan Barrett', inst.name)
Example #11
0
  def test_canonicalize_syndication_url(self):
    inst = Instagram.new(self.handler, auth_entity=self.auth_entity)

    for url in (
        'http://www.instagram.com/p/abcd',
        'https://www.instagram.com/p/abcd',
        'https://instagram.com/p/abcd',
    ):
      self.assertEqual(
        'http://instagram.com/p/abcd',
        inst.canonicalize_syndication_url(url))
Example #12
0
  def test_get_activities_response_no_activity_id(self):
    Activity(id='tag:instagram.com,2013:123', source=self.source.key,
             activity_json=json_dumps({'foo': 'bar'})).put()
    Activity(id='tag:instagram.com,2013:456', source=self.source.key,
             activity_json=json_dumps({'baz': 'biff'})).put()

    other = Instagram.new(actor={'username': '******'}).put()
    Activity(id='tag:instagram.com,2013:789', source=other,
             activity_json=json_dumps({'boo': 'bah'})).put()

    resp = self.source.get_activities_response()
    self.assert_equals([{'foo': 'bar'}, {'baz': 'biff'}], resp['items'])
Example #13
0
  def test_update_instagram_picture_profile_404s(self):
    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 = cron.application.get_response('/cron/update_instagram_pictures')
    self.assertEqual(200, resp.status_int)
    self.assertEquals('http://old/pic', source.key.get().picture)
Example #14
0
    def setUp(self):
        super(InstagramTest, self).setUp()
        self.handler.messages = []
        self.inst = Instagram.new(
            self.handler,
            actor={
                'objectType': 'person',
                'id': 'tag:instagram.com,2013:420973239',
                'username': '******',
                'displayName': 'Ryan Barrett',
                'url': 'https://snarfed.org/',
                'image': {
                    'url': 'http://pic.ture/url'
                },
                # ...
            })

        self.domain = Domain(id='snarfed.org', tokens=['towkin']).put()
Example #15
0
    def test_update_instagram_pictures(self):
        for username in "a", "b":
            self.expect_urlopen(
                "https://api.instagram.com/v1/users/self?access_token=token",
                json.dumps(
                    {
                        "data": {
                            "id": username,
                            "username": username,
                            "full_name": "Ryan Barrett",
                            "profile_picture": "http://new/pic",
                        }
                    }
                ),
            )
        self.mox.ReplayAll()

        sources = []
        for username in "a", "b", "c", "d":
            auth_entity = oauth_instagram.InstagramAuth(
                id=username,
                auth_code="code",
                access_token_str="token",
                user_json=json.dumps(
                    {"username": username, "full_name": "Ryan Barrett", "profile_picture": "http://old/pic"}
                ),
            )
            auth_entity.put()
            source = Instagram.new(None, auth_entity=auth_entity, features=["listen"])
            # 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)
Example #16
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)
Example #17
0
 def setUp(self):
     super(InstagramTest, self).setUp()
     self.source = Instagram.new(self.handler, actor=self.actor)
     self.domain = Domain(id='snarfed.org', tokens=['towkin']).put()
     self.auth = f'token=towkin&key={self.source.key.urlsafe().decode()}'