Skip to content

Commit

Permalink
[ML] tests for model stats
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jul 8, 2021
1 parent 8572f7b commit 4771092
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';
import { USER } from '../../../../functional/services/ml/security_common';
import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api';
import expect from '../../../../../../../../../../private/var/tmp/_bazel_darnautov/1afe62330ff0d9ae1ca2013aad33fd76/execroot/kibana/bazel-out/darwin-fastbuild/bin/packages/kbn-expect';

export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertestWithoutAuth');
const ml = getService('ml');

describe('GET trained_models/_stats', () => {
before(async () => {
await ml.testResources.setKibanaTimeZoneToUTC();
await ml.api.createdTestTrainedModels('regression', 2);
});

after(async () => {
await ml.api.cleanMlIndices();
});

it('returns trained model stats by id', async () => {
const { body } = await supertest
.get(`/api/ml/trained_models/dfa_regression_model_n_0/_stats`)
.auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER))
.set(COMMON_REQUEST_HEADERS)
.expect(200);

expect(body.count).to.eql(1);
expect(body.trained_model_stats[0].model_id).to.eql('dfa_regression_model_n_0');
});

it('return an error for unauthorized user', async () => {
await supertest
.get(`/api/ml/trained_models/dfa_regression_model_n_0/_stats`)
.auth(USER.ML_UNAUTHORIZED, ml.securityCommon.getPasswordForUser(USER.ML_UNAUTHORIZED))
.set(COMMON_REQUEST_HEADERS)
.expect(403);
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('trained models', function () {
loadTestFile(require.resolve('./get_models'));
loadTestFile(require.resolve('./get_model_stats'));
});
}

0 comments on commit 4771092

Please sign in to comment.