Connect sync timer to sync() for consistency and add unit tests.

Also rename a function to camelCase

CURA-7473
This commit is contained in:
Nino van Hooff 2020-06-26 16:09:33 +02:00
parent 4f1a18f102
commit 294afdb7ca
3 changed files with 56 additions and 3 deletions

View file

@ -3,6 +3,7 @@ from unittest.mock import MagicMock, patch
import pytest
from cura.API import Account
from cura.API.Account import SyncState
from cura.OAuth2.Models import UserProfile
@ -117,3 +118,55 @@ def test_userProfile(user_profile):
mocked_auth_service.getUserProfile = MagicMock(return_value=None)
assert account.userProfile is None
def test_sync_success():
account = Account(MagicMock())
service1 = "test_service1"
service2 = "test_service2"
account.setSyncState(service1, SyncState.SYNCING)
assert account.syncState == SyncState.SYNCING
account.setSyncState(service2, SyncState.SYNCING)
assert account.syncState == SyncState.SYNCING
account.setSyncState(service1, SyncState.SUCCESS)
# service2 still syncing
assert account.syncState == SyncState.SYNCING
account.setSyncState(service2, SyncState.SUCCESS)
assert account.syncState == SyncState.SUCCESS
def test_sync_update_action():
account = Account(MagicMock())
service1 = "test_service1"
mockUpdateCallback = MagicMock()
account.setSyncState(service1, SyncState.SYNCING)
assert account.syncState == SyncState.SYNCING
account.setUpdatePackagesAction(mockUpdateCallback)
account.onUpdatePackagesClicked()
mockUpdateCallback.assert_called_once_with()
account.setSyncState(service1, SyncState.SUCCESS)
account.sync() # starting a new sync resets the update action to None
account.setSyncState(service1, SyncState.SYNCING)
assert account.syncState == SyncState.SYNCING
account.onUpdatePackagesClicked() # Should not be connected to an action anymore
mockUpdateCallback.assert_called_once_with() # No additional calls
assert account.updatePackagesEnabled is False
account.setSyncState(service1, SyncState.SUCCESS)