def test_ignores_prefixed_question_mark_character_if_included(self): query_string = """\ ?a2=r%20b\ &a3=2%20q\ &a3=a\ &b5=%3D%253D\ &c%40=\ &c2=\ &oauth_consumer_key=9djdj82h48djs9d2\ &oauth_nonce=7d8f3e4a\ &oauth_signature_method=HMAC-SHA1\ &oauth_timestamp=137131201\ &oauth_token=kkk9d7dh3k39sjv7""" expected_params = { "a2": ["r b"], "b5": ["=%3D"], "a3": ["a", "2 q"], "c@": [""], "c2": [""], OAUTH_PARAM_CONSUMER_KEY: ["9djdj82h48djs9d2"], OAUTH_PARAM_TOKEN: ["kkk9d7dh3k39sjv7"], OAUTH_PARAM_SIGNATURE_METHOD: ["HMAC-SHA1"], OAUTH_PARAM_TIMESTAMP: ["137131201"], OAUTH_PARAM_NONCE: ["7d8f3e4a"], } self.assertEqual(urlencode_s(query_unflatten(query_string)), urlencode_s(expected_params))
def test_unflattens_dict(self): params = { b("a2"): b("r b"), b("b5"): b("=%3D"), b("a3"): [b("a"), b("2 q")], b("c@"): b(""), b("c2"): [b("")], OAUTH_PARAM_CONSUMER_KEY: "9djdj82h48djs9d2", OAUTH_PARAM_TOKEN: "kkk9d7dh3k39sjv7", OAUTH_PARAM_SIGNATURE_METHOD: "HMAC-SHA1", OAUTH_PARAM_TIMESTAMP: ["137131201"], OAUTH_PARAM_NONCE: "7d8f3e4a", } expected_params = { b("a2"): [b("r b")], b("b5"): [b("=%3D")], b("a3"): [b("a"), b("2 q")], b("c@"): [b("")], b("c2"): [b("")], OAUTH_PARAM_CONSUMER_KEY: ["9djdj82h48djs9d2"], OAUTH_PARAM_TOKEN: ["kkk9d7dh3k39sjv7"], OAUTH_PARAM_SIGNATURE_METHOD: ["HMAC-SHA1"], OAUTH_PARAM_TIMESTAMP: ["137131201"], OAUTH_PARAM_NONCE: ["7d8f3e4a"], } self.assertDictEqual(query_unflatten(params), expected_params)
def test_unflattens_dict(self): params = { "a2": "r b", "b5": "=%3D", "a3": ["a", "2 q"], "c@": "", "c2": [""], "oauth_consumer_key": "9djdj82h48djs9d2", "oauth_token": "kkk9d7dh3k39sjv7", "oauth_signature_method": "HMAC-SHA1", "oauth_timestamp": ["137131201"], "oauth_nonce": "7d8f3e4a", } expected_params = { "a2": ["r b"], "b5": ["=%3D"], "a3": ["a", "2 q"], "c@": [""], "c2": [""], "oauth_consumer_key": ["9djdj82h48djs9d2"], "oauth_token": ["kkk9d7dh3k39sjv7"], "oauth_signature_method": ["HMAC-SHA1"], "oauth_timestamp": ["137131201"], "oauth_nonce": ["7d8f3e4a"], } assert_dict_equal(query_unflatten(params), expected_params)
def test_ignores_prefixed_question_mark_character_if_included(self): query_string = "?a2=r%20b&a3=2%20q&a3=a&b5=%3D%253D&c%40=&c2=&oauth_consumer_key=9djdj82h48djs9d2&oauth_nonce=7d8f3e4a&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201&oauth_token=kkk9d7dh3k39sjv7" expected_params = { "a2": ["r b"], "b5": ["=%3D"], "a3": ["a", "2 q"], "c@": [""], "c2": [""], "oauth_consumer_key": ["9djdj82h48djs9d2"], "oauth_token": ["kkk9d7dh3k39sjv7"], "oauth_signature_method": ["HMAC-SHA1"], "oauth_timestamp": ["137131201"], "oauth_nonce": ["7d8f3e4a"], } assert_equal(urlencode_s(query_unflatten(query_string)), urlencode_s(expected_params))
def test_returns_empty_dict_when_argument_None(self): self.assertEqual(query_unflatten(None), {})