MCPcopy
hub / github.com/redis/redis-py / test_resolve

Method test_resolve

tests/test_command_policies.py:22–87  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

20@pytest.mark.fixed_client
21class TestBasePolicyResolver:
22 def test_resolve(self):
23 mock_command_parser = Mock(spec=CommandsParser)
24 zcount_policy = CommandPolicies(
25 request_policy=RequestPolicy.DEFAULT_KEYED,
26 response_policy=ResponsePolicy.DEFAULT_KEYED,
27 )
28 rpoplpush_policy = CommandPolicies(
29 request_policy=RequestPolicy.DEFAULT_KEYED,
30 response_policy=ResponsePolicy.DEFAULT_KEYED,
31 )
32
33 mock_command_parser.get_command_policies.return_value = {
34 "core": {
35 "zcount": zcount_policy,
36 "rpoplpush": rpoplpush_policy,
37 }
38 }
39
40 dynamic_resolver = DynamicPolicyResolver(mock_command_parser)
41 assert dynamic_resolver.resolve("zcount") == zcount_policy
42 assert dynamic_resolver.resolve("rpoplpush") == rpoplpush_policy
43
44 with pytest.raises(
45 ValueError, match="Wrong command or module name: foo.bar.baz"
46 ):
47 dynamic_resolver.resolve("foo.bar.baz")
48
49 assert dynamic_resolver.resolve("foo.bar") is None
50 assert dynamic_resolver.resolve("core.foo") is None
51
52 # Test that policy fallback correctly
53 static_resolver = StaticPolicyResolver()
54 with_fallback_dynamic_resolver = dynamic_resolver.with_fallback(static_resolver)
55
56 assert (
57 with_fallback_dynamic_resolver.resolve("ft.aggregate").request_policy
58 == RequestPolicy.DEFAULT_KEYLESS
59 )
60 assert (
61 with_fallback_dynamic_resolver.resolve("ft.aggregate").response_policy
62 == ResponsePolicy.DEFAULT_KEYLESS
63 )
64
65 # Extended chain with one more resolver
66 mock_command_parser = Mock(spec=CommandsParser)
67 foo_bar_policy = CommandPolicies(
68 request_policy=RequestPolicy.DEFAULT_KEYLESS,
69 response_policy=ResponsePolicy.DEFAULT_KEYLESS,
70 )
71
72 mock_command_parser.get_command_policies.return_value = {
73 "foo": {
74 "bar": foo_bar_policy,
75 }
76 }
77 another_dynamic_resolver = DynamicPolicyResolver(mock_command_parser)
78 with_fallback_static_resolver = static_resolver.with_fallback(
79 another_dynamic_resolver

Callers

nothing calls this directly

Calls 6

with_fallbackMethod · 0.95
with_fallbackMethod · 0.95
CommandPoliciesClass · 0.90
resolveMethod · 0.45

Tested by

no test coverage detected