def _new(self, e: Entity, access_token: str) -> Entity: uri = API_URL + mappers.collection_uri(e) include = [r for r in mappers.relationships(e) if getattr(e, r)] params = Parameter(include=include) auth = TokenAuth(access_token) return self._post(uri, e.dumps(), auth, params=params.dump())
class TestShowUsers(object): users_uri = mappers.collection_uri(User()) test_data = utils.load_test_data('show_users.json') def test_no_users(self, client): with requests_mock.Mocker() as mock: mock.get(self.users_uri, json={'data': []}) response = client.get(url_for('userinfo.show_users')) assert response.status_code == 200
def test_authorize_callback(client, mocker, auth_resp, user_data, next_url): users_uri = mappers.collection_uri(User()) user = UserSchema(many=True).dump(user_data).data mocker.patch('benwaonline.auth.views.verify_token', return_value=auth_payload()) mocker.patch('benwaonline.auth.views.handle_authorize_response', return_value=auth_resp) with requests_mock.Mocker() as mock: mock.get(users_uri, json=user) response = authenticate(client, mocker) assert response.status_code == 302 assert next_url in response.headers['location']
def get(self, **kwargs) -> List[Entity]: ''' Builds and executes a GET request for the collection of a resource Args: obj: is the Entity of the resource desired page_size: (optional) the number of results returned, 0 is all of the resources **kwargs: Arbitrary keyword arguments. Returns: a list of Entity. ''' uri = API_URL + mappers.collection_uri(self.entity()) params = Parameter(**kwargs) r = self._get(uri, params.dump()) e = assemblers.from_response(self.entity.type_, r.json(), many=True, include=params.include) return e
def _filter(self, e: Entity, **kwargs) -> Entity: uri = API_URL + mappers.collection_uri(e) q = EntityQuery(e) params = Parameter(filters=q.to_filter(), **kwargs) return self._get(uri, params.dump())