File: json_attribute_matcher.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (16 lines) | stat: -rw-r--r-- 578 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import json

_has_json_body = lambda req: req.body and "json" in req.headers.get("Content-Type", "")


def json_attribute_matcher(r1, r2):
    """Tests whether two vcr.py requests have JSON content with identical attributes (ignoring values)."""

    if _has_json_body(r1) and _has_json_body(r2):
        c1 = json.loads(str(r1.body))
        c2 = json.loads(str(r2.body))
        assert sorted(c1.keys()) == sorted(c2.keys())