Skip to content

Commit

Permalink
Merge pull request #94 from opendatadiscovery/feature/api_oddrn_gener…
Browse files Browse the repository at this point in the history
…ator

Adds ApiGenerator
  • Loading branch information
Vixtir authored Oct 27, 2023
2 parents f31345a + 9855634 commit a55fb5b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions oddrn_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
BigQueryStorageGenerator,
CKANGenerator,
AzureDataFactoryGenerator,
ApiGenerator,
)

__all__ = [
Expand Down Expand Up @@ -122,4 +123,5 @@
"BigQueryStorageGenerator",
"CKANGenerator",
"AzureDataFactoryGenerator",
"ApiGenerator",
]
7 changes: 7 additions & 0 deletions oddrn_generator/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
BigQueryStoragePathsModel,
CKANPathsModel,
AzureDataFactoryPathsModel,
ApiPathsModel,
)
from oddrn_generator.server_models import (
AbstractServerModel,
Expand Down Expand Up @@ -547,3 +548,9 @@ class AzureDataFactoryGenerator(Generator):
source = "azure_data_factory"
paths_model = AzureDataFactoryPathsModel
server_model = AzureDomainCloudModel


class ApiGenerator(Generator):
source = "api"
paths_model = ApiPathsModel
server_model = HostnameModel
11 changes: 11 additions & 0 deletions oddrn_generator/path_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,3 +911,14 @@ class Config:
"activities_runs",
),
}


class ApiPathsModel(BasePathsModel):
resources: Optional[str]
fields: Optional[str]

class Config:
dependencies_map = {
"resources": ("resources",),
"fields": ("resources", "fields"),
}
30 changes: 30 additions & 0 deletions tests/test_api_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from oddrn_generator.generators import ApiGenerator


def test_api_generator():
test_host_name = "www.test_host.com"
test_resource_name = "test_resource"
test_field_name = "test_field"

generator = ApiGenerator(
host_settings=test_host_name,
resources=test_resource_name,
fields=test_field_name
)
assert generator.get_data_source_oddrn() == f"//api/host/{test_host_name}"
assert (
generator.get_oddrn_by_path("resources")
== f"//api/host/{test_host_name}/resources/{test_resource_name}"
)
assert (
generator.get_oddrn_by_path("fields")
== f"//api/host/{test_host_name}/resources/{test_resource_name}/fields/{test_field_name}"
)

test_resource_name_2 = "test_resource_2"
test_field_name_2 = "test_field_2"
generator.set_oddrn_paths(resources=test_resource_name_2, fields=test_field_name_2)
assert (
generator.get_oddrn_by_path("fields")
== f"//api/host/{test_host_name}/resources/{test_resource_name_2}/fields/{test_field_name_2}"
)

0 comments on commit a55fb5b

Please sign in to comment.