예제 #1
0
def test_validate_login():
    with monkeypatch_cognite_client() as client:
        valid = _validate_login(client, client, None, None)
        assert valid is True
        wrong_src = _validate_login(client, client, "src", None)
        assert wrong_src is False
        wrong_dest = _validate_login(client, client, None, "dest")
        assert wrong_dest is False
예제 #2
0
def test_copy_events():
    events_src = [
        Event(metadata={}, id=1007, asset_ids=[3, 9], start_time=0, end_time=1),
        Event(metadata={}, id=2007, asset_ids=[7], start_time=1, end_time=2),
        Event(start_time=2, asset_ids=[5], end_time=4, metadata={}),
    ]
    id_mapping = {i: i * 111 for i in range(1, 10)}
    with monkeypatch_cognite_client() as client_dst:
        copy_events(events_src, {}, id_mapping, "src-project-name", 1000000, client_dst, None)
예제 #3
0
def test_create_hierarchy_without_dst_list():
    with monkeypatch_cognite_client() as client:
        runtime = time.time() * 1000
        assets_src = [
            Asset(
                id=3, name="Queen", external_id="Queen in the Kingdom", metadata={}, description="Married to the King"
            ),
            Asset(id=7, name="Prince", parent_id=3, external_id="Future King", metadata={}),
            Asset(id=5, name="Princess", parent_id=3, metadata={}),
        ]
예제 #4
0
def test_mock_cognite_client():
    with monkeypatch_cognite_client() as c_mock:
        c = CogniteClient()
        assert isinstance(c_mock, MagicMock)
        assert c_mock == c

        api_pairs = [
            (c.time_series, c_mock.time_series),
            (c.raw, c_mock.raw),
            (c.assets, c_mock.assets),
            (c.datapoints, c_mock.datapoints),
            (c.events, c_mock.events),
            (c.files, c_mock.files),
            (c.iam, c_mock.iam),
            (c.login, c_mock.login),
            (c.three_d, c_mock.three_d),
        ]
        for api, mock_api in api_pairs:
            assert isinstance(mock_api, MagicMock)
            assert api == mock_api

            with pytest.raises(AttributeError):
                api.does_not_exist
예제 #5
0
def cognite_client_mock():
    with monkeypatch_cognite_client() as client:
        yield client
예제 #6
0
def valid_config(loggedin_status, valid_config_dct):
    with monkeypatch_cognite_client() as cdf_mock:
        cdf_mock.login.status.return_value = loggedin_status
        return FunctionConfig.parse_obj(valid_config_dct)
예제 #7
0
def test_bad_config__cdf_project_mismatch(loggedin_status, valid_config_dct):
    valid_config_dct["tenant"]["cdf_project"] = "not mock!!"
    with monkeypatch_cognite_client() as cdf_mock:
        cdf_mock.login.status.return_value = loggedin_status
        with pytest.raises(ValueError):
            _ = FunctionConfig.parse_obj(valid_config_dct)
예제 #8
0
def test_cognite_client_accepts_arguments_during_and_after_mock():
    with monkeypatch_cognite_client():
        CogniteClient(api_key=None)
    CogniteClient(api_key=None)
예제 #9
0
def mock_cogcli_datapoints_retrieve_single():
    with monkeypatch_cognite_client() as cogmock:
        cogmock.datapoints.retrieve.return_value = Datapoints(
            id=1, external_id="1", value=[1, 2, 3], timestamp=[1000, 2000, 3000]
        )
        yield
예제 #10
0
def mock_cogcli_retrieve_dataframe():
    with monkeypatch_cognite_client() as cogmock:
        cogmock.datapoints.retrieve_dataframe.return_value = pd.DataFrame(
            [[1], [2], [3]], columns=["1"], index=[3000, 4000, 5000]
        )
        yield
예제 #11
0
def mock_cogcli_datapoints_query():
    with monkeypatch_cognite_client() as cogmock:
        cogmock.datapoints.query.return_value = [
            DatapointsList([Datapoints(id=1, external_id="1", value=[1, 2, 3], timestamp=[1000, 2000, 3000])])
        ]
        yield