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

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 Firebase Data Client

class tests.firebase_api.test_firebase_data_client.TestFirebaseDataClient[source]

Bases: object

Test for FirebaseDataClient

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