Repository: florimondmanca/djangorestframework-api-key

Issue:
RemovedInDjango41Warning due to default_app_config
**Describe the bug**

When starting a django application using this application on django 3.2, it generates this warning:

```
../usr/local/lib/python3.9/site-packages/django/apps/registry.py:91
  /usr/local/lib/python3.9/site-packages/django/apps/registry.py:91: RemovedInDjango41Warning: 'rest_framework_api_key' defines default_app_config = 'rest_framework_api_key.apps.RestFrameworkApiKeyConfig'. Django now detects this configuration automatically. You can remove default_app_config.
    app_config = AppConfig.create(entry)
```

**Desktop (please complete the following information):**
 - OS: Linux
 - Version: 2.0.0
 - Python Version: 3.9.2
 - Django Version: 3.2
 - DRF Version: 3.12.4

**Additional context**

See this for how the django_extensions handled this: https://github.com/django-extensions/django-extensions/pull/1654/files


Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca) Report
> Merging [#187](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca) (69a5630) into [master](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/commit/81f0c6564644c99126fc9dc204b6799255ef73e6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca) (81f0c65) will **increase** coverage by `0.21%`.
> The diff coverage is `97.05%`.

[![Impacted file tree graph](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/graphs/tree.svg?width=650&height=150&src=pr&token=VEi0iPvEl8&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca)](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca)

```diff
@@            Coverage Diff             @@
##           master     #187      +/-   ##
==========================================
+ Coverage   96.22%   96.43%   +0.21%     
==========================================
  Files          22       23       +1     
  Lines         503      533      +30     
==========================================
+ Hits          484      514      +30     
  Misses         19       19              
```


| [Impacted Files](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca) | Coverage Δ | |
|---|---|---|
| [tests/test\_compatibility.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-dGVzdHMvdGVzdF9jb21wYXRpYmlsaXR5LnB5) | `88.88% <88.88%> (ø)` | |
| [src/rest\_framework\_api\_key/\_\_init\_\_.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-c3JjL3Jlc3RfZnJhbWV3b3JrX2FwaV9rZXkvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | |
| [src/rest\_framework\_api\_key/\_\_version\_\_.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-c3JjL3Jlc3RfZnJhbWV3b3JrX2FwaV9rZXkvX192ZXJzaW9uX18ucHk=) | `100.00% <100.00%> (ø)` | |
| [src/rest\_framework\_api\_key/permissions.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-c3JjL3Jlc3RfZnJhbWV3b3JrX2FwaV9rZXkvcGVybWlzc2lvbnMucHk=) | `94.73% <100.00%> (+0.14%)` | :arrow_up: |
| [tests/test\_model.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-dGVzdHMvdGVzdF9tb2RlbC5weQ==) | `100.00% <100.00%> (ø)` | |
| [tests/test\_permissions.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-dGVzdHMvdGVzdF9wZXJtaXNzaW9ucy5weQ==) | `98.66% <100.00%> (+0.30%)` | :arrow_up: |
| [src/rest\_framework\_api\_key/models.py](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca#diff-c3JjL3Jlc3RfZnJhbWV3b3JrX2FwaV9rZXkvbW9kZWxzLnB5) | `100.00% <0.00%> (+1.16%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca).
> **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=Florimond+Manca)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca). Last update [0e7a0d4...69a5630](https://codecov.io/gh/florimondmanca/djangorestframework-api-key/pull/187?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Florimond+Manca). 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=Florimond+Manca).

syth0le: Great! That's would be a nice idea to test it on different django versions on CI
florimondmanca: @syth0le The versions updates got merged, feel free to rebase to see how this behaves against 2.2 and 3.2 :-)
syth0le: I think that all checks has been passed, but to be honest i dont know what to do with tests coverage (for 2 files). is it normal? 
Or do you need to more than 95 percent of tests coverage for each file?
florimondmanca: @syth0le I think codecov requires not reducing the coverage by default. We do have a code branch that's not run here (the one that's for < 3.2), and so the coverage decreased slightly. Not a problem, we can merge. I might look at if there's a way to have Codecov _not_ fail a build for this reason…

Patch:
diff --git a/.gitignore b/.gitignore
index 64c4504..9aeb664 100644
--- a/.gitignore
+++ b/.gitignore
@@ -105,3 +105,5 @@ venv.bak/
 
 # databases
 *.sqlite3
+
+.idea/
diff --git a/src/rest_framework_api_key/__init__.py b/src/rest_framework_api_key/__init__.py
index e327823..4d11ebb 100644
--- a/src/rest_framework_api_key/__init__.py
+++ b/src/rest_framework_api_key/__init__.py
@@ -1,5 +1,8 @@
+import django
+
 from .__version__ import __version__
 
-default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"
+if django.VERSION < (3, 2):
+    default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"
 
 __all__ = ["__version__", "default_app_config"]


Test patch:
diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py
new file mode 100644
index 0000000..ff09936
--- /dev/null
+++ b/tests/test_compatibility.py
@@ -0,0 +1,18 @@
+import django
+import pytest
+
+import rest_framework_api_key
+
+
+@pytest.mark.skipif(
+    django.VERSION < (3, 2), reason="app config is automatically defined by django"
+)
+def test_app_config_not_defined():
+    assert hasattr(rest_framework_api_key, "default_app_config") is False
+
+
+@pytest.mark.skipif(
+    django.VERSION >= (3, 2), reason="app config is not automatically defined by django"
+)
+def test_app_config_defined():
+    assert hasattr(rest_framework_api_key, "default_app_config") is True