Exemplo n.º 1
0
 def test_login_authenticate(self, pv_mocks, pv_response):
     request_mock = pv_mocks.REQUEST
     request_mock.return_value = pv_response.SUCCESS.AUTH
     api = PicovicoAPI("app_id", "device_id")
     assert not api.is_authorized()
     api.login("username", "password")
     assert api.is_authorized()
     api = PicovicoAPI("app_id", "device_id")
     assert not api.is_authorized()
     api.authenticate("app_secret")
     assert api.is_authorized()
Exemplo n.º 2
0
 def test_api_proxy(self):
     api = PicovicoAPI("app_id", "device_id")
     assert api.app_id
     assert api.headers is None
     api.set_access_tokens("access_key", "access_token")
     assert api.headers
     assert api.is_authorized()
     api.logout()
     assert not api.is_authorized()
Exemplo n.º 3
0
def prepare_api_object(profile_name, session=False):
    profile_name = profile_name or profile_utils.DEFAULT_PROFILE_NAME
    profile = profile_utils.get_profile(profile_name, info=True)
    api = PicovicoAPI(profile.APP_ID, profile.DEVICE_ID)
    if session:
        sess = profile_utils.get_session_info()
        if sess and sess.PROFILE == profile.NAME:
            api.set_access_tokens(sess.ACCESS_KEY, sess.ACCESS_TOKEN)
            api._ready_component_property()
        else:
            auth_names = profile_utils.get_auth_names(profile.NAME)
            if not auth_names:
                prompt.show_no_session(profile.NAME)
            action = {
                profile_utils.LOGIN_INFO: 'login',
                profile_utils.AUTHENTICATE_INFO: 'authenticate',
            }.get(auth_names, None)
            if not all(getattr(profile, k, None) for k in auth_names):
                prompt.show_no_session(profile.NAME)
            else:
                arguments = {k.lower(): getattr(profile, k) for k in auth_names}
                api = auth_action(action, profile.NAME, **arguments)
    return api
Exemplo n.º 4
0
 def test_auth_decoration(self, pv_mocks, pv_response, pv_act_request_args, pv_urls):
     request_mock = pv_mocks.REQUEST
     calls = ("app_id", "device_id", "username", "password")
     api = PicovicoAPI(*calls[:2])
     post_call = pv_act_request_args.POST.copy()
     with pytest.raises(pv_exceptions.PicovicoAPINotAllowed):
         api.me()
     request_mock.return_value = pv_response.SUCCESS.AUTH
     api.login(*calls[2:])
     post_call.update(data=dict(zip(calls, calls)), url=pv_urls.PICOVICO_LOGIN)
     request_mock.assert_called_with(**post_call)
     api.me()
     me_call = pv_act_request_args.GET_AUTH.copy()
     me_call.update(url=pv_urls.ME)
     request_mock.assert_called_with(**me_call)
Exemplo n.º 5
0
from picovico import PicovicoAPI

#Create a config files to import settings

PICOVICO_DEVICE_ID = 'SOME-DEVICE-ID'
PICOVICO_APP_ID = 'YOUR-APPLICATION-ID'
PICOVICO_APP_SECRET = None
#'YOUR-APP-SECRET'

#initiate api
api = PicovicoAPI(PICOVICO_APP_ID, PICOVICO_DEVICE_ID, PICOVICO_APP_SECRET)
#api = PicovicoAPI(PICOVICO_APP_ID, PICOVICO_DEVICE_ID)

#to get picovico system components
free_styles = api.free_styles()
free_musics = api.free_musics()

#To authenticate
api.authenticate('YOUR-APP-SECRET')
#if secret is initiated in api just call api.authenticate()

#To login with username and password
api.login('YOUR-USERNAME', 'YOUR-PASSWORD')

#Either login or authenticate is needed for actions described below:
my_music_component = api.music_component
my_style_component = api.style_component
my_photo_component = api.photo_component
my_video_component = api.video_component

#View profile