From 5cde2a576f3c3954a6e3a59e8a61ab1e6d6d01ac Mon Sep 17 00:00:00 2001 From: chausman <chausman@nrao.edu> Date: Mon, 25 Mar 2024 16:51:32 -0600 Subject: [PATCH] try making shared/ tests runable by service --- .gitlab-ci.yml | 3 + docker-compose.local.yml | 6 +- services/capability/poetry.lock | 78 ++++++++++++++++++- services/capability/pyproject.toml | 2 + services/workflow/Dockerfile | 21 ++--- shared/workspaces/test/capability/__init__.py | 0 .../{ => capability}/test_archive_service.py | 0 .../test_capability_actions.py | 2 +- .../test_capability_architect.py | 0 .../test_capability_execution.py | 0 .../{ => capability}/test_capability_info.py | 6 +- .../{ => capability}/test_capability_queue.py | 2 +- .../test_capability_request.py | 2 +- .../test_capability_service.py | 2 +- .../test_execution_manager.py | 6 +- .../{ => capability}/test_req_state_setter.py | 0 .../test/{ => capability}/test_states.py | 0 .../test/notification/test_nothing.py | 2 + shared/workspaces/test/workflow/__init__.py | 0 .../test_remote_processing_service.py | 2 +- .../test/{ => workflow}/test_views.py | 0 .../{ => workflow}/test_workflow_architect.py | 0 .../test/{ => workflow}/test_workflow_info.py | 0 .../{ => workflow}/test_workflow_recovery.py | 2 +- .../{ => workflow}/test_workflow_service.py | 2 +- 25 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 shared/workspaces/test/capability/__init__.py rename shared/workspaces/test/{ => capability}/test_archive_service.py (100%) rename shared/workspaces/test/{ => capability}/test_capability_actions.py (99%) rename shared/workspaces/test/{ => capability}/test_capability_architect.py (100%) rename shared/workspaces/test/{ => capability}/test_capability_execution.py (100%) rename shared/workspaces/test/{ => capability}/test_capability_info.py (99%) rename shared/workspaces/test/{ => capability}/test_capability_queue.py (98%) rename shared/workspaces/test/{ => capability}/test_capability_request.py (99%) rename shared/workspaces/test/{ => capability}/test_capability_service.py (98%) rename shared/workspaces/test/{ => capability}/test_execution_manager.py (97%) rename shared/workspaces/test/{ => capability}/test_req_state_setter.py (100%) rename shared/workspaces/test/{ => capability}/test_states.py (100%) create mode 100644 shared/workspaces/test/notification/test_nothing.py create mode 100644 shared/workspaces/test/workflow/__init__.py rename shared/workspaces/test/{ => workflow}/test_remote_processing_service.py (98%) rename shared/workspaces/test/{ => workflow}/test_views.py (100%) rename shared/workspaces/test/{ => workflow}/test_workflow_architect.py (100%) rename shared/workspaces/test/{ => workflow}/test_workflow_info.py (100%) rename shared/workspaces/test/{ => workflow}/test_workflow_recovery.py (97%) rename shared/workspaces/test/{ => workflow}/test_workflow_service.py (99%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ba4be96d0..ebc3a326b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -224,6 +224,7 @@ unit test workflow: variables: SERVICE_NAME: "workflow" PATH_PREFIX: "services/" + PATH_PREFIX2: "shared/workspaces/test/" extends: .unit-test unit test capability: @@ -232,6 +233,7 @@ unit test capability: variables: SERVICE_NAME: "capability" PATH_PREFIX: "services/" + PATH_PREFIX2: "shared/workspaces/test/" extends: .unit-test unit test notification: @@ -240,6 +242,7 @@ unit test notification: variables: SERVICE_NAME: "notification" PATH_PREFIX: "services/" + PATH_PREFIX2: "shared/workspaces/test/" extends: .unit-test diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 52ed048ed..fa0a13e66 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -52,7 +52,7 @@ services: context: . dockerfile: ./config/htcondor/cm/Dockerfile.local ports: - - 9618 + - "9618" condor-execute: build: @@ -202,7 +202,6 @@ services: - ./services/capability:/code/services/capability - ./shared:/code/shared - ./apps/cli:/code/apps/cli -# - ./testing:/code/testing notification: @@ -231,9 +230,6 @@ services: - ./docker.properties:/home/ssa/capo/docker.properties - ./services/notification:/code/services/notification - ./shared:/code/shared -# - ./apps/cli:/code/apps/cli -# - ./testing:/code/testing - frontend: build: diff --git a/services/capability/poetry.lock b/services/capability/poetry.lock index 2f47bf8d6..cd3d0815e 100644 --- a/services/capability/poetry.lock +++ b/services/capability/poetry.lock @@ -32,6 +32,25 @@ files = [ [package.dependencies] vine = ">=5.0.0" +[[package]] +name = "attrs" +version = "23.2.0" +description = "Classes Without Boilerplate" +optional = false +python-versions = ">=3.7" +files = [ + {file = "attrs-23.2.0-py3-none-any.whl", hash = "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1"}, + {file = "attrs-23.2.0.tar.gz", hash = "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30"}, +] + +[package.extras] +cov = ["attrs[tests]", "coverage[toml] (>=5.3)"] +dev = ["attrs[tests]", "pre-commit"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope-interface"] +tests = ["attrs[tests-no-zope]", "zope-interface"] +tests-mypy = ["mypy (>=1.6)", "pytest-mypy-plugins"] +tests-no-zope = ["attrs[tests-mypy]", "cloudpickle", "hypothesis", "pympler", "pytest (>=4.3.0)", "pytest-xdist[psutil]"] + [[package]] name = "beaker" version = "1.12.1" @@ -552,6 +571,38 @@ files = [ docs = ["Sphinx", "pylons-sphinx-themes", "setuptools", "watchdog"] testing = ["mock", "pytest", "pytest-cov", "watchdog"] +[[package]] +name = "hypothesis" +version = "6.87.1" +description = "A library for property-based testing" +optional = false +python-versions = ">=3.8" +files = [ + {file = "hypothesis-6.87.1-py3-none-any.whl", hash = "sha256:6b03e774d7ddddc29810e58ba4c41b5c9a894427aaf336e6400c560655a7449b"}, + {file = "hypothesis-6.87.1.tar.gz", hash = "sha256:13615a8f7fa27d102c43ab2f92eaef519988700f3ca8129bc6340d36dec372dd"}, +] + +[package.dependencies] +attrs = ">=19.2.0" +exceptiongroup = {version = ">=1.0.0", markers = "python_version < \"3.11\""} +sortedcontainers = ">=2.1.0,<3.0.0" + +[package.extras] +all = ["backports.zoneinfo (>=0.2.1)", "black (>=19.10b0)", "click (>=7.0)", "django (>=3.2)", "dpcontracts (>=0.4)", "lark (>=0.10.1)", "libcst (>=0.3.16)", "numpy (>=1.17.3)", "pandas (>=1.1)", "pytest (>=4.6)", "python-dateutil (>=1.4)", "pytz (>=2014.1)", "redis (>=3.0.0)", "rich (>=9.0.0)", "tzdata (>=2023.3)"] +cli = ["black (>=19.10b0)", "click (>=7.0)", "rich (>=9.0.0)"] +codemods = ["libcst (>=0.3.16)"] +dateutil = ["python-dateutil (>=1.4)"] +django = ["django (>=3.2)"] +dpcontracts = ["dpcontracts (>=0.4)"] +ghostwriter = ["black (>=19.10b0)"] +lark = ["lark (>=0.10.1)"] +numpy = ["numpy (>=1.17.3)"] +pandas = ["pandas (>=1.1)"] +pytest = ["pytest (>=4.6)"] +pytz = ["pytz (>=2014.1)"] +redis = ["redis (>=3.0.0)"] +zoneinfo = ["backports.zoneinfo (>=0.2.1)", "tzdata (>=2023.3)"] + [[package]] name = "idna" version = "3.4" @@ -743,6 +794,20 @@ sqlalchemy = "1.4.49" type = "directory" url = "../../shared/messaging" +[[package]] +name = "mock-alchemy" +version = "0.2.1" +description = "SQLAlchemy mock helpers." +optional = false +python-versions = ">=3.7,<4.0" +files = [ + {file = "mock-alchemy-0.2.1.tar.gz", hash = "sha256:05d15cd8c70266a15dc47e101446996f9b5cc61e01a2c91fc0e8408647983849"}, + {file = "mock_alchemy-0.2.1-py3-none-any.whl", hash = "sha256:ff606f210600e053a30d0b2ba1e3b55ff3bc9c5b848fce7d8145131c6e964785"}, +] + +[package.dependencies] +SQLAlchemy = ">=1.3.22,<2.0.0" + [[package]] name = "mysqlclient" version = "2.1.1" @@ -1287,6 +1352,17 @@ files = [ {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] +[[package]] +name = "sortedcontainers" +version = "2.4.0" +description = "Sorted Containers -- Sorted List, Sorted Dict, Sorted Set" +optional = false +python-versions = "*" +files = [ + {file = "sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"}, + {file = "sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"}, +] + [[package]] name = "sqlalchemy" version = "1.4.49" @@ -1605,4 +1681,4 @@ test = ["zope.testing"] [metadata] lock-version = "2.0" python-versions = "~3.10" -content-hash = "eed595656b356b93edda45bf37ede003e100722fd246e548ccfb7c1f0b02cd15" +content-hash = "fe8417a02c3de534ff5492efe37b174adaa428701ff567a2ea30d3d3a79ab155" diff --git a/services/capability/pyproject.toml b/services/capability/pyproject.toml index 6cc282962..d26762c35 100644 --- a/services/capability/pyproject.toml +++ b/services/capability/pyproject.toml @@ -39,6 +39,8 @@ pyramid-debugtoolbar = "4.10" [tool.poetry.group.test.dependencies] pytest = "7.4.2" pytest-cov = "4.1.0" +mock_alchemy = "0.2.1" +hypothesis = "6.87.1" [tool.poetry.scripts] launch_capability = "capability.capability_launcher:main" diff --git a/services/workflow/Dockerfile b/services/workflow/Dockerfile index 32558a54d..35687677a 100644 --- a/services/workflow/Dockerfile +++ b/services/workflow/Dockerfile @@ -37,19 +37,6 @@ RUN addgroup --gid 9233 almapipe && \ #WORKDIR /home/ssa/capo #COPY --chown=vlapipe:vlapipe docker.properties docker.properties - -USER root -WORKDIR /code/ -RUN chown vlapipe . && chgrp vlapipe . - -# Switch to appuser and install poetry -USER vlapipe -RUN curl -sSL https://install.python-poetry.org | python3 - - -ENV PATH "${PATH}:/home/vlapipe/.local/bin" -COPY --chown=vlapipe:vlapipe ./shared ./shared -COPY --chown=vlapipe:vlapipe ./apps/cli ./apps/cli - # HTCondor install USER root RUN apt update && apt install -y curl gnupg apt-transport-https @@ -68,6 +55,14 @@ COPY /config/htcondor/submit/nrao-nofile.conf /etc/security/limits.d/nrao-nofile WORKDIR /code RUN chown vlapipe . && chgrp vlapipe . +# Switch to appuser and install poetry +USER vlapipe +RUN curl -sSL https://install.python-poetry.org | python3 - + +ENV PATH "${PATH}:/home/vlapipe/.local/bin" +COPY --chown=vlapipe:vlapipe ./shared ./shared +COPY --chown=vlapipe:vlapipe ./apps/cli ./apps/cli + # Copy service directory to /code in the image # set ownership of content to vlapipe and the vlapipe group USER vlapipe diff --git a/shared/workspaces/test/capability/__init__.py b/shared/workspaces/test/capability/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/shared/workspaces/test/test_archive_service.py b/shared/workspaces/test/capability/test_archive_service.py similarity index 100% rename from shared/workspaces/test/test_archive_service.py rename to shared/workspaces/test/capability/test_archive_service.py diff --git a/shared/workspaces/test/test_capability_actions.py b/shared/workspaces/test/capability/test_capability_actions.py similarity index 99% rename from shared/workspaces/test/test_capability_actions.py rename to shared/workspaces/test/capability/test_capability_actions.py index 9e1971e7c..174609fd9 100644 --- a/shared/workspaces/test/test_capability_actions.py +++ b/shared/workspaces/test/capability/test_capability_actions.py @@ -47,7 +47,7 @@ from workspaces.capability.services.capability_info import CapabilityInfo from workspaces.capability.services.interfaces import ExecutionManagerIF from workspaces.notification.services.interfaces import NotificationServiceIF -from .conftest import ( +from test.conftest import ( SAMPLE_CAPABILITY_NAMES, SQLITE_MAX_INT, SQLITE_MIN_INT, diff --git a/shared/workspaces/test/test_capability_architect.py b/shared/workspaces/test/capability/test_capability_architect.py similarity index 100% rename from shared/workspaces/test/test_capability_architect.py rename to shared/workspaces/test/capability/test_capability_architect.py diff --git a/shared/workspaces/test/test_capability_execution.py b/shared/workspaces/test/capability/test_capability_execution.py similarity index 100% rename from shared/workspaces/test/test_capability_execution.py rename to shared/workspaces/test/capability/test_capability_execution.py diff --git a/shared/workspaces/test/test_capability_info.py b/shared/workspaces/test/capability/test_capability_info.py similarity index 99% rename from shared/workspaces/test/test_capability_info.py rename to shared/workspaces/test/capability/test_capability_info.py index a8ab6f42f..769dec58b 100644 --- a/shared/workspaces/test/test_capability_info.py +++ b/shared/workspaces/test/capability/test_capability_info.py @@ -43,7 +43,7 @@ from workspaces.capability.schema import ( ) from workspaces.capability.services.capability_info import CapabilityInfo -from .conftest import ( +from test.conftest import ( SAMPLE_CAPABILITY_NAMES, SAMPLE_STATE_MACHINES, SQLITE_MAX_INT, @@ -384,7 +384,9 @@ def test_lookup_capability_request(mock_capability_info: CapabilityInfo): """ Can we find a given CapabilityRequest? """ - template = CapabilityTemplate(filename="PPR.xml", content=str.encode("mi CASA es su CASA")) + template = CapabilityTemplate( + filename="../../../../apps/cli/executables/pexable/vela/test/PPR.xml", content=str.encode("mi CASA es su CASA") + ) capability = Capability() capability.name = "std_calibration" capability.id = 1 diff --git a/shared/workspaces/test/test_capability_queue.py b/shared/workspaces/test/capability/test_capability_queue.py similarity index 98% rename from shared/workspaces/test/test_capability_queue.py rename to shared/workspaces/test/capability/test_capability_queue.py index adfd90dbe..19b677d10 100644 --- a/shared/workspaces/test/test_capability_queue.py +++ b/shared/workspaces/test/capability/test_capability_queue.py @@ -31,7 +31,7 @@ from workspaces.system.schema import AbstractFile from workspaces.workflow.services.workflow_info import WorkflowInfo from workspaces.workflow.services.workflow_service import WorkflowService -from .conftest import mock_capability_info, mock_workflow_service +from test.conftest import mock_capability_info, mock_workflow_service class FakeQueueReporterExecutionManager(ExecutionManagerIF): diff --git a/shared/workspaces/test/test_capability_request.py b/shared/workspaces/test/capability/test_capability_request.py similarity index 99% rename from shared/workspaces/test/test_capability_request.py rename to shared/workspaces/test/capability/test_capability_request.py index 3d9ca25d1..99ae7c225 100644 --- a/shared/workspaces/test/test_capability_request.py +++ b/shared/workspaces/test/capability/test_capability_request.py @@ -35,7 +35,7 @@ from workspaces.capability.schema import ( ) from workspaces.capability.services.capability_info import CapabilityInfo -from .conftest import ( +from test.conftest import ( SAMPLE_CAPABILITY_NAMES, SQLITE_MAX_INT, SQLITE_MIN_INT, diff --git a/shared/workspaces/test/test_capability_service.py b/shared/workspaces/test/capability/test_capability_service.py similarity index 98% rename from shared/workspaces/test/test_capability_service.py rename to shared/workspaces/test/capability/test_capability_service.py index 45f9bf8d7..1cfa1dc41 100644 --- a/shared/workspaces/test/test_capability_service.py +++ b/shared/workspaces/test/capability/test_capability_service.py @@ -34,7 +34,7 @@ from workspaces.capability.services.capability_info import CapabilityInfo from workspaces.capability.services.capability_service import CapabilityService from workspaces.notification.services.interfaces import NotificationServiceIF -from .conftest import mock_capability_info, mock_capability_service +from test.conftest import mock_capability_info, mock_capability_service @pytest.mark.usefixtures("mock_capability_service") diff --git a/shared/workspaces/test/test_execution_manager.py b/shared/workspaces/test/capability/test_execution_manager.py similarity index 97% rename from shared/workspaces/test/test_execution_manager.py rename to shared/workspaces/test/capability/test_execution_manager.py index bc496d989..8a1f2a6d2 100644 --- a/shared/workspaces/test/test_execution_manager.py +++ b/shared/workspaces/test/capability/test_execution_manager.py @@ -105,7 +105,9 @@ def fake_execution() -> CapabilityExecution: :return: fake CapabilityExecution """ - template = CapabilityTemplate(filename="PPR.xml", content=str.encode("foo")) + template = CapabilityTemplate( + filename="../../../../apps/cli/executables/pexable/vela/test/PPR.xml", content=str.encode("foo") + ) capability = Capability() capability.name = "std_calibration" capability.id = 1 @@ -234,7 +236,7 @@ def test_submit_workflow_request( """ wf_request = mock_workflow_requests[0] wf_req_file = WorkflowRequestFile( - filename="PPR.xml", + filename="../../../../apps/cli/executables/pexable/vela/test/PPR.xml", content=str.encode("I'm a little teapot"), workflow_request_id=wf_request.workflow_request_id, ) diff --git a/shared/workspaces/test/test_req_state_setter.py b/shared/workspaces/test/capability/test_req_state_setter.py similarity index 100% rename from shared/workspaces/test/test_req_state_setter.py rename to shared/workspaces/test/capability/test_req_state_setter.py diff --git a/shared/workspaces/test/test_states.py b/shared/workspaces/test/capability/test_states.py similarity index 100% rename from shared/workspaces/test/test_states.py rename to shared/workspaces/test/capability/test_states.py diff --git a/shared/workspaces/test/notification/test_nothing.py b/shared/workspaces/test/notification/test_nothing.py new file mode 100644 index 000000000..3b79f3d7c --- /dev/null +++ b/shared/workspaces/test/notification/test_nothing.py @@ -0,0 +1,2 @@ +def test_always_passes(): + assert True diff --git a/shared/workspaces/test/workflow/__init__.py b/shared/workspaces/test/workflow/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/shared/workspaces/test/test_remote_processing_service.py b/shared/workspaces/test/workflow/test_remote_processing_service.py similarity index 98% rename from shared/workspaces/test/test_remote_processing_service.py rename to shared/workspaces/test/workflow/test_remote_processing_service.py index a48fe15d8..971485633 100644 --- a/shared/workspaces/test/test_remote_processing_service.py +++ b/shared/workspaces/test/workflow/test_remote_processing_service.py @@ -18,7 +18,7 @@ from datetime import datetime from unittest.mock import patch, MagicMock -from test.test_workflow_info import FakeWorkflowInfo +from .test_workflow_info import FakeWorkflowInfo from workspaces.system.schema import AbstractFile from workspaces.workflow.services.remote_processing_service import CapoInjector from workspaces.workflow.schema import Workflow, WorkflowRequest diff --git a/shared/workspaces/test/test_views.py b/shared/workspaces/test/workflow/test_views.py similarity index 100% rename from shared/workspaces/test/test_views.py rename to shared/workspaces/test/workflow/test_views.py diff --git a/shared/workspaces/test/test_workflow_architect.py b/shared/workspaces/test/workflow/test_workflow_architect.py similarity index 100% rename from shared/workspaces/test/test_workflow_architect.py rename to shared/workspaces/test/workflow/test_workflow_architect.py diff --git a/shared/workspaces/test/test_workflow_info.py b/shared/workspaces/test/workflow/test_workflow_info.py similarity index 100% rename from shared/workspaces/test/test_workflow_info.py rename to shared/workspaces/test/workflow/test_workflow_info.py diff --git a/shared/workspaces/test/test_workflow_recovery.py b/shared/workspaces/test/workflow/test_workflow_recovery.py similarity index 97% rename from shared/workspaces/test/test_workflow_recovery.py rename to shared/workspaces/test/workflow/test_workflow_recovery.py index 82334f057..f45d5c18b 100644 --- a/shared/workspaces/test/test_workflow_recovery.py +++ b/shared/workspaces/test/workflow/test_workflow_recovery.py @@ -25,7 +25,7 @@ from pendulum import DateTime import workspaces.workflow.services.recovery as recovery -from .conftest import mock_workflow_requests +from test.conftest import mock_workflow_requests fake_profile = "test-dev" diff --git a/shared/workspaces/test/test_workflow_service.py b/shared/workspaces/test/workflow/test_workflow_service.py similarity index 99% rename from shared/workspaces/test/test_workflow_service.py rename to shared/workspaces/test/workflow/test_workflow_service.py index 4d9f37d3a..6eb2b9628 100644 --- a/shared/workspaces/test/test_workflow_service.py +++ b/shared/workspaces/test/workflow/test_workflow_service.py @@ -47,7 +47,7 @@ from workspaces.workflow.services.interfaces import WorkflowInfoIF from workspaces.workflow.services.workflow_info import WorkflowInfo from workspaces.workflow.services.workflow_service import WorkflowService -from .conftest import mock_workflow_service +from test.conftest import mock_workflow_service logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) -- GitLab