-
Notifications
You must be signed in to change notification settings - Fork 0
/
pet_by_status.py
65 lines (50 loc) · 2.13 KB
/
pet_by_status.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
''' Step definition for pet_by_status.feature'''
# pylint: disable=consider-using-f-string
import re
import json
from behave import step, then
from settings import API_URL, log
@then('the json response should be a list of least "{int:d}" items')
def step_impl(context, int):
data = context.response.json()
assert isinstance(data, list), 'Expected a but found {}'.format(type(data))
assert len(data) >= int, 'List was {result} items, expected greater than {expected}'.format(
result=len(data),
expected=int
)
@then('the json response should be a dict of least "{int:d}" items')
def step_impl(context, int):
data = context.response.json()
assert isinstance(data, dict), 'Expected a but found {}'.format(type(data))
assert len(data) >= int, 'List was {result} items, expected greater than {expected}'.format(
result=len(data),
expected=int
)
@then('the json response should contain a dog named "{name}"')
def step_impl(context, name):
data = context.response.json()
assert any(dog['name'] == name for dog in data), 'Did not find a dog named {}'.format(name)
@then('the json response should not contain a dog named "{name}"')
def step_impl(context, name):
data = context.response.json()
for dog in data:
try:
assert not dog['name'] == name, 'Unexpectedly found a dog named {}'.format(name)
except KeyError:
continue
@then('all dogs should have a name')
def step_impl(context):
data = context.response.json()
assert all('name' in dog for dog in data), 'A dog was missing the name key'
@then('all dogs should have an ID')
def step_impl(context):
data = context.response.json()
assert all('id' in dog for dog in data), 'A dog was missing ID data'
@then('all dogs should have a status')
def step_impl(context):
data = context.response.json()
assert all('status' in dog for dog in data), 'A dog was missing status data'
@then('should not reveal dog pii')
def step_impl(context):
data = context.response.json()
assert not any('dob' in dog for dog in data), 'Data should not include a dogs Personal Identifiable Information'