Skip to content

Commit

Permalink
Add minimal test to ensure that start_progress is not called prematur…
Browse files Browse the repository at this point in the history
…ely.
  • Loading branch information
rtibbles committed Aug 14, 2023
1 parent 52e5882 commit f4d268c
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions kolibri/core/auth/test/test_sync_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from unittest.mock import Mock

from django.test import TestCase
from morango.sync.utils import SyncSignalGroup

from kolibri.core.auth.management.utils import MorangoSyncCommand


class TestProgressTracking(TestCase):
def test_transfer_tracker_adapter(self):
# Create an instance of the class you're testing
instance = MorangoSyncCommand()

# Mock the relevant methods
instance.start_progress = Mock()

instance.progresstracker = Mock()
instance.progresstracker.progress = 0

signal_group = SyncSignalGroup()
# Mock the TransferSession
transfer_session_mock = Mock()

transfer_session_mock.records_transferred = 0
transfer_session_mock.records_total = 10
transfer_session_mock.bytes_sent = 0
transfer_session_mock.bytes_received = 0

# Connect the signal group to _transfer_tracker_adapter for testing
instance._transfer_tracker_adapter(signal_group, "message", "sync_state", False)

# Check if start_progress hasn't been called yet
instance.start_progress.assert_not_called()

# Simulate the started signal
signal_group.started.fire(transfer_session=transfer_session_mock)

# Check that start_progress has now been called
instance.start_progress.assert_called()

def test_queueing_tracker_adapter(self):
# Create an instance of the class you're testing
instance = MorangoSyncCommand()

# Mock the relevant methods
instance.start_progress = Mock()

instance.progresstracker = Mock()
instance.progresstracker.progress = 0

signal_group = SyncSignalGroup()
# Mock the TransferSession
transfer_session_mock = Mock()

transfer_session_mock.records_transferred = 0
transfer_session_mock.records_total = 10
transfer_session_mock.bytes_sent = 0
transfer_session_mock.bytes_received = 0

# Connect the signal group to _transfer_tracker_adapter for testing
instance._queueing_tracker_adapter(signal_group, "message", "sync_state", False)

# Check if start_progress hasn't been called yet
instance.start_progress.assert_not_called()

# Simulate the started signal
signal_group.started.fire(transfer_session=transfer_session_mock)

# Check that start_progress has now been called
instance.start_progress.assert_called()

0 comments on commit f4d268c

Please sign in to comment.