Newer
Older
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from http import HTTPStatus
class Checks:
def __init__(self):
self.checks = {
'Check Response Status Code': Checks.check_response_status_code,
'Check Response Body Containing Array Of URIs set to': Checks.check_response_body_containing_array_of_uris_set_to,
'Check Created Resources Set To': Checks.check_created_resources_set_to
}
@staticmethod
def check_response_status_code(kwargs: list) -> str:
if "status_code" in kwargs:
status_code = kwargs['status_code']
return f'Response Status Code set to {status_code} ({HTTPStatus(status_code).phrase})'
else:
raise Exception(f'ERROR, Expected status_code parameter but received: {kwargs}')
@staticmethod
def check_response_body_containing_array_of_uris_set_to(kwargs: list) -> str:
return 'Response Body set to an array of created entities ids'
@staticmethod
def check_created_resources_set_to(kwargs: list) -> str:
return 'Created resources set to ${entities}'
def get_checks(self, **kwargs) -> str:
checking = None
if "checks" in kwargs:
checking = kwargs["checks"]
else:
raise Exception(f'ERROR, the attribute checks is mandatory, but received: {kwargs}')
if isinstance(checking, str):
result = self.checks[checking](kwargs)
elif isinstance(checking, list):
result = [self.checks[x](kwargs) for x in checking]
result = " and\n".join(result)
else:
raise Exception(f"ERROR, checks type not supported: {checking}")
return result
"""
003_01
Check Response Status Code 201 ${response.status_code}
Check Response Body Containing Array Of URIs set to ${expected_entities_ids} ${response.json()}
${response}= Query Entities
... ${entities_to_be_queried}
... Building
... context=${ngsild_test_suite_context}
... accept=${CONTENT_TYPE_LD_JSON}
Check Created Resources Set To ${entities_to_be_created} ${response.json()}
then {
the SUT sends a valid Response containing
Response Status Code set to 201 (Created) and
Response Body set to an array of created entities ids
and created resources set to ${entities}
}
"""
"""
Check Response Body Content
Check Response Headers Containing Content-Type set to
Check Response Headers Link Not Empty
Check Response Headers Containing URI set to
Check Response Headers ID Not Empty
Check Response Body Containing an Attribute set to
Check Response Body Containing Batch Operation Result
Check Response Body Containing Entity element
Check Response Body Containing List Containing Entity Elements
Check Response Body Containing List Containing Entity Elements With Different Types
Check Response Body Containing EntityTemporal element
Check Response Body Containing List Containing EntityTemporal elements
Check Response Body Containing Subscription element
Check Response Body Containing List Containing Subscription elements
Check Response Body Containing Number Of Entities
Check Response Body Containing Context Source Registration element
Check Response Body Containing EntityTypeList element
Check Response Body Containing EntityType element
Check Response Body Containing EntityTypeInfo element
Check Response Body Containing AttributeList element
Check Response Body Containing Attribute element
Check Response Body Containing List Containing Context Source Registrations elements
Check Response Body Type When Using Session Request
Check Response Body Containing ProblemDetails Element Containing Type Element set to
Check Response Body Title When Using Session Request
Check Response Body Containing ProblemDetails Element Containing Title Element
Check RL Response Body Containing ProblemDetails Element Containing Type Element set to
Check RL Response Body Containing ProblemDetails Element Containing Title Element
Check JSON Value In Response Body
Check NotificationParams
Check Pagination Prev And Next Headers
Check Resource Set To
Check Created Resource Set To
Check Updated Resource Set To
Check Updated Resources Set To
Check SUT Not Containing Resource
Check SUT Not Containing Resources
"""
if __name__ == "__main__":
data = Checks()
print(data.get_checks(checks='Check Response Status Code', status_code=201))
print(data.get_checks(checks='Check Response Body Containing Array Of URIs set to'))
print(data.get_checks(checks='Check Created Resources Set To'))
print()
print(data.get_checks(checks=
['Check Response Status Code',
'Check Response Body Containing Array Of URIs set to',
'Check Created Resources Set To']
, status_code=201))