コード例 #1
0
    def test_comment_on_photo(self):
        annoying_test = not self.test_settings['ignore_annoying_tests']
        if self.test_settings['oauth'] and annoying_test:
            old_photo = Photo(10)
            comment_body = """sweet photo Ev! Sorry if this gets posted a 
bunch of times, I'm testing out the api and there is no delete method in the api"""
            self.auth_zach.comment_on_photo(old_photo, comment_body)
コード例 #2
0
def main(narrations_on=True):
    """Fancy automagical api requests when needed 
    are completed by using the built in fhp.models.
   
    These fhp.models.do several things for you, like:
    1. Caching responses for you, so you don't need
       to waste time doing that yourself.
    2. Lazily doing requests so that the experience 
       feels faster
    
    We start by making a photo:
    """
    narrate.on = narrations_on
    narrate("We start by pulling down the photo")
    try:
        owly_photo = Photo(3256058)
        narrate("Looks like that went smoothly")
    except:
        narrate("Looks like a problem happened, are your auth creds set up?")

    narrate("Now, lets check out that photo photo url:")
    print owly_photo.image_url

    narrate("Here is a look at the full object:")
    pprint(owly_photo.__dict__)

    narrate("We don't *see* the user, but we know it is there")
    print 'user' in dir(owly_photo)

    narrate("So let's try to grab that user")
    print owly_photo.user

    narrate("Cool ain't it? Wondering who took this fine photo?")
    print owly_photo.user.username
コード例 #3
0
ファイル: test_photo.py プロジェクト: 500px/PxMagic
    def test_photos_user_cache(self):
        owly_photo = Photo(3256058)
        same_owly_photo = Photo(3256058)
        self.assertEqual(owly_photo.__hash__(), same_owly_photo.__hash__())

        different_users_owly_photo = Photo(1763176)
        self.assertNotEqual(owly_photo.__hash__(), different_users_owly_photo.__hash__())
        self.assertNotEqual(owly_photo.image_url, different_users_owly_photo.image_url)
        
        self.assertEqual(owly_photo.user.__hash__(),
                         same_owly_photo.user.__hash__())
        self.assertNotEqual(owly_photo.user.__hash__(),
                            different_users_owly_photo.user.__hash__())
        
        same_users_different_owly_photo = Photo(3255978)
        self.assertNotEqual(owly_photo.__hash__(), same_users_different_owly_photo.__hash__())
        self.assertEqual(owly_photo.user.__hash__(),
                         same_users_different_owly_photo.user.__hash__())
コード例 #4
0
 def test_user_likes(self):
     """ Since there is no way to unlike something with the 
     500px app / API, we are only left with the option to 
     have an annoying test where we find something to actually like.
     """
     annoying_test = not self.test_settings['ignore_annoying_tests']
     if self.test_settings['oauth'] and annoying_test:
         photo = Photo(13473159)
         self.assertTrue(self.auth_zach.like(photo))
コード例 #5
0
 def test_user_favorite(self):
     """ Normally I would split these into their own tests, but 
     they need to proceed sequentially or I may get an error due
     to trying to "unfavorite" a photo I've already unfavorited.
     """
     if self.test_settings['oauth']:
         photo_id = 10005987
         self.assertTrue(self.auth_zach.favorite(photo_id))
         self.assertTrue(self.auth_zach.unfavorite(photo_id))
         photo = Photo(photo_id)
         self.assertTrue(self.auth_zach.favorite(photo))
         self.assertTrue(self.auth_zach.unfavorite(photo))
コード例 #6
0
ファイル: photo_id_list.py プロジェクト: zachaysan/qtsnap
import subprocess
import os
from fhp.models.photo import Photo

i = 0

with open("ids") as id_file:
    for line in id_file.readlines():
        i += 1
        try:
            photo_id = int(line.rstrip())
        except:
            print "skipping line:"
            continue
        if i % 10000 == 0:
            print photo_id
            print i
        if os.path.isfile("photos/%s.jpg" % photo_id):
            continue
        try:
            photo = Photo(photo_id)
        except Exception, e:
            print "skipping photo %s" % photo_id
            print e
            continue
        url = photo.image_url_size(100)
        process_call = "wget --output-document=photos/%s.jpg %s" % (photo.id, url)
        subprocess.call(process_call, shell=True)
コード例 #7
0
 def test_photo_has_tags(self):
     marching_owl = Photo(897276)
     self.assertTrue(marching_owl.tags)
     self.assertIn('marching', marching_owl.tags)
     self.assertIn('owl', marching_owl.tags)
コード例 #8
0
 def setUp(self):
     self.owly_photo = Photo(3256058)
     self.test_settings = test_settings
コード例 #9
0
    def test_photos_user_cache(self):
        owly_photo = Photo(3256058)
        same_owly_photo = Photo(3256058)
        self.assertEqual(owly_photo.__hash__(), same_owly_photo.__hash__())

        different_users_owly_photo = Photo(1763176)
        self.assertNotEqual(owly_photo.__hash__(),
                            different_users_owly_photo.__hash__())
        self.assertNotEqual(owly_photo.image_url,
                            different_users_owly_photo.image_url)

        self.assertEqual(owly_photo.user.__hash__(),
                         same_owly_photo.user.__hash__())
        self.assertNotEqual(owly_photo.user.__hash__(),
                            different_users_owly_photo.user.__hash__())

        same_users_different_owly_photo = Photo(3255978)
        self.assertNotEqual(owly_photo.__hash__(),
                            same_users_different_owly_photo.__hash__())
        self.assertEqual(owly_photo.user.__hash__(),
                         same_users_different_owly_photo.user.__hash__())