Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Barthes <[email protected]>
  • Loading branch information
guilhem-barthes committed Aug 29, 2023
1 parent 772692a commit ca40568
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/api/tests/asset_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def create_function(
creation_date=timezone.now(),
owner=owner,
channel=channel,
status=Function.Status.FUNCTION_STATUS_CREATED,
**get_permissions(owner, public),
)

Expand Down
8 changes: 8 additions & 0 deletions backend/api/tests/views/test_views_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FunctionViewTests(APITestCase):
client_class = AuthenticatedClient

def setUp(self):
self.maxDiff = None
if not os.path.exists(MEDIA_ROOT):
os.makedirs(MEDIA_ROOT)

Expand Down Expand Up @@ -104,6 +105,7 @@ def setUp(self):
"outputs": {
"model": {"kind": "ASSET_MODEL", "multiple": False},
},
"status": "FUNCTION_STATUS_CREATED",
},
{
"key": str(aggregate_function.key),
Expand Down Expand Up @@ -135,6 +137,7 @@ def setUp(self):
"outputs": {
"model": {"kind": "ASSET_MODEL", "multiple": False},
},
"status": "FUNCTION_STATUS_CREATED",
},
{
"key": str(composite_function.key),
Expand Down Expand Up @@ -170,6 +173,7 @@ def setUp(self):
"local": {"kind": "ASSET_MODEL", "multiple": False},
"shared": {"kind": "ASSET_MODEL", "multiple": False},
},
"status": "FUNCTION_STATUS_CREATED",
},
{
"key": str(predict_function.key),
Expand Down Expand Up @@ -204,6 +208,7 @@ def setUp(self):
"outputs": {
"predictions": {"kind": "ASSET_MODEL", "multiple": False},
},
"status": "FUNCTION_STATUS_CREATED",
},
{
"key": str(metric_function.key),
Expand Down Expand Up @@ -237,6 +242,7 @@ def setUp(self):
"outputs": {
"performance": {"kind": "ASSET_PERFORMANCE", "multiple": False},
},
"status": "FUNCTION_STATUS_CREATED",
},
]

Expand Down Expand Up @@ -448,6 +454,7 @@ def mock_orc_response(data):
"function": data["function"],
"inputs": data["inputs"],
"outputs": data["outputs"],
"status": Function.Status.FUNCTION_STATUS_CREATED,
}

function_path = os.path.join(FIXTURE_PATH, filename)
Expand Down Expand Up @@ -477,6 +484,7 @@ def mock_orc_response(data):

with mock.patch.object(OrchestratorClient, "register_function", side_effect=mock_orc_response):
response = self.client.post(self.url, data=data, format="multipart")
print(response.data)
self.assertIsNotNone(response.data["key"])
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# asset created in local db
Expand Down
1 change: 1 addition & 0 deletions backend/backend/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile

from .common import *
from .deps.image_build import *
from .deps.restframework import *
from .mods.cors import *
from .mods.oidc import *
Expand Down
2 changes: 2 additions & 0 deletions backend/orchestrator/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .resources import DataSample
from .resources import Function
from .resources import FunctionInput
from .resources import FunctionStatus
from .resources import Model
from .resources import Permission
from .resources import Permissions
Expand Down Expand Up @@ -94,6 +95,7 @@ class Meta:
function_address = factory.SubFactory(AddressFactory)
inputs = {}
outputs = {}
status = FunctionStatus.FUNCTION_STATUS_CREATED


class ComputePlanFactory(factory.Factory):
Expand Down
7 changes: 0 additions & 7 deletions backend/substrapp/compute_tasks/image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,3 @@ def load_remote_function_image(function: orchestrator.Function, channel: str) ->
storage_path = pathlib.Path(tmp_dir) / f"{container_image_tag}.zip"
storage_path.write_bytes(function_image_content)
push_payload(storage_path, registry=REGISTRY, secure=False)

#
# if exc.status_code == 404:
# raise exceptions.CeleryRetryError(f"Function {function.key} was not found
# on backend {function.owner}")
# else:
# raise exceptions.CeleryNoRetryError("I've got a bad feeling about this.")
3 changes: 2 additions & 1 deletion backend/substrapp/tests/compute_tasks/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from builder import exceptions as build_errors
from orchestrator import failure_report_pb2
from substrapp.compute_tasks import errors

Expand All @@ -19,7 +20,7 @@ def test_from_int(self, input_value: int, expected: errors.ComputeTaskErrorType)
@pytest.mark.parametrize(
("exc", "expected"),
[
(errors.BuildError(logs="some build error"), failure_report_pb2.ERROR_TYPE_BUILD),
(build_errors.BuildError(logs="some build error"), failure_report_pb2.ERROR_TYPE_BUILD),
(errors.ExecutionError(logs=io.BytesIO()), failure_report_pb2.ERROR_TYPE_EXECUTION),
(Exception(), failure_report_pb2.ERROR_TYPE_INTERNAL),
],
Expand Down
4 changes: 2 additions & 2 deletions backend/substrapp/tests/tasks/test_compute_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_compute_task_exception(mocker: MockerFixture):
mock_init_task_dirs = mocker.patch("substrapp.tasks.tasks_compute_task.init_task_dirs")
mock_add_asset_to_buffer = mocker.patch("substrapp.tasks.tasks_compute_task.add_task_assets_to_buffer")
mock_add_asset_to_task_dir = mocker.patch("substrapp.tasks.tasks_compute_task.add_assets_to_taskdir")
mock_build_image_if_missing = mocker.patch("substrapp.tasks.tasks_compute_task.build_image_if_missing")
mock_build_image_if_missing = mocker.patch("builder.image_builder.image_builder.build_image_if_missing")
mock_execute_compute_task = mocker.patch("substrapp.tasks.tasks_compute_task.execute_compute_task")
saver = mocker.MagicMock()
mock_output_saver = mocker.patch("substrapp.tasks.tasks_compute_task.OutputSaver", return_value=saver)
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_celery_retry(mocker: MockerFixture):
mocker.patch("substrapp.tasks.tasks_compute_task.add_task_assets_to_buffer")
mocker.patch("substrapp.tasks.tasks_compute_task.add_assets_to_taskdir")
mocker.patch("substrapp.tasks.tasks_compute_task.restore_dir")
mocker.patch("substrapp.tasks.tasks_compute_task.build_image_if_missing")
mocker.patch("builder.image_builder.image_builder.build_image_if_missing")
mock_execute_compute_task = mocker.patch("substrapp.tasks.tasks_compute_task.execute_compute_task")
mocker.patch("substrapp.tasks.tasks_compute_task.teardown_task_dirs")
mock_retry = mocker.patch("substrapp.tasks.tasks_compute_task.ComputeTask.retry")
Expand Down

0 comments on commit ca40568

Please sign in to comment.