-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(client): adopt new client in tests
- Loading branch information
Showing
6 changed files
with
200 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,118 @@ | ||
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned,no-name-in-module | ||
|
||
from collections import defaultdict | ||
|
||
import instill.protogen.core.mgmt.v1alpha.mgmt_public_service_pb2_grpc as mgmt_service | ||
import instill.protogen.model.model.v1alpha.model_public_service_pb2_grpc as model_service | ||
import instill.protogen.vdp.pipeline.v1alpha.pipeline_public_service_pb2_grpc as pipeline_service | ||
from instill.clients import MgmtClient, ModelClient, PipelineClient | ||
from instill.clients.instance import InstillInstance | ||
|
||
|
||
def describe_client(): | ||
def describe_instance(): | ||
def when_not_set(expect): | ||
mgmt_client = MgmtClient() | ||
mgmt_client = MgmtClient(False) | ||
expect(mgmt_client.instance) == "" | ||
model_client = ModelClient(namespace="") | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
expect(model_client.instance) == "" | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
expect(pipeline_client.instance) == "" | ||
|
||
def when_set_correct_type(expect): | ||
mgmt_client = MgmtClient() | ||
mgmt_client = MgmtClient(False) | ||
mgmt_client.instance = "staging" | ||
expect(mgmt_client.instance) == "staging" | ||
model_client = ModelClient(namespace="") | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
model_client.instance = "staging" | ||
expect(model_client.instance) == "staging" | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
pipeline_client.instance = "staging" | ||
expect(pipeline_client.instance) == "staging" | ||
|
||
def describe_host(): | ||
def when_not_set(expect): | ||
mgmt_client = MgmtClient() | ||
mgmt_client = MgmtClient(False) | ||
expect(mgmt_client.hosts) is None | ||
model_client = ModelClient(namespace="") | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
expect(model_client.hosts) is None | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
expect(pipeline_client.hosts) is None | ||
|
||
def when_set_correct_type(expect): | ||
mgmt_client = MgmtClient() | ||
d = defaultdict(dict) # type: ignore | ||
d["test_instance"] = dict({"url": "test_url"}) | ||
mgmt_client.hosts = d | ||
expect(mgmt_client.hosts["test_instance"]["url"]) == "test_url" | ||
model_client = ModelClient(namespace="") | ||
model_client.hosts = d | ||
expect(model_client.hosts["test_instance"]["url"]) == "test_url" | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client.hosts = d | ||
expect(pipeline_client.hosts["test_instance"]["url"]) == "test_url" | ||
def when_set_correct_type_url(expect): | ||
mgmt_instance = { | ||
"test_instance": InstillInstance( | ||
mgmt_service.MgmtPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
mgmt_client = MgmtClient(False) | ||
mgmt_client.hosts = mgmt_instance | ||
expect(mgmt_client.hosts["test_instance"].url) == "test_url" | ||
|
||
model_instance = { | ||
"test_instance": InstillInstance( | ||
model_service.ModelPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
model_client.hosts = model_instance | ||
expect(model_client.hosts["test_instance"].url) == "test_url" | ||
|
||
pipeline_instance = { | ||
"test_instance": InstillInstance( | ||
pipeline_service.PipelinePublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
pipeline_client.hosts = pipeline_instance | ||
expect(pipeline_client.hosts["test_instance"].url) == "test_url" | ||
|
||
def when_set_correct_type_token(expect): | ||
mgmt_instance = { | ||
"test_instance": InstillInstance( | ||
mgmt_service.MgmtPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
mgmt_client = MgmtClient(False) | ||
mgmt_client.hosts = mgmt_instance | ||
expect(mgmt_client.hosts["test_instance"].token) == "token" | ||
|
||
model_instance = { | ||
"test_instance": InstillInstance( | ||
model_service.ModelPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
model_client.hosts = model_instance | ||
expect(model_client.hosts["test_instance"].token) == "token" | ||
|
||
pipeline_instance = { | ||
"test_instance": InstillInstance( | ||
pipeline_service.PipelinePublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
pipeline_client.hosts = pipeline_instance | ||
expect(pipeline_client.hosts["test_instance"].token) == "token" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,118 @@ | ||
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned,no-name-in-module | ||
|
||
from collections import defaultdict | ||
|
||
import instill.protogen.core.mgmt.v1alpha.mgmt_public_service_pb2_grpc as mgmt_service | ||
import instill.protogen.model.model.v1alpha.model_public_service_pb2_grpc as model_service | ||
import instill.protogen.vdp.pipeline.v1alpha.pipeline_public_service_pb2_grpc as pipeline_service | ||
from instill.clients import MgmtClient, ModelClient, PipelineClient | ||
from instill.clients.instance import InstillInstance | ||
|
||
|
||
def describe_client(): | ||
def describe_instance(): | ||
def when_not_set(expect): | ||
mgmt_client = MgmtClient() | ||
mgmt_client = MgmtClient(False) | ||
expect(mgmt_client.instance) == "" | ||
model_client = ModelClient(namespace="") | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
expect(model_client.instance) == "" | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
expect(pipeline_client.instance) == "" | ||
|
||
def when_set_correct_type(expect): | ||
mgmt_client = MgmtClient() | ||
mgmt_client = MgmtClient(False) | ||
mgmt_client.instance = "staging" | ||
expect(mgmt_client.instance) == "staging" | ||
model_client = ModelClient(namespace="") | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
model_client.instance = "staging" | ||
expect(model_client.instance) == "staging" | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
pipeline_client.instance = "staging" | ||
expect(pipeline_client.instance) == "staging" | ||
|
||
def describe_host(): | ||
def when_not_set(expect): | ||
mgmt_client = MgmtClient() | ||
mgmt_client = MgmtClient(False) | ||
expect(mgmt_client.hosts) is None | ||
model_client = ModelClient(namespace="") | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
expect(model_client.hosts) is None | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
expect(pipeline_client.hosts) is None | ||
|
||
def when_set_correct_type(expect): | ||
mgmt_client = MgmtClient() | ||
d = defaultdict(dict) # type: ignore | ||
d["test_instance"] = dict({"url": "test_url"}) | ||
mgmt_client.hosts = d | ||
expect(mgmt_client.hosts["test_instance"]["url"]) == "test_url" | ||
model_client = ModelClient(namespace="") | ||
model_client.hosts = d | ||
expect(model_client.hosts["test_instance"]["url"]) == "test_url" | ||
pipeline_client = PipelineClient(namespace="") | ||
pipeline_client.hosts = d | ||
expect(pipeline_client.hosts["test_instance"]["url"]) == "test_url" | ||
def when_set_correct_type_url(expect): | ||
mgmt_instance = { | ||
"test_instance": InstillInstance( | ||
mgmt_service.MgmtPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
mgmt_client = MgmtClient(False) | ||
mgmt_client.hosts = mgmt_instance | ||
expect(mgmt_client.hosts["test_instance"].url) == "test_url" | ||
|
||
model_instance = { | ||
"test_instance": InstillInstance( | ||
model_service.ModelPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
model_client.hosts = model_instance | ||
expect(model_client.hosts["test_instance"].url) == "test_url" | ||
|
||
pipeline_instance = { | ||
"test_instance": InstillInstance( | ||
pipeline_service.PipelinePublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
pipeline_client.hosts = pipeline_instance | ||
expect(pipeline_client.hosts["test_instance"].url) == "test_url" | ||
|
||
def when_set_correct_type_token(expect): | ||
mgmt_instance = { | ||
"test_instance": InstillInstance( | ||
mgmt_service.MgmtPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
mgmt_client = MgmtClient(False) | ||
mgmt_client.hosts = mgmt_instance | ||
expect(mgmt_client.hosts["test_instance"].token) == "token" | ||
|
||
model_instance = { | ||
"test_instance": InstillInstance( | ||
model_service.ModelPublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
model_client = ModelClient(namespace="", asyncio=False) | ||
model_client.hosts = model_instance | ||
expect(model_client.hosts["test_instance"].token) == "token" | ||
|
||
pipeline_instance = { | ||
"test_instance": InstillInstance( | ||
pipeline_service.PipelinePublicServiceStub, | ||
"test_url", | ||
"token", | ||
False, | ||
False, | ||
) | ||
} | ||
pipeline_client = PipelineClient(namespace="", asyncio=False) | ||
pipeline_client.hosts = pipeline_instance | ||
expect(pipeline_client.hosts["test_instance"].token) == "token" |