def test_advanced_list_fields(self, mock_rel_response): """ Checks that all (non deprecated) fields in the list method are surfaced in the api call """ # TODO: some fields are skipped here because there some deprecated fields are unified with new field, so that # there are inconsistencies in the naming in the api vs the sdk (e.g. there is a relationshipTypes field) in # the api, but no relationship_types in the sdk. If we drop support for the deprecated fields we should be # able to cover all fields with this setup. input = { "active_at_time": random.randint(0, 10000), "sources": [{"resource": "asset", "resource_id": random_string(random.randint(10, 15))}], "targets": [{"resource": "asset", "resource_id": random_string(random.randint(10, 15))}], # "relationship_type": ["flows_to"], "created_time": {"min": random.randint(0, 10000), "max": random.randint(10001, 20000)}, "last_updated_time": {"min": random.randint(0, 10000), "max": random.randint(10001, 20000)}, "start_time": {"min": random.randint(0, 10000), "max": random.randint(10001, 20000)}, "end_time": {"min": random.randint(0, 10000), "max": random.randint(10001, 20000)}, # "data_set": [_generate_random_string()], "confidence": {"min": random.random(), "max": random.random()}, } res = REL_API.list(**input) assert 1 == len(mock_rel_response.calls) assert isinstance(res, RelationshipList) assert 1 == len(res) request_filter = jsgz_load(mock_rel_response.calls[0].request.body)["filter"] for key in request_filter: assert to_snake_case(key) in input.keys() assert request_filter[key] == input[to_snake_case(key)] assert mock_rel_response.calls[0].response.json()["items"] == res.dump(camel_case=True)
def new_type(): tp = COGNITE_CLIENT.types.create( Type(external_id=random_string(30), properties=[{ "propertyId": "prop", "type": "string" }])) yield tp COGNITE_CLIENT.types.delete(external_id=tp.external_id)
def test_create_and_delete(self): random_name = "test_" + random_string(10) res = COGNITE_CLIENT.iam.security_categories.create( SecurityCategory(name=random_name)) assert res.id in { s.id for s in COGNITE_CLIENT.iam.security_categories.list() } COGNITE_CLIENT.iam.security_categories.delete(res.id) assert res.id not in { s.id for s in COGNITE_CLIENT.iam.security_categories.list() }
def test_create_and_delete(self): name = "test_sa_" + random_string(10) sa = COGNITE_CLIENT.iam.service_accounts.create( ServiceAccount(name=name)) assert isinstance(sa, ServiceAccount) assert sa.id in { s.id for s in COGNITE_CLIENT.iam.service_accounts.list() } COGNITE_CLIENT.iam.service_accounts.delete(sa.id) assert sa.id not in { s.id for s in COGNITE_CLIENT.iam.service_accounts.list() }
def new_label(): tp = COGNITE_CLIENT.labels.create( Label(external_id=random_string(30), name="mandatory")) yield tp COGNITE_CLIENT.labels.delete(external_id=tp.external_id)