mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Add first stubs for DF
CURA-7959
This commit is contained in:
parent
8f46a51ff2
commit
32ec72a28c
2 changed files with 96 additions and 0 deletions
86
plugins/DigitalLibrary/tests/TestDigitalLibraryApiClient.py
Normal file
86
plugins/DigitalLibrary/tests/TestDigitalLibraryApiClient.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
from src.DigitalFactoryApiClient import DigitalFactoryApiClient
|
||||||
|
from src.PaginationManager import PaginationManager
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def application():
|
||||||
|
app = MagicMock(spec=CuraApplication, name = "Mocked Cura Application")
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pagination_manager():
|
||||||
|
manager = MagicMock(name = "Mocked Pagination Manager")
|
||||||
|
return manager
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def api_client(application, pagination_manager):
|
||||||
|
api_client = DigitalFactoryApiClient(application, MagicMock())
|
||||||
|
api_client._projects_pagination_mgr = pagination_manager
|
||||||
|
return api_client
|
||||||
|
|
||||||
|
|
||||||
|
def test_getProjectsFirstPage(api_client):
|
||||||
|
# setup
|
||||||
|
http_manager = MagicMock()
|
||||||
|
api_client._http = http_manager
|
||||||
|
pagination_manager = api_client._projects_pagination_mgr
|
||||||
|
pagination_manager.limit = 20
|
||||||
|
|
||||||
|
finished_callback = MagicMock()
|
||||||
|
failed_callback = MagicMock()
|
||||||
|
|
||||||
|
# Call
|
||||||
|
api_client.getProjectsFirstPage(on_finished = finished_callback, failed = failed_callback)
|
||||||
|
|
||||||
|
# Asserts
|
||||||
|
pagination_manager.reset.assert_called_once() # Should be called since we asked for new set of projects
|
||||||
|
http_manager.get.assert_called_once()
|
||||||
|
args = http_manager.get.call_args_list[0]
|
||||||
|
|
||||||
|
# Ensure that it's called with the right limit
|
||||||
|
assert args[0][0] == 'https://api.ultimaker.com/cura/v1/projects?limit=20'
|
||||||
|
|
||||||
|
# Change the limit & try again
|
||||||
|
http_manager.get.reset_mock()
|
||||||
|
pagination_manager.limit = 80
|
||||||
|
api_client.getProjectsFirstPage(on_finished=finished_callback, failed=failed_callback)
|
||||||
|
args = http_manager.get.call_args_list[0]
|
||||||
|
|
||||||
|
# Ensure that it's called with the right limit
|
||||||
|
assert args[0][0] == 'https://api.ultimaker.com/cura/v1/projects?limit=80'
|
||||||
|
|
||||||
|
|
||||||
|
def test_getMoreProjects_noNewProjects(api_client):
|
||||||
|
api_client.hasMoreProjectsToLoad = MagicMock(return_value = False)
|
||||||
|
http_manager = MagicMock()
|
||||||
|
api_client._http = http_manager
|
||||||
|
|
||||||
|
finished_callback = MagicMock()
|
||||||
|
failed_callback = MagicMock()
|
||||||
|
api_client.getMoreProjects(finished_callback, failed_callback)
|
||||||
|
|
||||||
|
http_manager.get.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_getMoreProjects_hasNewProjects(api_client):
|
||||||
|
api_client.hasMoreProjectsToLoad = MagicMock(return_value=True)
|
||||||
|
http_manager = MagicMock()
|
||||||
|
api_client._http = http_manager
|
||||||
|
|
||||||
|
finished_callback = MagicMock()
|
||||||
|
failed_callback = MagicMock()
|
||||||
|
api_client.getMoreProjects(finished_callback, failed_callback)
|
||||||
|
|
||||||
|
http_manager.get.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
def test_clear(api_client):
|
||||||
|
api_client.clear()
|
||||||
|
api_client._projects_pagination_mgr.reset.assert_called_once()
|
||||||
|
|
10
plugins/DigitalLibrary/tests/conftest.py
Normal file
10
plugins/DigitalLibrary/tests/conftest.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Prevents error: "PyCapsule_GetPointer called with incorrect name" with conflicting SIP configurations between Arcus and PyQt: Import custom Sip bindings first!
|
||||||
|
import Savitar # Dont remove this line
|
||||||
|
import Arcus # No really. Don't. It needs to be there!
|
||||||
|
import pynest2d # Really!
|
||||||
|
|
||||||
|
|
||||||
|
# Ensure that the importing for all tests work
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
Loading…
Add table
Add a link
Reference in a new issue