Skip to content

Commit

Permalink
tests: update requests_mock URI registration
Browse files Browse the repository at this point in the history
* As of requests_mock 1.7.0 the previous behaviour of partial matching
  has changed, moving to a regex approach to make it compatible with
  both older and current versions.
  See also: jamielennox/requests-mock#109

Change-Id: Iab2d48365511ae408b1f78b5e8aa1d2e411d407b
  • Loading branch information
volans- committed Sep 29, 2019
1 parent efb86bc commit eefdd92
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cumin/tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Pytest customization for unit tests."""
import re

import pytest
import requests_mock

Expand Down Expand Up @@ -27,8 +29,11 @@ def query_requests(request, mocked_requests): # pylint: disable=redefined-outer
query = puppetdb.PuppetDBQuery(
{'puppetdb': {'api_version': 3, 'urllib3_disable_warnings': ['SubjectAltNameWarning']}})
for endpoint, key in query.hosts_keys.items():
mocked_requests.register_uri('GET', query.url + endpoint + '?query=', status_code=200, json=[
{key: endpoint + '_host1', 'key': 'value1'}, {key: endpoint + '_host2', 'key': 'value2'}])
mocked_requests.register_uri(
'GET',
re.compile(re.escape(query.url + endpoint + '?query=')),
status_code=200,
json=[{key: endpoint + '_host1', 'key': 'value1'}, {key: endpoint + '_host2', 'key': 'value2'}])

# Register a requests response for a non matching query
mocked_requests.register_uri(
Expand Down

0 comments on commit eefdd92

Please sign in to comment.