Skip to content

Commit

Permalink
Merge branch 'master' into ENG-2974
Browse files Browse the repository at this point in the history
  • Loading branch information
JMkrish committed Oct 30, 2023
2 parents afa0dcb + 1b35931 commit 3598381
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 43 deletions.
12 changes: 11 additions & 1 deletion docs/commonly_used_data_types/asset_selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ asset_selection: {
}
```

NOTE: The machine_type strings must match source_type, NOT source_type_clean.
~~NOTE: The machine_type strings must match source_type, NOT source_type_clean.~~

NOTE: Now we can use source_type_clean as well in asset_selection like below for KPIs related SDK functions-

```
asset_selection: {
machine_type: ["Pick & Place"],
machine_source: ["Nagoya - Pick and Place 6", ...]
}
```
3 changes: 3 additions & 0 deletions smsdk/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
API_KEY = "cea8969e-2acd-4ff4-b88b-e6b62d5cd857"
API_SECRETE = "sma_nBy04LSDJhwxXNct8R8pREkwzbUTWjU4ZmQj7Y2ApAi_"
TENANT = "demo-sdk-test"
12 changes: 6 additions & 6 deletions tests/Auth/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def test_auth_init():
"""Test that Authenticator host is set properly"""
tenant = "demo"
tenant = "demo-sdk-test"
cli = client.Client(tenant)
authed = cli.auth

Expand Down Expand Up @@ -64,7 +64,7 @@ def json():
post=MagicMock(return_value=Response()), get=MagicMock(return_value=Response())
)

tenant = "demo"
tenant = "demo-sdk-test"
user = "user@domain.com"
passw = "password"
cli = client.Client(tenant)
Expand All @@ -80,7 +80,7 @@ def test_auth_route_auth(mocked_apikey, mocked_basic):
"""
Test that Authenticator can properly route to auth methods
"""
tenant = "demo"
tenant = "demo-sdk-test"
user = "user@domain.com"
passw = "password"

Expand Down Expand Up @@ -144,7 +144,7 @@ def json():
post=MagicMock(return_value=Response()), get=MagicMock(return_value=Response())
)

tenant = "demo"
tenant = "demo-sdk-test"
user = "user@domain.com"
passw = "password"

Expand Down Expand Up @@ -172,7 +172,7 @@ def json():
post=MagicMock(return_value=Response()), get=MagicMock(return_value=Response())
)

tenant = "demo"
tenant = "demo-sdk-test"
cli = client.Client(tenant)
authed = cli.auth

Expand All @@ -199,7 +199,7 @@ def json():
# post=MagicMock(return_value=Response()), get=MagicMock(return_value=Response())
# )

# tenant = "demo"
# tenant = "demo-sdk-test"
# cli = client.Client(tenant)
# authed = cli.auth

Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from smsdk import client
from requests.sessions import Session
import pytest

from smsdk import const

# Define all the constants used in the test
# These values may change for each run.
API_KEY = "5a73aa5a-1962-4df9-b56e-4a59462f0f00"
API_SECRETE = "sma_FajgH3VbPu68gwy0PzccvhyGRyy1a8CCHhhvy6ooeg1O_"

TENANT = "demo"
API_KEY = const.API_KEY
API_SECRETE = const.API_SECRETE

TENANT = const.TENANT


@pytest.fixture(scope="session")
Expand Down
6 changes: 3 additions & 3 deletions tests/cookbook/test_cookbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def json():

mocked.return_value = MagicMock(get=MagicMock(return_value=ResponseGet()))

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
cookbooks = dt.get_cookbooks()
Expand All @@ -43,7 +43,7 @@ def json():

mocked.return_value = MagicMock(get=MagicMock(return_value=ResponseGet()))

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
runs = dt.get_cookbook_top_results("recipe_group_id", 1)
Expand All @@ -65,7 +65,7 @@ def json():

mocked.return_value = MagicMock(post=MagicMock(return_value=ResponseGet()))

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
value = dt.get_cookbook_current_value([{"asset": "test", "name": "test_field"}])
Expand Down
24 changes: 16 additions & 8 deletions tests/data_viz/test_share_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def json():
mocked.return_value = ResponsePost()
mock_type.return_value = "test_machine"

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
sharelink = dt.create_share_link(["test"], "line", {"id": "cans"})

# Verify
assert sharelink == "https://demo.sightmachine.io/#/analysis/datavis/s/test"
assert (
sharelink == "https://demo-sdk-test.sightmachine.io/#/analysis/datavis/s/test"
)
assert mocked.call_args[1]["json"]["state"]["asset"] == {
"machine_source": ["test"],
"machine_type": ["test_machine"],
Expand All @@ -45,13 +47,15 @@ def json():
mocked.return_value = ResponsePost()
mock_type.return_value = "test_machine"

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
sharelink = dt.create_share_link(["test"], "line", {"id": "cans"}, model="kpi")

# Verify
assert sharelink == "https://demo.sightmachine.io/#/analysis/datavis/s/test"
assert (
sharelink == "https://demo-sdk-test.sightmachine.io/#/analysis/datavis/s/test"
)
assert mocked.call_args[1]["json"]["state"]["asset"] == {
"machine_source": ["test"],
"machine_type": ["test_machine"],
Expand All @@ -74,15 +78,17 @@ def json():
mocked.return_value = ResponsePost()
mock_type.return_value = "test_machine"

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
sharelink = dt.create_share_link(
["test"], "line", {"field": "cans", "machineName": "test"}, model="line"
)

# Verify
assert sharelink == "https://demo.sightmachine.io/#/analysis/datavis/s/test"
assert (
sharelink == "https://demo-sdk-test.sightmachine.io/#/analysis/datavis/s/test"
)
assert mocked.call_args[1]["json"]["state"]["lineProcess"] == {
"selectedMachines": [{"machineName": "test"}]
}
Expand All @@ -109,7 +115,7 @@ def json():
mocked.return_value = ResponsePost()
mock_type.return_value = "test_machine"

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
sharelink = dt.create_share_link(
Expand All @@ -123,7 +129,9 @@ def json():
)

# Verify
assert sharelink == "https://demo.sightmachine.io/#/analysis/datavis/s/test"
assert (
sharelink == "https://demo-sdk-test.sightmachine.io/#/analysis/datavis/s/test"
)
assert mocked.call_args[1]["json"]["state"]["lineProcess"] == {
"assetOffsets": {"test": {"interval": "minutes", "period": 1}},
"selectedMachines": [{"machineName": "test"}],
Expand Down
2 changes: 1 addition & 1 deletion tests/downtime/test_downtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def mockapi(self, session, endpoint, **kwargs):

monkeypatch.setattr(Downtime, "get_downtime", mockapi)

dt = Downtime(get_session, "demo")
dt = Downtime(get_session, "demo-sdk-test")

# Run
df = dt.get_downtime(get_session, URL_V1)
Expand Down
6 changes: 3 additions & 3 deletions tests/kpi/test_kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def json():

mocked.return_value = MagicMock(get=MagicMock(return_value=ResponseGet()))

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
kpis = dt.get_kpis()
Expand All @@ -39,7 +39,7 @@ def mockapi(self, session, endpoint):

monkeypatch.setattr(KPI, "get_kpis_for_asset", mockapi)

dt = KPI(Session(), "demo")
dt = KPI(Session(), "demo-sdk-test")

# Run
df = dt.get_kpis_for_asset(Session(), "/v1/selector/datavis/kpi/y_axis")
Expand Down Expand Up @@ -79,7 +79,7 @@ def json():
get=MagicMock(return_value=ResponseGet()),
)

dt = Client("demo")
dt = Client("demo-sdk-test")
data = dt.get_kpi_data_viz()
assert len(data) == 3
assert data[0]["d_vals"]["quality"]["avg"] == 95.18072289156626
Expand Down
14 changes: 7 additions & 7 deletions tests/machine/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def mockapi(self, session, endpoint):

monkeypatch.setattr(Machine, "get_machines", mockapi)

dt = Machine(Session(), "demo")
dt = Machine(Session(), "demo-sdk-test")

# Run
df = dt.get_machines(Session(), "/api/machine")
Expand Down Expand Up @@ -50,7 +50,7 @@ def json():

mocked.return_value = MagicMock(get=MagicMock(return_value=ResponseGet()))

dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
type = dt.get_type_from_machine("test")
Expand All @@ -64,7 +64,7 @@ def json():
def test_get_machine_schema(mocked_types, mocked_machines):
mocked_machines.return_value = MACHINE_TYPE
mocked_types.return_value = "test"
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_machine_schema("test")
Expand All @@ -81,7 +81,7 @@ def test_get_machine_schema(mocked_types, mocked_machines):
def test_get_machine_schema_hidden(mocked_types, mocked_machines):
mocked_machines.return_value = MACHINE_TYPE
mocked_types.return_value = "test"
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_machine_schema("test", show_hidden=True)
Expand All @@ -100,7 +100,7 @@ def test_get_machine_schema_hidden(mocked_types, mocked_machines):
def test_get_machine_schema_types(mocked_types, mocked_machines):
mocked_machines.return_value = MACHINE_TYPE
mocked_types.return_value = "test"
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_machine_schema("test", types=["float"])
Expand All @@ -115,7 +115,7 @@ def test_get_machine_schema_types(mocked_types, mocked_machines):
def test_get_machine_schema_types_return_mtype(mocked_types, mocked_machines):
mocked_machines.return_value = MACHINE_TYPE
mocked_types.return_value = "test"
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_machine_schema("test", return_mtype=True)
Expand All @@ -129,7 +129,7 @@ def test_get_machine_schema_types_return_mtype(mocked_types, mocked_machines):


"""
This test is against the demo environment and if the environment is changed then this test has to change as well.
This test is against the demo-sdk-test environment and if the environment is changed then this test has to change as well.
"""


Expand Down
10 changes: 5 additions & 5 deletions tests/machine_type/test_machine_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def mockapi(self, session, endpoint):

monkeypatch.setattr(MachineType, "get_machine_types", mockapi)

dt = MachineType(Session(), "demo")
dt = MachineType(Session(), "demo-sdk-test")

# Run
df = dt.get_machine_types(Session(), "/api/machinetype")
Expand Down Expand Up @@ -54,7 +54,7 @@ def mockapi(self, session, endpoint):
@patch("smsdk.smsdk_entities.machine_type.machinetype.MachineType.get_fields")
def test_get_fields_of_machine_type(mocked_machines):
mocked_machines.return_value = MACHINE_TYPE_FIELDS
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_fields_of_machine_type("test")
Expand All @@ -67,7 +67,7 @@ def test_get_fields_of_machine_type(mocked_machines):
@patch("smsdk.smsdk_entities.machine_type.machinetype.MachineType.get_fields")
def test_get_fields_of_machine_type_hidden(mocked_machines):
mocked_machines.return_value = MACHINE_TYPE_FIELDS
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_fields_of_machine_type("test", show_hidden=True)
Expand All @@ -82,7 +82,7 @@ def test_get_fields_of_machine_type_hidden(mocked_machines):
@patch("smsdk.smsdk_entities.machine_type.machinetype.MachineType.get_fields")
def test_get_fields_of_machine_type_types(mocked_machines):
mocked_machines.return_value = MACHINE_TYPE_FIELDS
dt = Client("demo")
dt = Client("demo-sdk-test")

# Run
fields = dt.get_fields_of_machine_type("test", types=["float"])
Expand All @@ -94,7 +94,7 @@ def test_get_fields_of_machine_type_types(mocked_machines):


"""
This test is against the demo environment and if the environment is changed then this test has to change as well.
This test is against the demo-sdk-test environment and if the environment is changed then this test has to change as well.
"""


Expand Down
11 changes: 10 additions & 1 deletion tests/raw_data/test_raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ def test_get_utilities(get_session):


def test_get_raw_data(get_client):
raw_data = get_client.get_raw_data(RAW_DATA_TABLE)
timeselection = {
"time_type": "absolute",
"start_time": "2023-10-18T18:30:00.000Z",
"end_time": "2023-10-19T18:29:59.999Z",
"time_zone": "America/Los_Angeles",
}
select = []
raw_data = get_client.get_raw_data(
RAW_DATA_TABLE, fields=select, time_selection=timeselection
)

# check index
assert raw_data.index.name == "_id"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
def test_client_init():
"""Test the client initialization."""

cli = client.Client("demo")
cli = client.Client("demo-sdk-test")

assert cli.tenant == "demo"
assert cli.tenant == "demo-sdk-test"
assert cli.config["site.domain"] == "sightmachine.io"

cli = client.Client("demo")
cli = client.Client("demo-sdk-test")

# VERIFY
assert cli.tenant == "demo"
assert cli.tenant == "demo-sdk-test"
assert cli.config["site.domain"] == "sightmachine.io"

0 comments on commit 3598381

Please sign in to comment.