Skip to content

Commit

Permalink
Verify JSON attributes in Key Vault test playback (#9918)
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell authored Feb 21, 2020
1 parent 78fb483 commit 7dc041d
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 217 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,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())
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
from devtools_testutils import ResourceGroupPreparer, KeyVaultPreparer
from OpenSSL import crypto

from _shared.json_attribute_matcher import json_attribute_matcher
from _shared.preparer import KeyVaultClientPreparer
from _shared.test_case import KeyVaultTestCase


class MergeCertificateTest(KeyVaultTestCase):
def __init__(self, *args, **kwargs):
kwargs["match_body"] = False
kwargs["custom_request_matchers"] = [json_attribute_matcher]
super(MergeCertificateTest, self).__init__(*args, **kwargs)

@ResourceGroupPreparer(random_name_enabled=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from devtools_testutils import ResourceGroupPreparer, KeyVaultPreparer
from OpenSSL import crypto

from _shared.json_attribute_matcher import json_attribute_matcher
from _shared.preparer_async import KeyVaultClientPreparer
from _shared.test_case_async import KeyVaultTestCase


class MergeCertificateTest(KeyVaultTestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, match_body=False, **kwargs)
super().__init__(*args, match_body=False, custom_request_matchers=[json_attribute_matcher], **kwargs)

@ResourceGroupPreparer(random_name_enabled=True)
@KeyVaultPreparer()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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())
Loading

0 comments on commit 7dc041d

Please sign in to comment.