Exemplo n.º 1
0
 def test_common_request_get_signed_header(self, mock_get_rfc_2616_date):
     r = CommonRequest()
     r.set_version("version")
     r.set_uri_pattern('/users/[userid]')
     r.set_path_params({"userid": "jacksontian"})
     r.set_product('product')
     r.trans_to_acs_request()
     self.assertEqual(r.get_url("regionid", "accesskeyid", "secret"),
                      "/users/jacksontian")
     self.assertEqual(r.get_style(), "ROA")
     mock_get_rfc_2616_date.return_value = "2018-12-04T03:25:29Z"
     headers = r.get_signed_header("regionid", "accesskeyid", "secret")
     mock_get_rfc_2616_date.assert_called_once_with()
     self.assertDictEqual(
         headers, {
             'Accept': 'application/octet-stream',
             'Authorization':
             'acs accesskeyid:Lq1u0OzLW/uqLQswxwhne97Umlw=',
             'Date': '2018-12-04T03:25:29Z',
             'x-acs-region-id': 'regionid',
             'x-acs-signature-method': 'HMAC-SHA1',
             'x-acs-signature-version': '1.0',
             'x-acs-version': 'version',
             'x-sdk-invoke-type': 'common'
         })
Exemplo n.º 2
0
 def test_common_request_get_url(self):
     r = CommonRequest()
     r.set_version("version")
     r.set_uri_pattern('/users/[userid]')
     r.set_path_params({"userid": "jacksontian"})
     r.set_product('product')
     r.trans_to_acs_request()
     self.assertEqual(r.get_style(), "ROA")
     url = r.get_url("regionid", "accesskeyid", "secret")
     self.assertEqual(url, "/users/jacksontian")
Exemplo n.º 3
0
    def test_common_request(self):
        r = CommonRequest()
        # accept format
        self.assertIsNone(r.get_accept_format())
        r.set_accept_format('json')
        self.assertEqual(r.get_accept_format(), "json")
        # action name
        self.assertEqual(r.get_action_name(), None)
        r.set_action_name('new action name')
        self.assertEqual(r.get_action_name(), "new action name")
        # body params
        self.assertDictEqual(r.get_body_params(), {})
        r.set_body_params({'key': 'value'})
        self.assertDictEqual(r.get_body_params(), {'key': 'value'})
        r.add_body_params("key2", "value2")
        self.assertDictEqual(r.get_body_params(), {
            'key': 'value',
            'key2': 'value2'
        })
        # content
        self.assertIsNone(r.get_content())
        r.set_content("content")
        self.assertEqual(r.get_content(), "content")
        # headers
        self.assertDictEqual(r.get_headers(), {'x-sdk-invoke-type': 'common'})
        r.set_headers({})
        self.assertDictEqual(r.get_headers(), {})
        r.add_header("key", "value")
        self.assertDictEqual(r.get_headers(), {"key": "value"})
        # location endpoint type
        self.assertEqual(r.get_location_endpoint_type(), 'openAPI')
        # no set_location_endpoint_type ??
        # location_service_code
        self.assertEqual(r.get_location_service_code(), None)
        r.set_location_service_code('new service code')
        self.assertEqual(r.get_location_service_code(), 'new service code')
        # method
        self.assertEqual(r.get_method(), 'GET')
        r.set_method('POST')
        self.assertEqual(r.get_method(), 'POST')
        # product
        self.assertEqual(r.get_product(), None)
        r.set_product('new-product')
        self.assertEqual(r.get_product(), 'new-product')
        # protocol_type
        self.assertEqual(r.get_protocol_type(), "http")
        r.set_protocol_type('https')
        self.assertEqual(r.get_protocol_type(), "https")
        # query params
        self.assertDictEqual(r.get_query_params(), {})
        r.set_query_params({'key': 'value'})
        self.assertDictEqual(r.get_query_params(), {'key': 'value'})
        r.add_query_param("key2", "value2")
        self.assertDictEqual(r.get_query_params(), {
            'key': 'value',
            "key2": "value2"
        })

        # uri params
        self.assertEqual(r.get_uri_params(), None)
        r.set_uri_params({'user': "******"})
        self.assertDictEqual(r.get_uri_params(), {'user': '******'})
        # uri pattern
        self.assertEqual(r.get_uri_pattern(), None)
        r.set_uri_pattern('/users/:userid')
        self.assertEqual(r.get_uri_pattern(), '/users/:userid')
        # url
        # version
        self.assertEqual(r.get_version(), None)
        r.set_version('2014-10-18')
        self.assertEqual(r.get_version(), "2014-10-18")
        # user-agent
        self.assertEqual(r.get_headers().get('User-Agent'), None)
        r.set_user_agent("user-agent")
        self.assertEqual(r.get_headers().get('User-Agent'), "user-agent")
        # content-type
        self.assertEqual(r.get_headers().get('Content-Type'), None)
        r.set_content_type("application/json")
        self.assertEqual(r.get_headers().get('Content-Type'),
                         "application/json")
        # domain
        self.assertEqual(r.get_domain(), None)
        r.set_domain("new-domain")
        self.assertEqual(r.get_domain(), "new-domain")

        # path_params
        self.assertEqual(r.get_path_params(), None)
        r.add_path_param("userid", "jacksontian")
        r.add_path_param("repo", "snow")
        self.assertEqual(r.get_path_params(), {
            "userid": "jacksontian",
            "repo": "snow"
        })
        r.set_path_params({"userid": "linatian"})
        self.assertEqual(r.get_path_params(), {"userid": "linatian"})