-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from maykinmedia/feature/kanaal-kenmerken-nest…
…ed-fields ✨ [open-zaak/open-notificaties#156] Several changes to Kanalen
- Loading branch information
Showing
12 changed files
with
247 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
notifications_api_common/management/commands/generate_notificaties.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.conf import settings | ||
from django.core.management import BaseCommand | ||
from django.template.loader import render_to_string | ||
|
||
from notifications_api_common.kanalen import KANAAL_REGISTRY | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Generate a markdown file documenting the notification channels of the component | ||
""" | ||
|
||
def add_arguments(self, parser): | ||
super().add_arguments(parser) | ||
|
||
parser.add_argument( | ||
"--output-file", | ||
dest="output_file", | ||
default=None, | ||
help="Name of the output file", | ||
) | ||
|
||
def handle(self, output_file, *args, **options): | ||
kanalen = sorted(KANAAL_REGISTRY, key=lambda s: s.label) | ||
|
||
template = "notifications_api_common/notificaties.md" | ||
markdown = render_to_string( | ||
template, | ||
context={ | ||
"kanalen": kanalen, | ||
"project_name": settings.PROJECT_NAME, | ||
"site_title": settings.SITE_TITLE, | ||
}, | ||
) | ||
|
||
with open(output_file, "w") as f: | ||
f.write(markdown) |
24 changes: 24 additions & 0 deletions
24
notifications_api_common/templates/notifications_api_common/notificaties.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Notificaties | ||
## Berichtkenmerken voor {{ project_name }} API | ||
|
||
Kanalen worden typisch per component gedefinieerd. Producers versturen berichten op bepaalde kanalen, | ||
consumers ontvangen deze. Consumers abonneren zich via een notificatiecomponent (zoals {{ 'https://notificaties-api.vng.cloud/api/v1/schema/'|urlize }}) op berichten. | ||
|
||
Hieronder staan de kanalen beschreven die door deze component gebruikt worden, met de kenmerken bij elk bericht. | ||
|
||
De architectuur van de notificaties staat beschreven op {{ 'https://github.com/VNG-Realisatie/notificaties-api'|urlize }}. | ||
|
||
{% for kanaal in kanalen %} | ||
### {{ kanaal.label }} | ||
|
||
**Kanaal** | ||
`{{ kanaal.label }}` | ||
|
||
{{ kanaal.description|default:""|urlize }} | ||
|
||
**Resources en acties** | ||
|
||
{% for resource, actions in kanaal.get_usage %} | ||
* <code>{{ resource }}</code>: {{ actions|join:", " }} | ||
{% endfor %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from unittest.mock import mock_open, patch | ||
|
||
from django.test.testcases import call_command | ||
|
||
import pytest | ||
|
||
EXPECTED_OUTPUT = """## Notificaties | ||
## Berichtkenmerken voor Notifications API Common API | ||
Kanalen worden typisch per component gedefinieerd. Producers versturen berichten op bepaalde kanalen, | ||
consumers ontvangen deze. Consumers abonneren zich via een notificatiecomponent (zoals <a href="https://notificaties-api.vng.cloud/api/v1/schema/" rel="nofollow">https://notificaties-api.vng.cloud/api/v1/schema/</a>) op berichten. | ||
Hieronder staan de kanalen beschreven die door deze component gebruikt worden, met de kenmerken bij elk bericht. | ||
De architectuur van de notificaties staat beschreven op <a href="https://github.com/VNG-Realisatie/notificaties-api" rel="nofollow">https://github.com/VNG-Realisatie/notificaties-api</a>. | ||
### personen | ||
**Kanaal** | ||
`personen` | ||
**Main resource** | ||
`person` | ||
**Kenmerken** | ||
* `name`: The name of the person | ||
* `address_street`: custom help text | ||
**Resources en acties** | ||
* <code>person</code>: create, update, destroy | ||
""" | ||
|
||
|
||
@pytest.mark.django_db | ||
@patch( | ||
"notifications_api_common.management.commands.generate_notificaties.open", | ||
new_callable=mock_open, | ||
) | ||
def test_generate_notificaties(mock_file): | ||
call_command("generate_notificaties", output_file=["foobar"]) | ||
|
||
mock_file().write.assert_called_once_with(EXPECTED_OUTPUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.