def get_user(self, access_token): request_url = self._get_url() # This is a special case client, # because auth_token is not set yet (this is how we verify it) # So do not use the shared base client for this! response = requests.get(request_url, headers={"Authorization": "Bearer {}".format(access_token)}) # TODO: replace with self.get(...) try: user_dict = response.json() response.raise_for_status() except Exception: if response.status_code == 401: raise AuthenticationError( request_url, response, "Invalid Token.\nSee http://docs.polyaxon.com/faqs/authentication/ for help", 401) raise AuthenticationError( request_url, response, "Login failed.\nSee http://docs.polyaxon.com/faqs/authentication/ for help", response.status_code) return UserConfig.from_dict(user_dict)
def test_project_config(self): config_dict = { 'username': '******', 'uid': 'sdfsdf098sdf80s9dSDF800', 'email': '*****@*****.**' } config = UserConfig.from_dict(config_dict) assert config.to_dict() == config_dict
def test_get_user(self): user = UserConfig('user', '*****@*****.**').to_dict() httpretty.register_uri(httpretty.GET, AuthClient._build_url(self.client.base_url, AuthClient.ENDPOINT), body=json.dumps(user), content_type='application/json', status=200) user_result = self.client.get_user() assert user == user_result.to_dict()
def get_user(self, token=None): token = token or self.token request_url = self._get_http_url() response = self.get(request_url, headers={ "Authorization": "{} {}".format(self.authentication_type, token) }) try: user_dict = response.json() response.raise_for_status() except Exception: if response.status_code == 401: raise AuthenticationError( request_url, response, "Invalid Token.\nSee http://docs.polyaxon.com/faqs/authentication/ for help", 401) raise AuthenticationError( request_url, response, "Login failed.\nSee http://docs.polyaxon.com/faqs/authentication/ for help", response.status_code) return UserConfig.from_dict(user_dict)
def retrieve(self, request, *args, **kwargs): user = request.user return Response(UserConfig.obj_to_dict(user))
def test_user_config(self): config_dict = {'username': '******', 'email': '*****@*****.**'} config = UserConfig.from_dict(config_dict) assert config.to_dict() == config_dict