Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ clean:

## coverage - Test the project and generate an HTML coverage report
coverage:
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=term-missing --cov-fail-under=88
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=term-missing --cov-fail-under=87

## black - Runs the Black Python formatter against the project
black:
Expand Down
46 changes: 23 additions & 23 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,35 @@ def before_record_response(response: Any) -> Any:
if response["body"]["string"]:
response_body = json.loads(response["body"]["string"].decode())

response_body = scrub_data(response_body)
for scrubber in scrubbers:
response_body = scrub_data(response_body, scrubber)

response["body"]["string"] = json.dumps(response_body).encode()
return response

def scrub_data(data: Any) -> Any:
def scrub_data(data: Any, scrubber: Tuple[str, Any]) -> Any:
"""Scrub data from a cassette recursively."""
for scrubber in scrubbers:
key = scrubber[0]
replacement = scrubber[1]

# Root-level list scrubbing
if isinstance(data, list):
key = scrubber[0]
replacement = scrubber[1]

# Root-level list scrubbing
if isinstance(data, list):
for index, item in enumerate(data):
if key in item:
data[index][key] = replacement
elif isinstance(data, dict):
# Root-level key scrubbing
if key in data:
data[key] = replacement
else:
# Nested scrubbing
for index, item in enumerate(data):
if key in item:
data[index][key] = replacement
elif isinstance(data, dict):
# Root-level key scrubbing
if key in data:
data[key] = replacement
else:
# Nested scrubbing
for index, item in enumerate(data):
element = data[item]
if isinstance(element, list):
for nested_index, nested_item in enumerate(element):
data[item][nested_index] = scrub_data(nested_item)
elif isinstance(element, dict):
data[item] = scrub_data(element)
element = data[item]
if isinstance(element, list):
for nested_index, nested_item in enumerate(element):
data[item][nested_index] = scrub_data(nested_item, scrubber)
elif isinstance(element, dict):
data[item] = scrub_data(element, scrubber)
return data

return before_record_response
Expand Down