Firebase API

This package contains tests of the integreat_cms.firebase_api app

Test Firebase API Client

class tests.firebase_api.test_firebase_api_client.TestFirebaseApiClient[source]

Bases: object

Test for FirebaseApiClient

Only tests the correct result (True/False) and logging output depending on the firebase-HTTP response. It does not test if firebase-api-server works/answers as expected.

__init__() None[source]
Return type:

None

response_mock_data = {'200_no_name': {'status_code': 200}, '200_success': {'name': 'projects/integreat-2020/messages/1', 'status_code': 200}, '401_invalid_key': {'error': {'code': 401, 'message': 'Request had invalid authentication credentials.'}, 'status_code': 401}, '404': {'error': {'code': 404}, 'status_code': 404}}[source]

A set of response-data for the mocking-function Google does not really document what errors are possible

send_all_with_mocked_response(settings: SettingsWrapper, requests_mock: Mocker, mocked_response: dict[str, Any]) bool[source]

Fires a send_all() with mocked post

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • requests_mock (Mocker) – Fixture for mocking requests, see pytest

  • mocked_response (dict[str, Any]) – Data for the mocked response, depending on test-scenario (given by response_mock_data)

Returns:

Success status of the notification sending

Return type:

bool

setup_method() None[source]
Return type:

None

teardown_method() None[source]
Return type:

None

test_client_throws_exception_when_fcm_disabled(settings: SettingsWrapper, load_test_data: None) None[source]

Tests that an ImproperlyConfigured exception is thrown, if firebase API is disabled in settings

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

Return type:

None

test_firebase_api_200_success(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker, caplog: LogCaptureFixture) None[source]

Tests firebase-api-response handling, test a successful API call

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • requests_mock (Mocker) – Fixture for mocking requests, see pytest

  • caplog (LogCaptureFixture) – Fixture for asserting log messages in tests (see caplog)

Return type:

None

test_firebase_api_200_unexpected_api_response(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker, caplog: LogCaptureFixture) None[source]

Tests firebase-api-response handling, test a partial successful api call - HTTP 200 but no message name in response

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • requests_mock (Mocker) – Fixture for mocking requests, see pytest

  • caplog (LogCaptureFixture) – Fixture for asserting log messages in tests (see caplog)

Return type:

None

test_firebase_api_403_wrong_token(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker, caplog: LogCaptureFixture) None[source]

Tests firebase-api-response handling, test a denied call - HTTP 403 because of wrong auth-token

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • requests_mock (Mocker) – Fixture for mocking requests, see pytest

  • caplog (LogCaptureFixture) – Fixture for asserting log messages in tests (see caplog)

Return type:

None

test_firebase_api_404(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker, caplog: LogCaptureFixture) None[source]

Tests firebase-api-response handling, test 404 response

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • requests_mock (Mocker) – Fixture for mocking requests, see pytest

  • caplog (LogCaptureFixture) – Fixture for asserting log messages in tests (see caplog)

Return type:

None

test_is_invalid_when_no_title(settings: SettingsWrapper, load_test_data: None) None[source]

Tests that is_valid() is False, when pushNotification-title is missing

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

Return type:

None

test_is_invalid_when_no_translation(settings: SettingsWrapper, load_test_data: None) None[source]

Tests that is_valid() is False, when translation missing

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

Return type:

None

test_is_valid(settings: SettingsWrapper, load_test_data: None) None[source]

Tests that is_valid() is True, when FCM_ENABLED and pushNotification valid (with title and translation)

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

Return type:

None

test_multiple_regions_notification_send(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker) None[source]
Parameters:
  • settings (SettingsWrapper)

  • load_test_data (None)

  • requests_mock (Mocker)

Return type:

None

test_region_notification_send(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker) None[source]
Parameters:
  • settings (SettingsWrapper)

  • load_test_data (None)

  • requests_mock (Mocker)

Return type:

None

Test Firebase Data Client

class tests.firebase_api.test_firebase_data_client.TestFirebaseDataClient[source]

Bases: object

Test for FirebaseDataClient

__init__()[source]
endpoint_mock_url = 'https://fcmdata.googleapis.com/v1beta1/projects/integreat/androidApps/123456/deliveryData'[source]
response_mock_data = {'androidDeliveryData': [{'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '425', 'countNotificationsAccepted': '111'}, 'date': {'day': 5, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '631', 'countNotificationsAccepted': '123'}, 'date': {'day': 5, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '430', 'countNotificationsAccepted': '111'}, 'date': {'day': 5, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '430', 'countNotificationsAccepted': '305'}, 'date': {'day': 5, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '628', 'countNotificationsAccepted': '493', 'proxyNotificationInsightPercents': {'skippedUnsupported': 56}}, 'date': {'day': 4, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '628', 'countNotificationsAccepted': '493', 'proxyNotificationInsightPercents': {'skippedUnsupported': 56}}, 'date': {'day': 4, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '902', 'countNotificationsAccepted': '623', 'proxyNotificationInsightPercents': {'skippedUnsupported': 55}}, 'date': {'day': 4, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '902', 'countNotificationsAccepted': '623', 'proxyNotificationInsightPercents': {'skippedUnsupported': 55}}, 'date': {'day': 4, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '705', 'countNotificationsAccepted': '535', 'proxyNotificationInsightPercents': {'skippedUnsupported': 56}}, 'date': {'day': 3, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '705', 'countNotificationsAccepted': '535', 'proxyNotificationInsightPercents': {'skippedUnsupported': 56}}, 'date': {'day': 3, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '800', 'countNotificationsAccepted': '32', 'proxyNotificationInsightPercents': {'skippedUnsupported': 12}}, 'date': {'day': 3, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '800', 'countNotificationsAccepted': '32', 'proxyNotificationInsightPercents': {'skippedUnsupported': 12}}, 'date': {'day': 3, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 2, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 2, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 2, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 2, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '627', 'countNotificationsAccepted': '474', 'proxyNotificationInsightPercents': {'skippedUnsupported': 73}}, 'date': {'day': 1, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '627', 'countNotificationsAccepted': '474', 'proxyNotificationInsightPercents': {'skippedUnsupported': 73}}, 'date': {'day': 1, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '822', 'countNotificationsAccepted': '512', 'proxyNotificationInsightPercents': {'skippedUnsupported': 12}}, 'date': {'day': 1, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '822', 'countNotificationsAccepted': '512', 'proxyNotificationInsightPercents': {'skippedUnsupported': 12}}, 'date': {'day': 1, 'month': 7, 'year': 2024}}, {'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 30, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 30, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 30, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 30, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'augsburg-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 29, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'augsburg-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 29, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'berlin-de', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 29, 'month': 6, 'year': 2024}}, {'analyticsLabel': 'berlin-en', 'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 29, 'month': 6, 'year': 2024}}]}[source]
test_avg_per_region(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker, mock_firebase_credentials: None) None[source]
Parameters:
  • settings (SettingsWrapper)

  • load_test_data (None)

  • requests_mock (Mocker)

  • mock_firebase_credentials (None)

Return type:

None

test_client_throws_exception_when_fcm_disabled(settings: SettingsWrapper, load_test_data: None, mock_firebase_credentials: None) None[source]

Tests that an ImproperlyConfigured exception is thrown, if firebase API is disabled in settings

Parameters:
  • settings (SettingsWrapper) – The Django settings

  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • mock_firebase_credentials (None) – The mock Firebase credentials

Return type:

None

test_without_analytics_labels(settings: SettingsWrapper, load_test_data: None, requests_mock: Mocker, mock_firebase_credentials: None) None[source]
Parameters:
  • settings (SettingsWrapper)

  • load_test_data (None)

  • requests_mock (Mocker)

  • mock_firebase_credentials (None)

Return type:

None

unlabeled_response_mock_data = {'androidDeliveryData': [{'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '230', 'countNotificationsAccepted': '204'}, 'date': {'day': 5, 'month': 7, 'year': 2024}}, {'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '628', 'countNotificationsAccepted': '493', 'proxyNotificationInsightPercents': {'skippedUnsupported': 56}}, 'date': {'day': 4, 'month': 7, 'year': 2024}}, {'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '705', 'countNotificationsAccepted': '535', 'proxyNotificationInsightPercents': {'skippedUnsupported': 56}}, 'date': {'day': 3, 'month': 7, 'year': 2024}}, {'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 2, 'month': 7, 'year': 2024}}, {'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {'countMessagesAccepted': '627', 'countNotificationsAccepted': '474', 'proxyNotificationInsightPercents': {'skippedUnsupported': 73}}, 'date': {'day': 1, 'month': 7, 'year': 2024}}, {'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 30, 'month': 6, 'year': 2024}}, {'appId': '1:164298278764:android:3fc1f67f3883df306fd549', 'data': {}, 'date': {'day': 29, 'month': 6, 'year': 2024}}]}[source]