Skip to content

Commit

Permalink
Progress on tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Turley <[email protected]>
  • Loading branch information
mturley committed Aug 14, 2024
1 parent e813135 commit 4c660dd
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 17 deletions.
3 changes: 2 additions & 1 deletion frontend/src/__mocks__/mockModelArtifact.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ModelArtifact } from '~/concepts/modelRegistry/types';

export const mockModelArtifact = (): ModelArtifact => ({
export const mockModelArtifact = (partial?: Partial<ModelArtifact>): ModelArtifact => ({
...partial,
createTimeSinceEpoch: '1712234877179',
id: '1',
lastUpdateTimeSinceEpoch: '1712234877179',
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/__mocks__/mockModelArtifactList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import { ModelArtifactList } from '~/concepts/modelRegistry/types';
import { mockModelArtifact } from './mockModelArtifact';

export const mockModelArtifactList = (): ModelArtifactList => ({
items: [mockModelArtifact()],
export const mockModelArtifactList = ({
items = [mockModelArtifact()],
}: Partial<ModelArtifactList>): ModelArtifactList => ({
items,
nextPageToken: '',
pageSize: 0,
size: 1,
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/__mocks__/mockModelVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type MockModelVersionType = {
labels?: string[];
state?: ModelState;
description?: string;
createTimeSinceEpoch?: string;
};

export const mockModelVersion = ({
Expand All @@ -19,9 +20,10 @@ export const mockModelVersion = ({
id = '1',
state = ModelState.LIVE,
description = 'Description of model version',
createTimeSinceEpoch = '1712234877179',
}: MockModelVersionType): ModelVersion => ({
author,
createTimeSinceEpoch: '1712234877179',
createTimeSinceEpoch,
customProperties: createModelRegistryLabelsObject(labels),
id,
lastUpdateTimeSinceEpoch: '1712234877179',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
type ModelArtifact,
} from '~/concepts/modelRegistry/types';
import { mockModelRegistryService } from '~/__mocks__/mockModelRegistryService';
import { mockRegisteredModelList } from '~/__mocks__/mockRegisteredModelsList';
import { mockModelVersionList } from '~/__mocks__/mockModelVersionList';
import { mockModelArtifactList } from '~/__mocks__/mockModelArtifactList';

const MODEL_REGISTRY_API_VERSION = 'v1alpha3';

Expand Down Expand Up @@ -51,6 +54,166 @@ const initIntercepts = () => {
]),
);

cy.interceptOdh(
`GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models`,
{
path: { serviceName: 'modelregistry-sample', apiVersion: MODEL_REGISTRY_API_VERSION },
},
mockRegisteredModelList({
items: [
mockRegisteredModel({ id: '1', name: 'Test model 1' }),
mockRegisteredModel({ id: '2', name: 'Test model 2' }),
mockRegisteredModel({ id: '3', name: 'Test model 3 has version but is missing artifact' }),
mockRegisteredModel({ id: '4', name: 'Test model 4 is missing version and artifact' }),
],
}),
);

cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
registeredModelId: 1,
},
},
mockModelVersionList({
items: [
mockModelVersion({
id: '1',
registeredModelId: '1',
name: 'Test older version for model 1',
createTimeSinceEpoch: '1712234877179', // Apr 04 2024
}),
mockModelVersion({
id: '2',
registeredModelId: '1',
name: 'Test latest version for model 1',
createTimeSinceEpoch: '1723659611927', // Aug 14 2024
}),
],
}),
);

cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
registeredModelId: 2,
},
},
mockModelVersionList({
items: [
mockModelVersion({
id: '3',
registeredModelId: '2',
name: 'Test older version for model 2',
createTimeSinceEpoch: '1712234877179', // Apr 04 2024
}),
mockModelVersion({
id: '4',
registeredModelId: '2',
name: 'Test latest version for model 2',
createTimeSinceEpoch: '1723659611927', // Aug 14 2024
}),
],
}),
);

cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
registeredModelId: 3,
},
},
mockModelVersionList({
items: [
mockModelVersion({
id: '5',
registeredModelId: '3',
name: 'Test version for model 3',
}),
],
}),
);

cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
registeredModelId: 4,
},
},
mockModelVersionList({
items: [], // Model 4 has no versions
}),
);

// Model id 1's latest version is id 2
cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/model_versions/:modelVersionId/artifacts',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
modelVersionId: 2,
},
},
mockModelArtifactList({
items: [
mockModelArtifact({
modelFormatName: 'test-version-id-2-format-name',
modelFormatVersion: 'test-version-id-2-format-version',
uri: 's3://test-bucket-version-id-2/demo-models/test-path?endpoint=test-endpoint&defaultRegion=test-region',
}),
],
}),
);

// Model id 2's latest version is id 4
cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/model_versions/:modelVersionId/artifacts',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
modelVersionId: 4,
},
},
mockModelArtifactList({
items: [
mockModelArtifact({
modelFormatName: 'test-version-id-4-format-name',
modelFormatVersion: 'test-version-id-4-format-version',
uri: 'oops-malformed-uri',
}),
],
}),
);

// Model id 3's latest version is id 5
cy.interceptOdh(
'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/model_versions/:modelVersionId/artifacts',
{
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
modelVersionId: 5,
},
},
mockModelArtifactList({
items: [], // Model 3 has no artifacts
}),
);

cy.interceptOdh(
'POST /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
{
Expand All @@ -60,7 +223,7 @@ const initIntercepts = () => {
registeredModelId: 1,
},
},
mockModelVersion({ id: '2', name: 'Test version name' }),
mockModelVersion({ id: '6', name: 'Test version name' }),
).as('createModelVersion');

cy.interceptOdh(
Expand All @@ -69,14 +232,14 @@ const initIntercepts = () => {
path: {
serviceName: 'modelregistry-sample',
apiVersion: MODEL_REGISTRY_API_VERSION,
modelVersionId: 2,
modelVersionId: 6,
},
},
mockModelArtifact(),
).as('createModelArtifact');
};

describe('Register model page', () => {
describe('Register model page with no preselected model', () => {
beforeEach(() => {
initIntercepts();
registerVersionPage.visit();
Expand Down Expand Up @@ -210,7 +373,24 @@ describe('Register model page', () => {
cy.url().should('include', '/modelRegistry/modelregistry-sample/registeredModels/1');
});

it('Preselects a model and prefills its version/artifact details when opened from the model details page', () => {
it('Prefills version/artifact details when a model is selected', () => {
// TODO select a model
// TODO assert the fields have the details in them
// TODO select a different model
// TODO assert that the fields changed
});

it('Clears prefilled details if switching to a model with missing version', () => {});

it('Clears prefilled details if switching to a model with missing artifact', () => {});
});

describe('Register model page with preselected model', () => {
beforeEach(() => {
initIntercepts();
});

it('Prefills version/artifact details for the preselected model', () => {
registerVersionPage.visit('1');
// Don't select a model, model 1 is already selected
registerVersionPage.findFormField(FormFieldSelector.VERSION_NAME).type('Test version name');
Expand All @@ -219,14 +399,10 @@ describe('Register model page', () => {
.findFormField(FormFieldSelector.LOCATION_PATH)
.type('demo-models/flan-t5-small-caikit');
registerVersionPage.findSubmitButton().should('be.enabled');

// TODO do the submission and assert the created resources and the redirect
});

it('Prefills version/artifact details when a model is selected', () => {
// TODO select a model
// TODO assert the fields have the details in them
// TODO select a different model
// TODO assert that the fields changed
});
it('Does not prefill location fields if the URI on the artifact is malformed', () => {});
it('Disables submit until required fields are filled in object storage mode', () => {});
it('Creates expected resources in object storage mode', () => {});
it('Disables submit until required fields are filled in URI mode', () => {});
it('Creates expected resources in URI mode', () => {});
});

0 comments on commit 4c660dd

Please sign in to comment.