13
13
import pytest
14
14
15
15
from botocore .args import PRIORITY_ORDERED_SUPPORTED_PROTOCOLS
16
- from botocore .loaders import Loader
17
16
from botocore .session import get_session
18
17
19
18
20
- def _get_services_models_by_protocols_trait ( has_protocol_trait ):
19
+ def _multi_protocol_test_cases ( ):
21
20
session = get_session ()
22
- service_list = Loader ().list_available_services ('service-2' )
23
- for service in service_list :
21
+ loader = session .get_component ('data_loader' )
22
+ services = loader .list_available_services ('service-2' )
23
+ multi_protocol_services = []
24
+ supported_protocols = []
25
+ for service in services :
24
26
service_model = session .get_service_model (service )
25
- if ('protocols' in service_model .metadata ) == has_protocol_trait :
26
- yield service_model
27
+ if 'protocols' in service_model .metadata :
28
+ multi_protocol_services .append (service )
29
+ supported_protocols .append (
30
+ service_model .metadata .get ('protocols' , [])
31
+ )
32
+ return list (zip (multi_protocol_services , supported_protocols ))
33
+
34
+
35
+ def _single_protocol_test_cases ():
36
+ session = get_session ()
37
+ loader = session .get_component ('data_loader' )
38
+ services = loader .list_available_services ('service-2' )
39
+ single_protocol_services = []
40
+ supported_protocol = []
41
+ for service in services :
42
+ service_model = session .get_service_model (service )
43
+ if 'protocols' not in service_model .metadata :
44
+ single_protocol_services .append (service )
45
+ supported_protocol .append (service_model .metadata .get ('protocol' ))
46
+ return list (zip (single_protocol_services , supported_protocol ))
27
47
28
48
29
49
@pytest .mark .validates_models
30
50
@pytest .mark .parametrize (
31
- "service " ,
32
- _get_services_models_by_protocols_trait ( True ),
51
+ "service_name, supported_protocols " ,
52
+ _multi_protocol_test_cases ( ),
33
53
)
34
- def test_services_with_protocols_trait_have_supported_protocol (service ):
35
- service_supported_protocols = service .metadata .get ('protocols' , [])
36
- message = f"No protocols supported for service { service .service_name } "
54
+ def test_services_with_protocols_trait_have_supported_protocol (
55
+ service_name , supported_protocols
56
+ ):
57
+ message = f"No protocols supported for service { service_name } "
37
58
assert any (
38
59
protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS
39
- for protocol in service_supported_protocols
60
+ for protocol in supported_protocols
40
61
), message
41
62
42
63
43
64
@pytest .mark .validates_models
44
65
@pytest .mark .parametrize (
45
- "service " ,
46
- _get_services_models_by_protocols_trait ( False ),
66
+ "service_name, supported_protocol " ,
67
+ _single_protocol_test_cases ( ),
47
68
)
48
- def test_services_without_protocols_trait_have_supported_protocol (service ):
49
- message = f"Service protocol not supported for { service .service_name } "
69
+ def test_services_without_protocols_trait_have_supported_protocol (
70
+ service_name , supported_protocol
71
+ ):
72
+ message = f"Service protocol not supported for { service_name } "
50
73
assert (
51
- service . metadata . get ( 'protocol' )
74
+ supported_protocol
52
75
in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS
53
- ), message
76
+ ), message
0 commit comments