Skip to content

Commit

Permalink
Merge pull request #138 from PagerDuty/v5.3.0-support-numeric-filtering
Browse files Browse the repository at this point in the history
V5.3.0: Add support for finding based on numeric fields
  • Loading branch information
Deconstrained authored Oct 4, 2024
2 parents f0cdd6a + 5c0858e commit f414884
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '5.2.0',
VERSION: '5.3.0',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>Changelog &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>Changelog &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>Contribution Guide &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>Contribution Guide &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>Index &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>PDPYRAS: PagerDuty Python REST API Sessions &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>PDPYRAS: PagerDuty Python REST API Sessions &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
11 changes: 10 additions & 1 deletion docs/module_reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>Module Reference &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>Module Reference &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down Expand Up @@ -392,6 +392,15 @@ <h2>API Client Classes<a class="headerlink" href="#api-client-classes" title="Pe
constrained to those matching the query, and so every result in the
index will be downloaded and compared against the query up until a
matching result is found or all results have been checked.</p>
<p>The comparison between the query and matching results is case-insenitive. When
determining uniqueness, APIs are mostly case-insensitive, and therefore objects
with similar characters but differing case can’t even exist. All results (and
the search query) are for this reason reduced pre-comparison to a common form
(all-lowercase strings) so that case doesn’t need to match in the query argument
(which is also interpreted by the API as case-insensitive).</p>
<p>If said behavior differs for a given API, i.e. the uniqueness constraint on a
field is case-sensitive, it should still return the correct results because the
search term sent to the index in the querystring is not lower-cased.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Module Index &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>Python Module Index &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>Search &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />

Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/user_guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>User Guide &#8212; PagerDuty Python REST API Sessions 5.2.0 documentation</title>
<title>User Guide &#8212; PagerDuty Python REST API Sessions 5.3.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
16 changes: 13 additions & 3 deletions pdpyras.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from urllib3.exceptions import HTTPError, PoolError
from requests.exceptions import RequestException

__version__ = '5.2.0'
__version__ = '5.3.0'

#######################
### CLIENT DEFAULTS ###
Expand Down Expand Up @@ -1687,6 +1687,17 @@ def find(self, resource, query, attribute='name', params=None) \
index will be downloaded and compared against the query up until a
matching result is found or all results have been checked.
The comparison between the query and matching results is case-insenitive. When
determining uniqueness, APIs are mostly case-insensitive, and therefore objects
with similar characters but differing case can't even exist. All results (and
the search query) are for this reason reduced pre-comparison to a common form
(all-lowercase strings) so that case doesn't need to match in the query argument
(which is also interpreted by the API as case-insensitive).
If said behavior differs for a given API, i.e. the uniqueness constraint on a
field is case-sensitive, it should still return the correct results because the
search term sent to the index in the querystring is not lower-cased.
:param resource:
The name of the resource endpoint to query, i.e.
``escalation_policies``
Expand All @@ -1710,8 +1721,7 @@ def find(self, resource, query, attribute='name', params=None) \
if params is not None:
query_params.update(params)
query_params.update({'query':query})
# When determining uniqueness, web/the API is largely case-insensitive:
simplify = lambda s: s.lower()
simplify = lambda s: str(s).lower()
search_term = simplify(query)
equiv = lambda s: simplify(s[attribute]) == search_term
obj_iter = self.iter_all(resource, params=query_params)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

__version__ = '5.2.0'
__version__ = '5.3.0'

if __name__ == '__main__':
setup(
Expand Down
11 changes: 8 additions & 3 deletions test_pdpyras.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,20 @@ def test_print_debug(self):
def test_find(self, iter_all):
sess = pdpyras.APISession('token')
iter_all.return_value = iter([
{'type':'user', 'name': 'Someone Else', 'email':'[email protected]'},
{'type':'user', 'name': 'Space Person', 'email':'[email protected] '},
{'type':'user', 'name': 'Someone Personson', 'email':'[email protected]'},
{'type':'user', 'name': 'Someone Else', 'email':'[email protected]', 'f':1},
{'type':'user', 'name': 'Space Person', 'email':'[email protected] ', 'f':2},
{'type':'user', 'name': 'Someone Personson', 'email':'[email protected]', 'f':3},
{'type':'user', 'name': 'Numeric Fields', 'email': '[email protected]', 'f':5}
])
self.assertEqual(
'Someone Personson',
sess.find('users', '[email protected]', attribute='email')['name']
)
iter_all.assert_called_with('users', params={'query':'[email protected]'})
self.assertEqual(
'Numeric Fields',
sess.find('users', 5, attribute='f')['name']
)

@patch.object(pdpyras.APISession, 'iter_cursor')
@patch.object(pdpyras.APISession, 'get')
Expand Down

0 comments on commit f414884

Please sign in to comment.