-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontextargs_test.py
100 lines (79 loc) · 3.29 KB
/
contextargs_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""contextargs.py unit tests."""
from pypyr.context import Context
from pypyr.errors import KeyInContextHasNoValueError, KeyNotInContextError
import pypyraws.contextargs as contextargs
import pytest
# ---------------------------- get_awsclient_args-----------------------------#
def test_get_awsclient_args_pass():
"""get_awsclient_args pass."""
context = Context({
'k1': 'v1',
'awsClientIn': {
'serviceName': 'service name',
'methodName': 'method_name',
'arbKey': 'arb_value'
}})
(service_name,
method_name,
client_args,
method_args) = contextargs.get_awsclient_args(context['awsClientIn'],
'pypyraws.steps.client')
assert service_name == 'service name'
assert method_name == 'method_name'
assert client_args is None
assert method_args is None
def test_get_awsclient_args_missing_servicename():
"""Missing serviceName raises."""
context = Context({
'k1': 'v1',
'awsClientIn': {
'methodName': 'method_name',
'arbKey': 'arb_value'
}})
with pytest.raises(KeyNotInContextError) as err_info:
contextargs.get_awsclient_args(context['awsClientIn'],
'pypyraws.steps.client')
assert str(err_info.value) == ("awsClientIn missing required key for "
"pypyraws.steps.client: 'serviceName'")
def test_get_awsclient_args_missing_methodname():
"""Missing methodName raises."""
context = Context({
'k1': 'v1',
'awsClientIn': {
'serviceName': 'service name',
'arbKey': 'arb_value'
}})
with pytest.raises(KeyNotInContextError) as err_info:
contextargs.get_awsclient_args(context['awsClientIn'],
'pypyraws.steps.client')
assert str(err_info.value) == ("awsClientIn missing required key for "
"pypyraws.steps.client: 'methodName'")
def test_get_awsclient_args_servicename_empty():
"""Empty serviceName raises."""
context = Context({
'k1': 'v1',
'awsClientIn': {
'serviceName': '',
'methodName': 'method_name',
'arbKey': 'arb_value'
}})
with pytest.raises(KeyInContextHasNoValueError) as err_info:
contextargs.get_awsclient_args(context['awsClientIn'],
'pypyraws.steps.client')
assert str(err_info.value) == ("serviceName required in awsClientIn "
"for pypyraws.steps.client")
def test_get_awsclient_args_methodname_empty():
"""Whitespace serviceName raises."""
context = Context({
'k1': 'v1',
'awsClientIn': {
'serviceName': 'service name',
'methodName': ' ',
'arbKey': 'arb_value'
}})
with pytest.raises(KeyInContextHasNoValueError) as err_info:
contextargs.get_awsclient_args(context['awsClientIn'],
'pypyraws.steps.client')
assert str(err_info.value) == ("methodName required in awsClientIn "
"for pypyraws.steps.client")
# ---------------------------- get_awsclient_args-----------------------------#