def created_asset(): random_asset_name = "test_asset" + generate_random_string(10) a1 = Asset(name=random_asset_name) res = assets.post_assets([a1]) assert isinstance(res, AssetListResponse) assert res.to_json()[0]["name"] == random_asset_name assert res.to_json()[0].get("id") != None assets_response = assets.get_assets(random_asset_name, depth=0) while len(assets_response) == 0: assets_response = assets.get_assets(random_asset_name, depth=0) time.sleep(0.5) return assets_response[0]
from typing import List import pandas as pd import pytest from cognite import APIError, CogniteClient from cognite.client.experimental.sequences import Column, Row, RowValue, Sequence, SequenceDataResponse from tests.conftest import generate_random_string sequences = CogniteClient().experimental.sequences # This variable will hold the ID of the sequence that is created in one of the test fixtures of this class. CREATED_SEQUENCE_ID = None # This variable holds the external id used for the sequence that'll be created (and deleted) in these tests SEQUENCE_EXTERNAL_ID = "external_id" + generate_random_string(10) class TestSequences: @pytest.fixture(scope="class") def sequence_that_isnt_created(self): """Returns a Sequence that hasn't been created yet. (It does not have an ID)""" global SEQUENCE_EXTERNAL_ID return Sequence( id=None, name="test_sequence", external_id=SEQUENCE_EXTERNAL_ID, asset_id=None, columns=[ Column(id=None, name="test_column",
import pandas as pd import pytest from cognite import CogniteClient from cognite.client.stable.assets import Asset, AssetListResponse, AssetResponse from tests.conftest import generate_random_string assets = CogniteClient().assets ASSET_NAME = "test_asset" + generate_random_string(10) @pytest.fixture(scope="module") def get_asset_subtree_response(): return assets.get_asset_subtree(asset_id=6354653755843357, limit=1) @pytest.fixture(scope="module") def get_assets_response(): return assets.get_assets(limit=1) def test_get_assets_response_object(get_assets_response): assert isinstance(get_assets_response, AssetListResponse) assert get_assets_response.next_cursor() is not None assert get_assets_response.previous_cursor() is None def test_get_assets_with_metadata_args(): res = assets.get_assets(limit=1, metadata={"something": "something"}) assert not res.to_json()
def test_update_multiple_assets(created_asset): new_name = generate_random_string(10) res = assets.update_assets([Asset(id=created_asset.id, name=new_name)]) assert new_name == res[0].name
def test_update_asset(created_asset): new_name = generate_random_string(10) res = assets.update_asset(created_asset.id, name=new_name) assert new_name == res.name