Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions tests/test_streaming_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
from datetime import datetime, timezone
from unittest.mock import MagicMock, Mock
from unittest.mock import MagicMock

import requests
import responses
Expand Down Expand Up @@ -42,14 +42,14 @@ def test_environment_updates_on_recent_event(
stream_updated_at = datetime(2020, 1, 1, 1, 1, 2, tzinfo=timezone.utc)
environment_updated_at = datetime(2020, 1, 1, 1, 1, 1, tzinfo=timezone.utc)

mocker.patch("flagsmith.Flagsmith.update_environment")

flagsmith = Flagsmith(environment_key=server_api_key)
update_environment = mocker.patch.object(flagsmith, "update_environment")
flagsmith._local_evaluation = MagicMock(spec=LocalEvaluation)
flagsmith._environment_updated_at = environment_updated_at

flagsmith.handle_stream_event(event=StreamEvent(updated_at=stream_updated_at))
assert isinstance(flagsmith.update_environment, Mock)
flagsmith.update_environment.assert_called_once()

update_environment.assert_called_once_with()


def test_environment_does_not_update_on_past_event(
Expand All @@ -58,15 +58,14 @@ def test_environment_does_not_update_on_past_event(
stream_updated_at = datetime(2020, 1, 1, 1, 1, 1, tzinfo=timezone.utc)
environment_updated_at = datetime(2020, 1, 1, 1, 1, 2, tzinfo=timezone.utc)

mocker.patch("flagsmith.Flagsmith.update_environment")

flagsmith = Flagsmith(environment_key=server_api_key)
update_environment = mocker.patch.object(flagsmith, "update_environment")
flagsmith._local_evaluation = MagicMock(spec=LocalEvaluation)
flagsmith._environment_updated_at = environment_updated_at

flagsmith.handle_stream_event(event=StreamEvent(updated_at=stream_updated_at))
assert isinstance(flagsmith.update_environment, Mock)
flagsmith.update_environment.assert_not_called()

update_environment.assert_not_called()


def test_environment_does_not_update_on_same_event(
Expand All @@ -75,12 +74,11 @@ def test_environment_does_not_update_on_same_event(
stream_updated_at = datetime(2020, 1, 1, 1, 1, 1, tzinfo=timezone.utc)
environment_updated_at = datetime(2020, 1, 1, 1, 1, 1, tzinfo=timezone.utc)

mocker.patch("flagsmith.Flagsmith.update_environment")

flagsmith = Flagsmith(environment_key=server_api_key)
update_environment = mocker.patch.object(flagsmith, "update_environment")
flagsmith._local_evaluation = MagicMock(spec=LocalEvaluation)
flagsmith._environment_updated_at = environment_updated_at

flagsmith.handle_stream_event(event=StreamEvent(updated_at=stream_updated_at))
assert isinstance(flagsmith.update_environment, Mock)
flagsmith.update_environment.assert_not_called()

update_environment.assert_not_called()