Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kupsum committed Jan 10, 2024
1 parent 5117e64 commit 1f31b13
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import importlib
import json
from unittest import mock

from django.test import TestCase
from django.conf import settings
from django.test import TestCase, override_settings
from django.utils import timezone

from push_notifications.conf import AppConfig
Expand Down Expand Up @@ -515,3 +517,29 @@ def test_can_save_wsn_device(self):
self.assertIsNotNone(device.pk)
self.assertIsNotNone(device.date_created)
self.assertEqual(device.date_created.date(), timezone.now().date())

def test_gcm_is_default_cloud_message_type_when_not_specified_in_settings(self) -> None:
self._validate_device_cloud_message_type(expected_cloud_message_type="GCM")

@override_settings()
def test_cloud_message_type_is_set_to_gcm(self) -> None:
settings.PUSH_NOTIFICATIONS_SETTINGS.update({
"DEFAULT_CLOUD_MESSAGE_TYPE": "GCM",
})
self._validate_device_cloud_message_type(expected_cloud_message_type="GCM")

@override_settings()
def test_cloud_message_type_is_set_to_fcm(self) -> None:
settings.PUSH_NOTIFICATIONS_SETTINGS.update({
"DEFAULT_CLOUD_MESSAGE_TYPE": "FCM",
})
self._validate_device_cloud_message_type(expected_cloud_message_type="FCM")

def _validate_device_cloud_message_type(self, expected_cloud_message_type: str) -> None:
# Reload the models so that cached model is evicted and
# field default value is re-read from settings
import push_notifications.models
importlib.reload(push_notifications.models)
from push_notifications.models import GCMDevice
field_object = GCMDevice._meta.get_field("cloud_message_type")
self.assertEqual(field_object.default, expected_cloud_message_type)

0 comments on commit 1f31b13

Please sign in to comment.