feat: add dataflow publication contracts and workflow webui
This commit is contained in:
76
tests/test_dataflow_contract.py
Normal file
76
tests/test_dataflow_contract.py
Normal file
@@ -0,0 +1,76 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from govoplan_core.core.dataflows import (
|
||||
CAPABILITY_DATAFLOW_RUN_LIFECYCLE,
|
||||
DataflowRunDescriptor,
|
||||
DataflowRunLifecycleProvider,
|
||||
dataflow_run_lifecycle,
|
||||
)
|
||||
from govoplan_core.core.modules import ModuleContext, ModuleManifest
|
||||
from govoplan_core.core.registry import PlatformRegistry
|
||||
|
||||
|
||||
class _Provider:
|
||||
def start_run(self, session, principal, *, request):
|
||||
del session, principal
|
||||
return DataflowRunDescriptor(
|
||||
ref="dataflow-run:1",
|
||||
pipeline_ref=request.pipeline_ref,
|
||||
revision=request.revision,
|
||||
status="succeeded",
|
||||
definition_hash="abc",
|
||||
executor_version="test",
|
||||
)
|
||||
|
||||
def get_run(self, session, principal, *, run_ref):
|
||||
del session, principal
|
||||
if run_ref != "dataflow-run:1":
|
||||
return None
|
||||
return DataflowRunDescriptor(
|
||||
ref=run_ref,
|
||||
pipeline_ref="pipeline:1",
|
||||
revision=1,
|
||||
status="succeeded",
|
||||
definition_hash="abc",
|
||||
executor_version="test",
|
||||
)
|
||||
|
||||
def cancel_run(self, session, principal, *, run_ref):
|
||||
del session, principal
|
||||
return DataflowRunDescriptor(
|
||||
ref=run_ref,
|
||||
pipeline_ref="pipeline:1",
|
||||
revision=1,
|
||||
status="cancelled",
|
||||
definition_hash="abc",
|
||||
executor_version="test",
|
||||
)
|
||||
|
||||
|
||||
class DataflowContractTests(unittest.TestCase):
|
||||
def test_run_lifecycle_is_runtime_checkable_and_resolved(self) -> None:
|
||||
provider = _Provider()
|
||||
self.assertIsInstance(provider, DataflowRunLifecycleProvider)
|
||||
registry = PlatformRegistry()
|
||||
registry.register(
|
||||
ModuleManifest(
|
||||
id="dataflow_contract_test",
|
||||
name="Dataflow contract test",
|
||||
version="test",
|
||||
capability_factories={
|
||||
CAPABILITY_DATAFLOW_RUN_LIFECYCLE: lambda context: provider,
|
||||
},
|
||||
)
|
||||
)
|
||||
registry.configure_capability_context(
|
||||
ModuleContext(registry=registry, settings=object())
|
||||
)
|
||||
|
||||
self.assertIs(provider, dataflow_run_lifecycle(registry))
|
||||
self.assertIsNone(dataflow_run_lifecycle(PlatformRegistry()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -6,6 +6,7 @@ from govoplan_core.core.datasources import (
|
||||
CAPABILITY_DATASOURCE_CATALOGUE,
|
||||
CAPABILITY_DATASOURCE_LIFECYCLE,
|
||||
CAPABILITY_DATASOURCE_ORIGINS,
|
||||
CAPABILITY_DATASOURCE_PUBLICATION,
|
||||
DatasourceCatalogueProvider,
|
||||
DatasourceDescriptor,
|
||||
DatasourceField,
|
||||
@@ -14,11 +15,14 @@ from govoplan_core.core.datasources import (
|
||||
DatasourceOrigin,
|
||||
DatasourceOriginProvider,
|
||||
DatasourceOriginReadResult,
|
||||
DatasourcePublicationProvider,
|
||||
DatasourcePublicationResult,
|
||||
DatasourceReadResult,
|
||||
DatasourceStage,
|
||||
datasource_catalogue,
|
||||
datasource_lifecycle,
|
||||
datasource_origins,
|
||||
datasource_publication,
|
||||
)
|
||||
from govoplan_core.core.modules import ModuleContext, ModuleManifest
|
||||
from govoplan_core.core.registry import PlatformRegistry
|
||||
@@ -99,6 +103,21 @@ class _Provider:
|
||||
del session, principal, datasource_ref
|
||||
return self.descriptor
|
||||
|
||||
def publish_rows(self, session, principal, *, request):
|
||||
del session, principal, request
|
||||
return DatasourcePublicationResult(
|
||||
ref="publication:1",
|
||||
status="published",
|
||||
datasource=self.descriptor,
|
||||
materialization=DatasourceMaterialization(
|
||||
ref="materialization:1",
|
||||
datasource_ref=self.descriptor.ref,
|
||||
revision=1,
|
||||
state="published",
|
||||
fingerprint=self.descriptor.fingerprint,
|
||||
),
|
||||
)
|
||||
|
||||
def list_origins(self, session, principal, *, query="", limit=100):
|
||||
del session, principal, query
|
||||
return (
|
||||
@@ -131,6 +150,7 @@ class DatasourceContractTests(unittest.TestCase):
|
||||
provider = _Provider()
|
||||
self.assertIsInstance(provider, DatasourceCatalogueProvider)
|
||||
self.assertIsInstance(provider, DatasourceLifecycleProvider)
|
||||
self.assertIsInstance(provider, DatasourcePublicationProvider)
|
||||
self.assertIsInstance(provider, DatasourceOriginProvider)
|
||||
registry = PlatformRegistry()
|
||||
registry.register(
|
||||
@@ -141,6 +161,7 @@ class DatasourceContractTests(unittest.TestCase):
|
||||
capability_factories={
|
||||
CAPABILITY_DATASOURCE_CATALOGUE: lambda context: provider,
|
||||
CAPABILITY_DATASOURCE_LIFECYCLE: lambda context: provider,
|
||||
CAPABILITY_DATASOURCE_PUBLICATION: lambda context: provider,
|
||||
CAPABILITY_DATASOURCE_ORIGINS: lambda context: provider,
|
||||
},
|
||||
)
|
||||
@@ -149,6 +170,7 @@ class DatasourceContractTests(unittest.TestCase):
|
||||
|
||||
self.assertIs(provider, datasource_catalogue(registry))
|
||||
self.assertIs(provider, datasource_lifecycle(registry))
|
||||
self.assertIs(provider, datasource_publication(registry))
|
||||
self.assertIs(provider, datasource_origins(registry))
|
||||
self.assertIsNone(datasource_catalogue(PlatformRegistry()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user