From 39bf0e2d94ac8c04f631c8a7ac7c0e4b11d51b10 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Wed, 24 Jul 2024 19:55:21 +0200 Subject: [PATCH] Rename to use credentials file --- temba/channels/types/firebase/tests.py | 4 ++-- temba/channels/types/firebase/views.py | 11 ++--------- temba/utils/fields.py | 5 +++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/temba/channels/types/firebase/tests.py b/temba/channels/types/firebase/tests.py index badce95441f..d62c22bc515 100644 --- a/temba/channels/types/firebase/tests.py +++ b/temba/channels/types/firebase/tests.py @@ -20,7 +20,7 @@ def setUp(self): address="87654", role="SR", schemes=["fcm"], - config={"FCM_TITLE": "Title", "FCM_AUTH_JSON": {"foo": "bar", "project_id": "87654"}}, + config={"FCM_TITLE": "Title", "FCM_CREDENTIALS_JSON": {"foo": "bar", "project_id": "87654"}}, ) @patch("requests.get") @@ -50,7 +50,7 @@ def test_claim(self, mock_get): self.assertEqual( channel.config, { - "FCM_AUTH_JSON": {"foo": "bar", "baz": "abc", "project_id": "abcde12345"}, + "FCM_CREDENTIALS_JSON": {"foo": "bar", "baz": "abc", "project_id": "abcde12345"}, "FCM_TITLE": "FCM Channel", "FCM_NOTIFICATION": True, }, diff --git a/temba/channels/types/firebase/views.py b/temba/channels/types/firebase/views.py index e16e4434875..b9f48eedd51 100644 --- a/temba/channels/types/firebase/views.py +++ b/temba/channels/types/firebase/views.py @@ -1,21 +1,14 @@ -import json - from smartmin.views import SmartFormView from django import forms from django.utils.translation import gettext_lazy as _ -from temba.utils.fields import InputWidget +from temba.utils.fields import InputWidget, PrettyJSONEncoder from ...models import Channel from ...views import ClaimViewMixin -class PrettyJSONEncoder(json.JSONEncoder): - def __init__(self, *args, indent, sort_keys, **kwargs): - super().__init__(*args, indent=4, sort_keys=False, **kwargs) - - class ClaimView(ClaimViewMixin, SmartFormView): class Form(ClaimViewMixin.Form): title = forms.CharField(label=_("Notification Title")) @@ -43,7 +36,7 @@ def form_valid(self, form): title = form.cleaned_data.get("title") authentication_json = form.cleaned_data.get("authentication_json") address = form.cleaned_data.get("address") - config = {"FCM_TITLE": title, "FCM_AUTH_JSON": authentication_json} + config = {"FCM_TITLE": title, "FCM_CREDENTIALS_JSON": authentication_json} if form.cleaned_data.get("send_notification") == "True": config["FCM_NOTIFICATION"] = True diff --git a/temba/utils/fields.py b/temba/utils/fields.py index ba76e621d06..a4c960c38a7 100644 --- a/temba/utils/fields.py +++ b/temba/utils/fields.py @@ -387,3 +387,8 @@ def prepare_value(self, value): def valid_value(self, value): return True + + +class PrettyJSONEncoder(json.JSONEncoder): # pragma: needs cover + def __init__(self, *args, indent, sort_keys, **kwargs): + super().__init__(*args, indent=4, sort_keys=False, **kwargs)