示例#1
0
class TestApi(unittest.TestCase):
    def setUp(self):
        self.smugmug = SmugMug(api_key=API_KEY, api_version='1.2.2', app_name='TestApp')

    def test_ping(self):
        rsp = self.smugmug.service_ping()
        self.assertEqual(rsp['stat'], 'ok')

    def test_dynamic_method(self):
        self.smugmug.login_anonymously()
        rsp = self.smugmug.albums_get(NickName='test')
        self.assertEqual(rsp['method'], 'smugmug.albums.get')
        self.smugmug.reset_auth()

    def test_authorize(self):
        expected = 'http://api.smugmug.com/services/oauth/authorize.mg?oauth_token=ABC&Access=Public&Permissions=Read'
        self.smugmug.set_oauth_token('ABC','123')
        url = self.smugmug.authorize(access='Public', perm='Read')
        self.assertEqual(url, expected)
        self.smugmug.reset_auth()

    def test_failed_api(self):
        if sys.version_info < (2, 7):
            self.assertRaises(SmugMugException, lambda: self.smugmug.bad_apimethod())
        else:
            with self.assertRaises(SmugMugException):
                self.smugmug.bad_apimethod()
示例#2
0
class TestApi(unittest.TestCase):
    def setUp(self):
        self.smugmug = SmugMug(api_key=API_KEY,
                               api_version='1.2.2',
                               app_name='TestApp')

    def test_ping(self):
        rsp = self.smugmug.service_ping()
        self.assertEqual(rsp['stat'], 'ok')

    def test_dynamic_method(self):
        self.smugmug.login_anonymously()
        rsp = self.smugmug.albums_get(NickName='test')
        self.assertEqual(rsp['method'], 'smugmug.albums.get')
        self.smugmug.reset_auth()

    def test_authorize(self):
        expected = 'http://api.smugmug.com/services/oauth/authorize.mg?oauth_token=ABC&Access=Public&Permissions=Read'
        self.smugmug.set_oauth_token('ABC', '123')
        url = self.smugmug.authorize(access='Public', perm='Read')
        self.assertEqual(url, expected)
        self.smugmug.reset_auth()

    def test_failed_api(self):
        if sys.version_info < (2, 7):
            self.assertRaises(SmugMugException,
                              lambda: self.smugmug.bad_apimethod())
        else:
            with self.assertRaises(SmugMugException):
                self.smugmug.bad_apimethod()
示例#3
0
class TestApiImageUploadOauth(unittest.TestCase):
    def setUp(self):
        self.smugmug = SmugMug(api_key=API_KEY, api_version='1.3.0', app_name='TestApp', oauth_secret=OAUTH_SECRET)

    def test_image_upload_oauth(self):
        self.smugmug.set_oauth_token('ABC','123')
        rsp = self.smugmug.images_upload(File='tests/smuggy.jpg', AlbumID=1234)
        self.assertEqual(rsp['method'], 'smugmug.images.upload')
        self.smugmug.reset_auth()
示例#4
0
def smug_init():

    smugmug = SmugMug(api_key=settings['smugmug']['api_key'],\
     oauth_secret=settings['smugmug']['oauth_secret'],\
     app_name=settings['smugmug']['app'])

    oauth_token_id = settings['smugmug']['oauth_token_id']
    oauth_token_secret = settings['smugmug']['oauth_token_secret']
    smugmug.set_oauth_token(oauth_token_id, oauth_token_secret)

    return smugmug
示例#5
0
class TestApiImageUploadOauth(unittest.TestCase):
    def setUp(self):
        self.smugmug = SmugMug(api_key=API_KEY,
                               api_version='1.3.0',
                               app_name='TestApp',
                               oauth_secret=OAUTH_SECRET)

    def test_image_upload_oauth(self):
        self.smugmug.set_oauth_token('ABC', '123')
        rsp = self.smugmug.images_upload(File='tests/smuggy.jpg', AlbumID=1234)
        self.assertEqual(rsp['method'], 'smugmug.images.upload')
        self.smugmug.reset_auth()
示例#6
0
def smug_auth():
    smugmug = SmugMug(api_key=config.get('smugmug', 'key'), oauth_secret=config.get('smugmug', 'secret'), api_version="1.3.0", app_name="flickr-to-smugmug")
    if config.has_option('smugmug', 'oauth_token'):
        smugmug.set_oauth_token(config.get('smugmug', 'oauth_token'), config.get('smugmug', 'oauth_token_secret'))
    else:
        smugmug.auth_getRequestToken()
        get_input("Authorize app at %s\n\nPress Enter when complete.\n" % (smugmug.authorize(access='Full', perm='Modify')))
        smugmug.auth_getAccessToken()
        config.set('smugmug', 'oauth_token', smugmug.oauth_token)
        config.set('smugmug', 'oauth_token_secret', smugmug.oauth_token_secret)
        save()
    return smugmug
示例#7
0
def smug_init():

    smugmug = SmugMug(api_key=settings['smugmug']['api_key'],\
     oauth_secret=settings['smugmug']['oauth_secret'],\
     app_name=settings['smugmug']['app'])

    #oauth handshake
    #smugmug.auth_getRequestToken()
    #raw_input("Authorize app at %s\n" % (smugmug.authorize(access="Full")))
    #result = smugmug.auth_getAccessToken()

    oauth_token_id = settings['smugmug']['oauth_token_id']
    oauth_token_secret = settings['smugmug']['oauth_token_secret']
    smugmug.set_oauth_token(oauth_token_id, oauth_token_secret)

    return smugmug
# parse config file
config = configparser.ConfigParser()
config.read(SCRIPTPATH+'/smugmuglinkgen.conf')
API_KEY = config.get('main', 'api_key')
API_SECRET = config.get('main', 'api_secret')
TOKEN = config.get('main', 'token')
SECRET = config.get('main', 'secret')
USERNAME = config.get('main', 'smugmug_user')

# set up smugmug API
smugmug = SmugMug(api_key=API_KEY, oauth_secret=API_SECRET, app_name="get_gallery_links")

# oauth
if TOKEN and SECRET:
    smugmug.set_oauth_token(TOKEN, SECRET)
    response = smugmug.auth_checkAccessToken()
    #print response
else:
    smugmug.auth_getRequestToken()
    raw_input("Authorize app at %s\n\nPress Enter when complete.\n" % (smugmug.authorize(access='Full')))
    response = smugmug.auth_getAccessToken()
    print("  token: %s" % response['Auth']['Token']['id'])
    print("  secret: %s" % response['Auth']['Token']['Secret'])
    print("Enter these values into smugmuglinkgen.conf to skip this auth process the next time around.")

# the real work starts here
albums = smugmug.albums_get(NickName=USERNAME)
for album in albums['Albums']:
    if arguments['list']:
        print(album['Title'])