Esempio n. 1
0
    def test_data_remains_gone_when_none_supplied(self):

        # Verify that when neither 'operation' nor 'data' are supplied, that
        # the resulting request has no 'data' key
        req1 = BllRequest(target=util.randomword(), action=util.randomword())

        self.assertFalse(req1.get('data'))
Esempio n. 2
0
    def _build_request(self,
                       request=None,
                       target=None,
                       auth_token=None,
                       operation=None,
                       action=None,
                       data=None,
                       region=None,
                       **kwargs):
        """
        Construct a request object using the following, in priority order (
        highest priority first):
        1. Function arguments (e.g. operation)
        2. Values in the ``request`` argument
        3. Values from the service making the request for fields that are
           commonly inherited (txn, region, auth_token)

        For example, if the auth_token is passed as a parameter, it will be
        used; otherwise, the auth_token will be taken from any request
        object passes as a parameter; otherwise it will be copied from the
        calling service.
        """
        txn_id = new_txn_id(self.txn_id)
        language = self.request.get(api.LANGUAGE)

        if not region:
            if request:
                region = request.get(api.REGION)

            region = region or self.region

        req = BllRequest(request=request,
                         target=target,
                         auth_token=auth_token,
                         operation=operation,
                         action=action,
                         data=data,
                         txn_id=txn_id,
                         region=region,
                         language=language,
                         **kwargs)

        if not req.get(api.AUTH_TOKEN) and getattr(self, 'token_helper', None):
            req[api.AUTH_TOKEN] = self.token_helper.get_user_token()

        return req