Ejemplo n.º 1
0
    def test_calculate_signatures(self):
        """Calculate and compare signatures. Including the tricky situations
        """

        self.assertEqual(
            calculate_oauth_signature(
                'http://data.hyves.nl/',
                'uri',
                {
                    'test':'value'
                },
                'consumer_secret',
                'token_secret'
            ),
            'AD7pfDU3JJNsaXZW4uGccTt0Mj8='
        )

        self.assertEqual(
            calculate_oauth_signature(
                'POST',
                'TEST',
                {
                    'a':'b test'
                },
                'oauth_consumer_secret',
                'oauth_token_secret'),
            'HPcbjA9VIzxoQDRYGnOVWGpyMec='
        )

        self.assertEqual(
            calculate_oauth_signature(
                'POST',
                'TEST',
                {
                    'a':'b+&test'
                },
                'oauth_consumer_secret',
                'oauth_token_secret'
            ),
            '3pKzqGPLUmQ4jF5QuirKSQFyVtU='
        )
Ejemplo n.º 2
0
    def do_method(self,
                  ha_method,
                  params,
                  token = None,
                  http_type = HTTP_TYPE_POST):
        """Makes the hyves API call, raises exceptions over bad HTTP status
        codes and Hyves errors
        """

        default_params = {
            'oauth_consumer_key': self.consumer.key,
            'oauth_timestamp': self.get_oauth_timestamp(),
            'oauth_nonce': self.get_oauth_nonce(),
            'oauth_signature_method': GenusApi.DEFAULT_OAUTH_SIGNATURE_METHOD,
            'ha_method': ha_method,
            'ha_format': GenusApi.DEFAULT_HA_FORMAT,
            'ha_fancylayout': GenusApi.DEFAULT_HA_FANCYLAYOUT,
            'ha_version': self.ha_version,
        }

        oauth_consumer_secret = self.consumer.secret
        oauth_token_secret = ''

        if token:
            default_params['oauth_token'] = token.key
            oauth_token_secret = token.secret

        params.update(default_params)
        params['oauth_signature'] = utils.calculate_oauth_signature(
            http_type,
            GenusApi.API_URL,
            params,
            oauth_consumer_secret,
            oauth_token_secret)

        params = oauth_util.normalize_key_value_parameters(params)

        try:
            response = utils.do_http_call(
                GenusApi.API_URL,
                params,
                http_type == GenusApi.HTTP_TYPE_POST
            )

        except IOError, exception:
            self.logger.exception(exception)