notifications-api-common 0.2.2__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/CHANGELOG.rst +14 -0
  2. {notifications-api-common-0.2.2/notifications_api_common.egg-info → notifications_api_common-0.3.0}/PKG-INFO +33 -11
  3. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/README.rst +5 -4
  4. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/admin.py +1 -2
  5. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/kanalen.py +1 -0
  6. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/locale/en/LC_MESSAGES/django.po +1 -1
  7. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/locale/nl/LC_MESSAGES/django.po +1 -1
  8. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/management/commands/register_kanalen.py +5 -3
  9. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/models.py +12 -12
  10. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/settings.py +2 -0
  11. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/tasks.py +5 -5
  12. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/viewsets.py +8 -3
  13. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0/notifications_api_common.egg-info}/PKG-INFO +33 -11
  14. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common.egg-info/requires.txt +4 -3
  15. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/setup.cfg +9 -9
  16. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/tests/test_register_webhook.py +16 -10
  17. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/tests/test_send_message.py +30 -12
  18. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/LICENSE +0 -0
  19. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/MANIFEST.in +0 -0
  20. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/__init__.py +0 -0
  21. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/api/__init__.py +0 -0
  22. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/api/serializers.py +0 -0
  23. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/apps.py +0 -0
  24. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/autoretry.py +0 -0
  25. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/constants.py +0 -0
  26. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/locale/en/LC_MESSAGES/django.mo +0 -0
  27. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/locale/nl/LC_MESSAGES/django.mo +0 -0
  28. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/management/__init__.py +0 -0
  29. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/management/commands/__init__.py +0 -0
  30. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0001_initial.py +0 -0
  31. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0002_notificationsconfig_notifications_api_service.py +0 -0
  32. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0003_migrate_api_root.py +0 -0
  33. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0004_remove_notificationsconfig_api_root.py +0 -0
  34. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0005_auto_20220810_0950.py +0 -0
  35. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0006_auto_20221018_1406.py +0 -0
  36. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0006_auto_20221213_0214.py +0 -0
  37. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0007_auto_20221206_0414.py +0 -0
  38. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/0008_merge_0006_auto_20221213_0214_0007_auto_20221206_0414.py +0 -0
  39. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/migrations/__init__.py +0 -0
  40. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/py.typed +0 -0
  41. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/query.py +0 -0
  42. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/templates/notifications_api_common/kanalen.html +0 -0
  43. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/tests/__init__.py +0 -0
  44. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/tests/utils.py +0 -0
  45. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/urls.py +0 -0
  46. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/utils.py +0 -0
  47. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/validators.py +0 -0
  48. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common/views.py +0 -0
  49. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common.egg-info/SOURCES.txt +0 -0
  50. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common.egg-info/dependency_links.txt +0 -0
  51. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common.egg-info/not-zip-safe +0 -0
  52. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/notifications_api_common.egg-info/top_level.txt +0 -0
  53. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/pyproject.toml +0 -0
  54. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/setup.py +0 -0
  55. {notifications-api-common-0.2.2 → notifications_api_common-0.3.0}/tests/test_kanaal_documentation.py +0 -0
@@ -2,6 +2,20 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ 0.3.0 (2024-10-24)
6
+ ------------------
7
+
8
+ * Upgraded Django requirement to >= 4.2
9
+ * Upgraded minimum python requirement to >= 3.10
10
+ * Added python 3.12 support
11
+ * Added the `NOTIFICATIONS_GUARANTEE_DELIVERY` environment variable which allows
12
+ `RuntimeError`s to be raised (or not to) whenever no Notifications API is
13
+ configured. The default for this setting is set to `True`.
14
+ * Upgraded zgw-consumers to 0.35.1
15
+ * This removed support for retrieving external OAS files to determine
16
+ * This requires `zgw_consumers.models.Service` ("service") instances to be
17
+ created to do external API calls through `zgw_consumer`
18
+
5
19
  0.2.2 (2023-04-20)
6
20
  ------------------
7
21
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: notifications-api-common
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Re-usable integration layer for the Common Ground Notifications API specification.
5
5
  Home-page: https://github.com/maykinmedia/notifications-api-common
6
6
  Author: Maykin Media
@@ -12,32 +12,53 @@ Project-URL: Source Code, https://github.com/maykinmedia/notifications-api-commo
12
12
  Keywords: notifications,REST,API,Common Ground,ZGW
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Framework :: Django
15
- Classifier: Framework :: Django :: 3.2
16
- Classifier: Framework :: Django :: 4.0
15
+ Classifier: Framework :: Django :: 4.2
17
16
  Classifier: Intended Audience :: Developers
18
17
  Classifier: Operating System :: Unix
19
18
  Classifier: Operating System :: MacOS
20
19
  Classifier: Operating System :: Microsoft :: Windows
21
- Classifier: Programming Language :: Python :: 3.7
22
- Classifier: Programming Language :: Python :: 3.8
23
- Classifier: Programming Language :: Python :: 3.9
24
20
  Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
25
23
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ License-File: LICENSE
25
+ Requires-Dist: django>=4.2.0
26
+ Requires-Dist: django-solo
27
+ Requires-Dist: djangorestframework>=3.12.0
28
+ Requires-Dist: celery
29
+ Requires-Dist: djangorestframework_camel_case>=1.2.0
30
+ Requires-Dist: zgw-consumers>=0.35.1
31
+ Requires-Dist: ape-pie
26
32
  Provides-Extra: db
33
+ Requires-Dist: psycopg2; extra == "db"
27
34
  Provides-Extra: tests
35
+ Requires-Dist: psycopg2; extra == "tests"
36
+ Requires-Dist: pytest; extra == "tests"
37
+ Requires-Dist: pytest-django; extra == "tests"
38
+ Requires-Dist: freezegun; extra == "tests"
39
+ Requires-Dist: tox; extra == "tests"
40
+ Requires-Dist: isort; extra == "tests"
41
+ Requires-Dist: black; extra == "tests"
42
+ Requires-Dist: flake8; extra == "tests"
43
+ Requires-Dist: zgw-consumers[testutils]>=0.35.1; extra == "tests"
28
44
  Provides-Extra: pep8
45
+ Requires-Dist: flake8; extra == "pep8"
29
46
  Provides-Extra: coverage
47
+ Requires-Dist: pytest-cov; extra == "coverage"
30
48
  Provides-Extra: docs
49
+ Requires-Dist: sphinx; extra == "docs"
50
+ Requires-Dist: sphinx-rtd-theme; extra == "docs"
31
51
  Provides-Extra: release
32
- License-File: LICENSE
52
+ Requires-Dist: bumpversion; extra == "release"
53
+ Requires-Dist: twine; extra == "release"
33
54
 
34
55
  notifications-api-common
35
56
  ========================
36
57
 
37
- :Version: 0.2.2
58
+ :Version: 0.3.0
38
59
  :Source: https://github.com/maykinmedia/notifications-api-common
39
60
  :Keywords: notifications, REST, API, Common Ground, ZGW
40
- :PythonVersion: 3.9
61
+ :PythonVersion: 3.10
41
62
 
42
63
  |build-status| |code-quality| |black| |coverage| |docs|
43
64
 
@@ -62,9 +83,10 @@ Installation
62
83
  Requirements
63
84
  ------------
64
85
 
65
- * Python 3.7 or above
86
+ * Python 3.10 or above
66
87
  * setuptools 30.3.0 or above
67
- * Django 3.2 or newer
88
+ * Django 4.2 or newer
89
+ * Celery 5.0 or newer setup with one worker deployed
68
90
 
69
91
 
70
92
  Install
@@ -1,10 +1,10 @@
1
1
  notifications-api-common
2
2
  ========================
3
3
 
4
- :Version: 0.2.2
4
+ :Version: 0.3.0
5
5
  :Source: https://github.com/maykinmedia/notifications-api-common
6
6
  :Keywords: notifications, REST, API, Common Ground, ZGW
7
- :PythonVersion: 3.9
7
+ :PythonVersion: 3.10
8
8
 
9
9
  |build-status| |code-quality| |black| |coverage| |docs|
10
10
 
@@ -29,9 +29,10 @@ Installation
29
29
  Requirements
30
30
  ------------
31
31
 
32
- * Python 3.7 or above
32
+ * Python 3.10 or above
33
33
  * setuptools 30.3.0 or above
34
- * Django 3.2 or newer
34
+ * Django 4.2 or newer
35
+ * Celery 5.0 or newer setup with one worker deployed
35
36
 
36
37
 
37
38
  Install
@@ -3,7 +3,6 @@ from django.utils.translation import gettext_lazy as _
3
3
 
4
4
  from requests.exceptions import RequestException
5
5
  from solo.admin import SingletonModelAdmin
6
- from zds_client.client import ClientError
7
6
 
8
7
  from .models import NotificationsConfig, Subscription
9
8
 
@@ -20,7 +19,7 @@ def register_webhook(modeladmin, request, queryset):
20
19
 
21
20
  try:
22
21
  sub.register()
23
- except (ClientError, RequestException) as e:
22
+ except RequestException as e:
24
23
  messages.error(
25
24
  request,
26
25
  _(
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Provide notifications kanaal/exchange classes.
3
3
  """
4
+
4
5
  from collections import defaultdict
5
6
  from typing import Dict, Tuple
6
7
 
@@ -6,7 +6,7 @@
6
6
  #, fuzzy
7
7
  msgid ""
8
8
  msgstr ""
9
- "Project-Id-Version: 0.2.2\n"
9
+ "Project-Id-Version: 0.3.0\n"
10
10
  "Report-Msgid-Bugs-To: \n"
11
11
  "POT-Creation-Date: 2022-12-14 13:45+0100\n"
12
12
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
@@ -6,7 +6,7 @@
6
6
  #, fuzzy
7
7
  msgid ""
8
8
  msgstr ""
9
- "Project-Id-Version: 0.2.2\n"
9
+ "Project-Id-Version: 0.3.0\n"
10
10
  "Report-Msgid-Bugs-To: \n"
11
11
  "POT-Creation-Date: 2022-12-14 13:45+0100\n"
12
12
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
@@ -21,10 +21,12 @@ def create_kanaal(kanaal: str) -> None:
21
21
  """
22
22
  client = NotificationsConfig.get_client()
23
23
 
24
+ assert client
25
+
24
26
  # look up the exchange in the registry
25
27
  _kanaal = next(k for k in KANAAL_REGISTRY if k.label == kanaal)
26
28
 
27
- kanalen = client.list("kanaal", query_params={"naam": kanaal})
29
+ kanalen = client.get("kanaal", params={"naam": kanaal})
28
30
  if kanalen:
29
31
  raise KanaalExists()
30
32
 
@@ -35,9 +37,9 @@ def create_kanaal(kanaal: str) -> None:
35
37
  f"{protocol}://{domain}{reverse('notifications:kanalen')}#{kanaal}"
36
38
  )
37
39
 
38
- client.create(
40
+ client.post(
39
41
  "kanaal",
40
- {
42
+ json={
41
43
  "naam": kanaal,
42
44
  "documentatieLink": documentation_url,
43
45
  "filters": list(_kanaal.kenmerken),
@@ -4,8 +4,9 @@ from django.contrib.postgres.fields import ArrayField
4
4
  from django.db import models
5
5
  from django.utils.translation import gettext_lazy as _
6
6
 
7
+ from ape_pie.client import APIClient
7
8
  from solo.models import SingletonModel
8
- from zds_client import Client, ClientAuth
9
+ from zgw_consumers.client import ZGWAuth, build_client
9
10
  from zgw_consumers.constants import APITypes
10
11
  from zgw_consumers.models import Service
11
12
 
@@ -56,13 +57,15 @@ class NotificationsConfig(SingletonModel):
56
57
  )
57
58
 
58
59
  @classmethod
59
- def get_client(cls) -> Optional[Client]:
60
+ def get_client(cls) -> Optional[APIClient]:
60
61
  """
61
62
  Construct a client, prepared with the required auth.
62
63
  """
63
64
  config = cls.get_solo()
64
65
  if config.notifications_api_service:
65
- return config.notifications_api_service.build_client()
66
+ return build_client(
67
+ config.notifications_api_service, client_factory=APIClient
68
+ )
66
69
  return None
67
70
 
68
71
 
@@ -110,23 +113,20 @@ class Subscription(models.Model):
110
113
  """
111
114
  Registers the webhook with the notification component.
112
115
  """
113
- assert (
114
- NotificationsConfig.get_solo().notifications_api_service
115
- ), "No service for Notifications API configured"
116
+ service = NotificationsConfig.get_solo().notifications_api_service
117
+ assert service, "No service for Notifications API configured"
116
118
 
117
119
  client = NotificationsConfig.get_client()
120
+ assert client
118
121
 
119
122
  # This authentication is for the NC to call us. Thus, it's *not* for
120
123
  # calling the NC to create a subscription.
121
124
  # TODO should be replaced with `TokenAuth`
122
125
  # see: maykinmedia/notifications-api-common/pull/1#discussion_r941450384
123
- self_auth = ClientAuth(
124
- client_id=self.client_id,
125
- secret=self.secret,
126
- )
126
+ self_auth = ZGWAuth(service)
127
127
  data = {
128
128
  "callbackUrl": self.callback_url,
129
- "auth": self_auth.credentials()["Authorization"],
129
+ "auth": f"Bearer {self_auth._token}",
130
130
  "kanalen": [
131
131
  {
132
132
  "naam": channel,
@@ -138,7 +138,7 @@ class Subscription(models.Model):
138
138
  }
139
139
 
140
140
  # register the subscriber
141
- subscriber = client.create("abonnement", data=data)
141
+ subscriber = client.post("abonnement", json=data).json()
142
142
 
143
143
  self._subscription = subscriber["url"]
144
144
  self.save(update_fields=["_subscription"])
@@ -7,6 +7,8 @@ NOTIFICATIONS_DISABLED = False
7
7
 
8
8
  IS_HTTPS = True
9
9
 
10
+ NOTIFICATIONS_GUARANTEE_DELIVERY = True
11
+
10
12
 
11
13
  def get_setting(name: str) -> Any:
12
14
  this_module = sys.modules[__name__]
@@ -2,7 +2,6 @@ import logging
2
2
 
3
3
  import requests
4
4
  from celery import shared_task
5
- from zds_client import ClientError
6
5
 
7
6
  from .autoretry import add_autoretry_behaviour
8
7
  from .models import NotificationsConfig
@@ -27,13 +26,14 @@ def send_notification(self, message: dict) -> None:
27
26
  return
28
27
 
29
28
  try:
30
- client.create("notificaties", message)
29
+ response = client.post("notificaties", json=message)
30
+ response.raise_for_status()
31
31
  # any unexpected errors should show up in error-monitoring, so we only
32
- # catch ClientError exceptions
33
- except (ClientError, requests.HTTPError) as exc:
32
+ # catch HTTPError exceptions
33
+ except requests.HTTPError as exc:
34
34
  logger.warning(
35
35
  "Could not deliver message to %s",
36
- client.api_root,
36
+ client.base_url,
37
37
  exc_info=exc,
38
38
  extra={
39
39
  "notification_msg": message,
@@ -161,11 +161,16 @@ class NotificationMixin(metaclass=NotificationMixinBase):
161
161
  # build the content of the notification
162
162
  message = self.construct_message(data, instance=instance)
163
163
 
164
- # build the client from the singleton config. This will raise an
165
- # exception if the config is not complete. We want this to hard-fail!
164
+ # build the client from the singleton config.
165
+ # This will raise an exception if the config is not complete unless
166
+ # NOTIFICATIONS_GUARANTEE_DELIVERY is explicitly set to False
166
167
  client = NotificationsConfig.get_client()
167
168
  if client is None:
168
- raise RuntimeError("Could not build a client for Notifications API")
169
+ msg = "Not notifying, Notifications API configuration is broken or absent."
170
+ logger.warning(msg)
171
+ if get_setting("NOTIFICATIONS_GUARANTEE_DELIVERY"):
172
+ raise RuntimeError(msg)
173
+ return
169
174
 
170
175
  # We've performed all the work that can raise uncaught exceptions that we can
171
176
  # still put inside an atomic transaction block. Next, we schedule the actual
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: notifications-api-common
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Re-usable integration layer for the Common Ground Notifications API specification.
5
5
  Home-page: https://github.com/maykinmedia/notifications-api-common
6
6
  Author: Maykin Media
@@ -12,32 +12,53 @@ Project-URL: Source Code, https://github.com/maykinmedia/notifications-api-commo
12
12
  Keywords: notifications,REST,API,Common Ground,ZGW
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Framework :: Django
15
- Classifier: Framework :: Django :: 3.2
16
- Classifier: Framework :: Django :: 4.0
15
+ Classifier: Framework :: Django :: 4.2
17
16
  Classifier: Intended Audience :: Developers
18
17
  Classifier: Operating System :: Unix
19
18
  Classifier: Operating System :: MacOS
20
19
  Classifier: Operating System :: Microsoft :: Windows
21
- Classifier: Programming Language :: Python :: 3.7
22
- Classifier: Programming Language :: Python :: 3.8
23
- Classifier: Programming Language :: Python :: 3.9
24
20
  Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
25
23
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ License-File: LICENSE
25
+ Requires-Dist: django>=4.2.0
26
+ Requires-Dist: django-solo
27
+ Requires-Dist: djangorestframework>=3.12.0
28
+ Requires-Dist: celery
29
+ Requires-Dist: djangorestframework_camel_case>=1.2.0
30
+ Requires-Dist: zgw-consumers>=0.35.1
31
+ Requires-Dist: ape-pie
26
32
  Provides-Extra: db
33
+ Requires-Dist: psycopg2; extra == "db"
27
34
  Provides-Extra: tests
35
+ Requires-Dist: psycopg2; extra == "tests"
36
+ Requires-Dist: pytest; extra == "tests"
37
+ Requires-Dist: pytest-django; extra == "tests"
38
+ Requires-Dist: freezegun; extra == "tests"
39
+ Requires-Dist: tox; extra == "tests"
40
+ Requires-Dist: isort; extra == "tests"
41
+ Requires-Dist: black; extra == "tests"
42
+ Requires-Dist: flake8; extra == "tests"
43
+ Requires-Dist: zgw-consumers[testutils]>=0.35.1; extra == "tests"
28
44
  Provides-Extra: pep8
45
+ Requires-Dist: flake8; extra == "pep8"
29
46
  Provides-Extra: coverage
47
+ Requires-Dist: pytest-cov; extra == "coverage"
30
48
  Provides-Extra: docs
49
+ Requires-Dist: sphinx; extra == "docs"
50
+ Requires-Dist: sphinx-rtd-theme; extra == "docs"
31
51
  Provides-Extra: release
32
- License-File: LICENSE
52
+ Requires-Dist: bumpversion; extra == "release"
53
+ Requires-Dist: twine; extra == "release"
33
54
 
34
55
  notifications-api-common
35
56
  ========================
36
57
 
37
- :Version: 0.2.2
58
+ :Version: 0.3.0
38
59
  :Source: https://github.com/maykinmedia/notifications-api-common
39
60
  :Keywords: notifications, REST, API, Common Ground, ZGW
40
- :PythonVersion: 3.9
61
+ :PythonVersion: 3.10
41
62
 
42
63
  |build-status| |code-quality| |black| |coverage| |docs|
43
64
 
@@ -62,9 +83,10 @@ Installation
62
83
  Requirements
63
84
  ------------
64
85
 
65
- * Python 3.7 or above
86
+ * Python 3.10 or above
66
87
  * setuptools 30.3.0 or above
67
- * Django 3.2 or newer
88
+ * Django 4.2 or newer
89
+ * Celery 5.0 or newer setup with one worker deployed
68
90
 
69
91
 
70
92
  Install
@@ -1,10 +1,10 @@
1
- django>=3.2.0
1
+ django>=4.2.0
2
2
  django-solo
3
3
  djangorestframework>=3.12.0
4
4
  celery
5
5
  djangorestframework_camel_case>=1.2.0
6
- gemma-zds-client>=0.15.0
7
- zgw-consumers
6
+ zgw-consumers>=0.35.1
7
+ ape-pie
8
8
 
9
9
  [coverage]
10
10
  pytest-cov
@@ -32,3 +32,4 @@ tox
32
32
  isort
33
33
  black
34
34
  flake8
35
+ zgw-consumers[testutils]>=0.35.1
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = notifications-api-common
3
- version = 0.2.2
3
+ version = 0.3.0
4
4
  description = Re-usable integration layer for the Common Ground Notifications API specification.
5
5
  long_description = file: README.rst
6
6
  url = https://github.com/maykinmedia/notifications-api-common
@@ -15,16 +15,14 @@ keywords = notifications, REST, API, Common Ground, ZGW
15
15
  classifiers =
16
16
  Development Status :: 4 - Beta
17
17
  Framework :: Django
18
- Framework :: Django :: 3.2
19
- Framework :: Django :: 4.0
18
+ Framework :: Django :: 4.2
20
19
  Intended Audience :: Developers
21
20
  Operating System :: Unix
22
21
  Operating System :: MacOS
23
22
  Operating System :: Microsoft :: Windows
24
- Programming Language :: Python :: 3.7
25
- Programming Language :: Python :: 3.8
26
- Programming Language :: Python :: 3.9
27
23
  Programming Language :: Python :: 3.10
24
+ Programming Language :: Python :: 3.11
25
+ Programming Language :: Python :: 3.12
28
26
  Topic :: Software Development :: Libraries :: Python Modules
29
27
 
30
28
  [options]
@@ -32,13 +30,13 @@ zip_safe = False
32
30
  include_package_data = True
33
31
  packages = find:
34
32
  install_requires =
35
- django>=3.2.0
33
+ django>=4.2.0
36
34
  django-solo
37
35
  djangorestframework>=3.12.0
38
36
  celery
39
37
  djangorestframework_camel_case>=1.2.0
40
- gemma-zds-client>=0.15.0
41
- zgw-consumers
38
+ zgw-consumers>=0.35.1
39
+ ape-pie
42
40
  tests_require =
43
41
  psycopg2
44
42
  pytest
@@ -48,6 +46,7 @@ tests_require =
48
46
  isort
49
47
  black
50
48
  flake8
49
+ zgw-consumers[testutils]>=0.35.1
51
50
 
52
51
  [options.packages.find]
53
52
  include =
@@ -66,6 +65,7 @@ tests =
66
65
  isort
67
66
  black
68
67
  flake8
68
+ zgw-consumers[testutils]>=0.35.1
69
69
  pep8 = flake8
70
70
  coverage = pytest-cov
71
71
  docs =
@@ -4,16 +4,24 @@ from django.contrib.messages import get_messages
4
4
  from django.utils.translation import gettext as _
5
5
 
6
6
  import pytest
7
- from requests.exceptions import RequestException
8
- from zds_client.client import ClientError
7
+ from requests import Response
8
+ from requests.exceptions import HTTPError, RequestException
9
9
 
10
10
  from notifications_api_common.admin import register_webhook
11
11
  from notifications_api_common.models import Subscription
12
12
 
13
13
 
14
+ class MockResponse:
15
+ def __init__(self, data):
16
+ self.data = data
17
+
18
+ def json(self):
19
+ return self.data
20
+
21
+
14
22
  @patch(
15
- "zds_client.client.Client.create",
16
- return_value={"url": "https://example.com/api/v1/abonnementen/1"},
23
+ "ape_pie.APIClient.post",
24
+ return_value=MockResponse({"url": "https://example.com/api/v1/abonnementen/1"}),
17
25
  )
18
26
  @pytest.mark.django_db
19
27
  def test_register_webhook_success(
@@ -47,9 +55,7 @@ def test_register_webhook_request_exception(
47
55
  channels=["zaken"],
48
56
  )
49
57
 
50
- with patch(
51
- "zds_client.client.Client.create", side_effect=RequestException("exception")
52
- ):
58
+ with patch("ape_pie.APIClient.post", side_effect=RequestException("exception")):
53
59
  register_webhook(object, request_with_middleware, Subscription.objects.all())
54
60
 
55
61
  messages = list(get_messages(request_with_middleware))
@@ -61,7 +67,7 @@ def test_register_webhook_request_exception(
61
67
 
62
68
 
63
69
  @pytest.mark.django_db
64
- def test_register_webhook_client_error(request_with_middleware, notifications_config):
70
+ def test_register_webhook_http_error(request_with_middleware, notifications_config):
65
71
  Subscription.objects.create(
66
72
  callback_url="https://example.com/callback",
67
73
  client_id="client_id",
@@ -69,7 +75,7 @@ def test_register_webhook_client_error(request_with_middleware, notifications_co
69
75
  channels=["zaken"],
70
76
  )
71
77
 
72
- with patch("zds_client.client.Client.create", side_effect=ClientError("exception")):
78
+ with patch("ape_pie.APIClient.post", side_effect=HTTPError("400")):
73
79
  register_webhook(object, request_with_middleware, Subscription.objects.all())
74
80
 
75
81
  messages = list(get_messages(request_with_middleware))
@@ -77,4 +83,4 @@ def test_register_webhook_client_error(request_with_middleware, notifications_co
77
83
  assert len(messages) == 1
78
84
  assert messages[0].message == _(
79
85
  "Something went wrong while registering subscription for {callback_url}: {e}"
80
- ).format(callback_url="https://example.com/callback", e="exception")
86
+ ).format(callback_url="https://example.com/callback", e="400")
@@ -1,12 +1,12 @@
1
1
  from pathlib import Path
2
2
  from unittest.mock import patch
3
3
 
4
+ from django.test import override_settings
4
5
  from django.urls import reverse
5
6
 
6
7
  import pytest
7
8
  from celery.exceptions import Retry
8
9
  from freezegun import freeze_time
9
- from zgw_consumers.test import mock_service_oas_get
10
10
 
11
11
  from notifications_api_common.tasks import NotificationException, send_notification
12
12
  from testapp.models import Person
@@ -50,9 +50,6 @@ def test_api_create_person(api_client, notifications_config):
50
50
  @pytest.mark.django_db()
51
51
  def test_task_send_notification_success(notifications_config, requests_mock, settings):
52
52
  msg = {"foo": "bar"}
53
- # add mocks
54
- settings.ZGW_CONSUMERS_TEST_SCHEMA_DIRS = [TESTS_DIR / "schemas"]
55
- mock_service_oas_get(requests_mock, NOTIFICATIONS_API_ROOT, "nrc")
56
53
  requests_mock.post(f"{NOTIFICATIONS_API_ROOT}notificaties", status_code=201)
57
54
 
58
55
  send_notification(msg)
@@ -68,10 +65,6 @@ def test_task_send_notification_with_retry(
68
65
  notifications_config, requests_mock, settings
69
66
  ):
70
67
  msg = {"foo": "bar"}
71
-
72
- # add NRC mocks
73
- settings.ZGW_CONSUMERS_TEST_SCHEMA_DIRS = [TESTS_DIR / "schemas"]
74
- mock_service_oas_get(requests_mock, NOTIFICATIONS_API_ROOT, "nrc")
75
68
  exc = NotificationException()
76
69
  requests_mock.post(f"{NOTIFICATIONS_API_ROOT}notificaties", exc=exc)
77
70
 
@@ -93,8 +86,6 @@ def test_task_send_notification_catch_404(
93
86
  which can be handled by the lib users
94
87
  """
95
88
  # add NRC mocks
96
- settings.ZGW_CONSUMERS_TEST_SCHEMA_DIRS = [TESTS_DIR / "schemas"]
97
- mock_service_oas_get(requests_mock, NOTIFICATIONS_API_ROOT, "nrc")
98
89
  requests_mock.post(f"{NOTIFICATIONS_API_ROOT}notificaties", status_code=404)
99
90
 
100
91
  with pytest.raises(NotificationException):
@@ -110,9 +101,36 @@ def test_task_send_notification_catch_500(
110
101
  which can be handled by the lib users
111
102
  """
112
103
  # add NRC mocks
113
- settings.ZGW_CONSUMERS_TEST_SCHEMA_DIRS = [TESTS_DIR / "schemas"]
114
- mock_service_oas_get(requests_mock, NOTIFICATIONS_API_ROOT, "nrc")
115
104
  requests_mock.post(f"{NOTIFICATIONS_API_ROOT}notificaties", status_code=500)
116
105
 
117
106
  with pytest.raises(NotificationException):
118
107
  send_notification({"foo": "bar"})
108
+
109
+
110
+ @freeze_time("2022-01-01")
111
+ @pytest.mark.django_db(transaction=True)
112
+ def test_api_create_person_unconfigured(api_client, notifications_config):
113
+ """Test the default behavior of NOTIFICATIONS_GUARANTEE_DELIVERY=True"""
114
+ notifications_config.delete()
115
+ url = reverse("person-list")
116
+ data = {"name": "John", "address_street": "Grotestraat", "address_number": "1"}
117
+
118
+ with pytest.raises(RuntimeError):
119
+ response = api_client.post(url, data)
120
+
121
+ assert Person.objects.count() == 0
122
+
123
+
124
+ @freeze_time("2022-01-01")
125
+ @pytest.mark.django_db(transaction=True)
126
+ @override_settings(NOTIFICATIONS_GUARANTEE_DELIVERY=False)
127
+ def test_api_create_person_unconfigured_notifications_guarantee_delivery_false(
128
+ api_client, notifications_config
129
+ ):
130
+ notifications_config.delete()
131
+ url = reverse("person-list")
132
+ data = {"name": "John", "address_street": "Grotestraat", "address_number": "1"}
133
+
134
+ response = api_client.post(url, data)
135
+
136
+ assert Person.objects.count() == 1