Repository: jazzband/django-axes
Pull request #749 (2021-05-17 12:06:17)

Bump pytest-django from 4.2.0 to 4.3.0
Bumps [pytest-django](https://github.com/pytest-dev/pytest-django) from 4.2.0 to 4.3.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pytest-dev/pytest-django/blob/master/docs/changelog.rst">pytest-django's changelog</a>.</em></p>
<blockquote>
<h2>v4.3.0 (2021-05-15)</h2>
<p>Improvements
^^^^^^^^^^^^</p>
<ul>
<li>
<p>Add experimental :ref:<code>multiple databases &lt;multi-db&gt;</code> (multi db) support.</p>
</li>
<li>
<p>Add type annotations. If you previously excluded <code>pytest_django</code> from
your type-checker, you can remove the exclusion.</p>
</li>
<li>
<p>Documentation improvements.</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/44fddc2082db16e96e77d388db0ef94812f06226"><code>44fddc2</code></a> Release 4.3.0</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/7924519c309b1df9719cd539bc665228f7e5b376"><code>7924519</code></a> asserts: fix annoying py35 syntax error</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/a54ae984741ae22313deac1c95bae40ce2bf6907"><code>a54ae98</code></a> asserts: add type annotations</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/6ab338f54d1452b012e7bc4b1fee31b168efa97e"><code>6ab338f</code></a> doc/helpers: more directly mention that marks can be scoped</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/92c6b7ef6ee2bf475e529dbc3dcbbd7cbd61e593"><code>92c6b7e</code></a> Add initial experimental multi database support</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/59d0bf3c3ca691c58e8dc1f33e27846f20e8ed6f"><code>59d0bf3</code></a> coverage: exclude TYPE_CHECKING blocks from coverage</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/d3f3d4445c5078064b504fec263e5f11e860dfb1"><code>d3f3d44</code></a> tests: fix a typo in the previous commit</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/648e1b6d4857ecd3ee5b145adf81c344adf14a6b"><code>648e1b6</code></a> tests: avoid if <em>all</em> connections support transactions</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/1ba6b3d47477f2ff3039bc7a1c5cafb05c0d2b82"><code>1ba6b3d</code></a> docs: replace odd page title</li>
<li><a href="https://github.com/pytest-dev/pytest-django/commit/29f71402f8d4bf99290a69ee25294c2b1a1296a8"><code>29f7140</code></a> docs/faq: add missing add_arguments to <code>./manage.py test</code> recipe</li>
<li>Additional commits viewable in <a href="https://github.com/pytest-dev/pytest-django/compare/v4.2.0...v4.3.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pytest-django&package-manager=pip&previous-version=4.2.0&new-version=4.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov[bot]: # [Codecov](https://codecov.io/gh/jazzband/django-axes/pull/749?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) Report
> Merging [#749](https://codecov.io/gh/jazzband/django-axes/pull/749?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) (1edfbe2) into [master](https://codecov.io/gh/jazzband/django-axes/commit/a9c38d0d0b5d33776f7586e11bd2cd613a9dea95?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) (a9c38d0) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/jazzband/django-axes/pull/749/graphs/tree.svg?width=650&height=150&src=pr&token=gcIvl2ZfVI&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband)](https://codecov.io/gh/jazzband/django-axes/pull/749?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband)

```diff
@@           Coverage Diff           @@
##           master     #749   +/-   ##
=======================================
  Coverage   97.93%   97.93%           
=======================================
  Files          31       31           
  Lines         920      920           
  Branches      125      125           
=======================================
  Hits          901      901           
  Misses         16       16           
  Partials        3        3           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/jazzband/django-axes/pull/749?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/jazzband/django-axes/pull/749?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband). Last update [a9c38d0...1edfbe2](https://codecov.io/gh/jazzband/django-axes/pull/749?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband).


Patch:
diff --git a/axes/conf.py b/axes/conf.py
index d2ffe65..4747f1b 100644
--- a/axes/conf.py
+++ b/axes/conf.py
@@ -125,3 +125,7 @@ settings.AXES_SENSITIVE_PARAMETERS = getattr(
     "AXES_SENSITIVE_PARAMETERS",
     [],
 )
+
+# set the callable for the readable string that can be used in
+# e.g. logging to distinguish client requests
+settings.AXES_CLIENT_STR_CALLABLE = getattr(settings, "AXES_CLIENT_STR_CALLABLE", None)
diff --git a/axes/helpers.py b/axes/helpers.py
index d92a80e..dff7f18 100644
--- a/axes/helpers.py
+++ b/axes/helpers.py
@@ -250,6 +250,21 @@ def get_client_str(
     ``{username: "example", ip_address: "127.0.0.1", path_info: "/example/"}``
     """
 
+    if settings.AXES_CLIENT_STR_CALLABLE:
+        log.debug("Using settings.AXES_CLIENT_STR_CALLABLE to get client string.")
+
+        if callable(settings.AXES_CLIENT_STR_CALLABLE):
+            return settings.AXES_CLIENT_STR_CALLABLE(
+                username, ip_address, user_agent, path_info
+            )
+        if isinstance(settings.AXES_CLIENT_STR_CALLABLE, str):
+            return import_string(settings.AXES_CLIENT_STR_CALLABLE)(
+                username, ip_address, user_agent, path_info
+            )
+        raise TypeError(
+            "settings.AXES_CLIENT_STR_CALLABLE needs to be a string, callable or None."
+        )
+
     client_dict = dict()
 
     if settings.AXES_VERBOSE:


Test patch:
diff --git a/requirements-test.txt b/requirements-test.txt
index 6e9db1d..a5a3f39 100644
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -2,5 +2,5 @@
 coverage==5.5
 pytest==6.2.4
 pytest-cov==2.11.1
-pytest-django==4.2.0
+pytest-django==4.3.0
 pytest-subtests==0.4.0
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 14cb557..d2f02af 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -225,6 +225,16 @@ class ClientStringTestCase(AxesTestCase):
 
         self.assertEqual(expected, actual)
 
+    @override_settings(AXES_CLIENT_STR_CALLABLE="tests.test_helpers.get_dummy_client_str")
+    def test_get_client_str_callable(self):
+        self.assertEqual(
+            get_client_str("username", "ip_address", "user_agent", "path_info"),
+            "client string"
+        )
+
+def get_dummy_client_str(username, ip_address, user_agent, path_info):
+    return "client string"
+
 
 class ClientParametersTestCase(AxesTestCase):
     @override_settings(AXES_ONLY_USER_FAILURES=True)