File: json_attribute_matcher.py

package info (click to toggle)
python-azure 20201208%2Bgit-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,437,920 kB
  • sloc: python: 4,287,452; javascript: 269; makefile: 198; sh: 187; xml: 106
file content (18 lines) | stat: -rw-r--r-- 612 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import json

import six

_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(six.ensure_str(r1.body))
        c2 = json.loads(six.ensure_str(r2.body))
        assert sorted(c1.keys()) == sorted(c2.keys())