Skip to content

Commit

Permalink
fix(context.py): fixing class validator (#17)
Browse files Browse the repository at this point in the history
* fix(context.py): fixing class validator

Fixed HTTPContext failing to be instantiated due to not reading the workspace properly.

* fix(fixing-workspace-reading): Fixed post_model_validator()

* style(workflow): fixing precommit errors

* fix(run.py): fixing pre-commit errors

* test(tests): fixing tests
  • Loading branch information
odarotto authored Mar 1, 2024
1 parent bb38414 commit 7bc52bb
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""pytest configuration file."""

from click.testing import CliRunner

from workflow.cli.main import cli as workflow
Expand Down
5 changes: 4 additions & 1 deletion tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from workflow.lifecycle.archive import http, posix, run, s3
from workflow.utils import read

WORKSPACE = read.workspace("sample-test")
workspace_path = (
Path(__file__).parent.parent / "workflow" / "workspaces" / "sample-test.yaml"
)
WORKSPACE = read.workspace(workspace_path)


@pytest.fixture(scope="module")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_http_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test the HTTPContext object."""

import pytest

from workflow.http.context import HTTPContext


class TestHTTPContext:
def test_can_be_instantiated(self):
"""Test that the HTTPContext object can be instantiated."""
HTTPContext()

@pytest.mark.skip
def test_clients_connect_to_base_url(self):
"""Tests HTTPContext.clients have connection to their proper backend."""
http = HTTPContext()
assert isinstance(http.buckets.info(), dict)
# TODO test results and pipelines
1 change: 1 addition & 0 deletions tests/test_token.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the token passing."""

from workflow.definitions.work import Work
from workflow.http.context import HTTPContext

Expand Down
7 changes: 4 additions & 3 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from os import chown
from os import chmod

import pytest

from workflow.lifecycle.validate import command, function


@pytest.mark.skip
def test_validate_function():
"""Test the validate function function."""
result = function("os.chown")
assert result == chown
result = function("os.chmod")
assert result == chmod

# Test function import error
with pytest.raises(ImportError):
Expand Down
1 change: 1 addition & 0 deletions workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Top-level imports for Tasks API."""

from pathlib import Path

# Root path to the Workflow Module
Expand Down
1 change: 1 addition & 0 deletions workflow/cli/buckets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common Workflow Utilities."""

from typing import Any, Dict, List, Optional

import click
Expand Down
1 change: 1 addition & 0 deletions workflow/cli/pipelines.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Manage workflow pipelines."""

import json
from typing import Any, Dict, Optional, Tuple

Expand Down
12 changes: 4 additions & 8 deletions workflow/cli/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Fetch and process Work using any method compatible with Tasks API."""


import platform
import signal
import time
Expand Down Expand Up @@ -68,9 +67,9 @@
help="filter work by parent.",
)
@click.option(
"--attempts",
"--lives",
type=int,
default=-1,
default=1,
show_default=True,
help="number of times to attempt work.",
)
Expand Down Expand Up @@ -255,7 +254,6 @@ def attempt(
Returns:
bool: True if work was performed, False otherwise.
"""
kwargs: Dict[str, Any] = {"base_url": base_url}
mode: str = "dynamic"
work: Optional[Work] = None
command: Optional[List[str]] = None
Expand All @@ -272,9 +270,7 @@ def attempt(

# Get work from the workflow backend
try:
work = Work.withdraw(
pipeline=bucket, site=site, tags=tags, parent=parent, **kwargs
)
work = Work.withdraw(pipeline=bucket, site=site, tags=tags, parent=parent)
except Exception as error:
logger.exception(error)

Expand Down Expand Up @@ -314,7 +310,7 @@ def attempt(
]
if any(work.notify.slack.dict().values()) and work.plots:
work.plots = [f"<{product_url}{plot}|{plot}>" for plot in work.plots]
work.update(**kwargs) # type: ignore
work.update() # type: ignore
logger.info("work completed: ✅")
unset_tag()
return status
Expand Down
1 change: 1 addition & 0 deletions workflow/daemons/audit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Audit Daemon."""

import time
from typing import Any, Dict, Optional

Expand Down
1 change: 1 addition & 0 deletions workflow/daemons/transfer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Workflow Transfer Daemon."""

import time
from typing import Any, Dict, List

Expand Down
1 change: 1 addition & 0 deletions workflow/definitions/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Work Object Configuration."""

from typing import List, Optional

from pydantic import Field, field_validator
Expand Down
1 change: 1 addition & 0 deletions workflow/definitions/notify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Notification Configuration."""

from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field, StrictStr
Expand Down
2 changes: 1 addition & 1 deletion workflow/definitions/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def post_model_validation(self) -> "Work":
Work: The current work object.
"""
# Validate if the site provided is allowed in the workspace.
config: Dict[str, Any] = read.workspace(self.workspace.as_posix())
config: Dict[str, Any] = read.workspace(self.workspace)
sites: List[str] = config.get("sites", [])
if self.site not in sites:
error = (
Expand Down
2 changes: 1 addition & 1 deletion workflow/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def configure_session(self) -> "Client":
Client: The validated client instance.
"""
config: Dict[str, Any] = read.workspace(DEFAULT_WORKSPACE_PATH.as_posix())
config: Dict[str, Any] = read.workspace(DEFAULT_WORKSPACE_PATH)
if config.get("auth", {}).get("type", None) == "token":
if config.get("auth", {}).get("provider", None) == "github":
if self.token:
Expand Down
2 changes: 1 addition & 1 deletion workflow/http/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create_clients(self) -> "HTTPContext":
"pipelines": Pipelines,
}
logger.debug(f"creating http clients for {list(clients.keys())}")
config: Dict[str, Any] = read.workspace(self.workspace.as_posix())
config: Dict[str, Any] = read.workspace(self.workspace)
baseurls = config.get("http", {}).get("baseurls", {})
logger.debug(f"baseurls: {baseurls}")
for _name, _class in clients.items():
Expand Down
1 change: 1 addition & 0 deletions workflow/lifecycle/execute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Execute the work function or command."""

import ast
import subprocess
import time
Expand Down
1 change: 1 addition & 0 deletions workflow/lifecycle/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for validating user input."""

import platform
import subprocess
from importlib import import_module
Expand Down
1 change: 1 addition & 0 deletions workflow/utils/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Workflow decorators."""

from typing import Any, Callable

from workflow.utils.logger import get_logger
Expand Down

0 comments on commit 7bc52bb

Please sign in to comment.