You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/07/30 18:35:41 UTC
[airavata-django-portal] 05/06: AIRAVATA-3491 Add
applicationInterfaceId option to createExperiment
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit 52244a9f9fab9541bdb6ca90a0b253652983a2d8
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Jul 30 14:30:25 2021 -0400
AIRAVATA-3491 Add applicationInterfaceId option to createExperiment
---
.../js/utils/ExperimentUtils.js | 15 ++++++++--
.../tests/utils/ExperimentUtils.test.js | 32 +++++++++++++++++++++-
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js b/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js
index 0088e27..be91f0a 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js
@@ -3,12 +3,17 @@ import { services } from "../index";
const createExperiment = async function ({
applicationName, // name of the application interface (usually the same as the application module)
applicationId, // the id of the application module
+ applicationInterfaceId, // the id of the application interface
computeResourceName,
experimentName,
experimentInputs,
} = {}) {
let applicationInterface = null;
- if (applicationId) {
+ if (applicationInterfaceId) {
+ applicationInterface = await loadApplicationInterfaceById(
+ applicationInterfaceId
+ );
+ } else if (applicationId) {
applicationInterface = await loadApplicationInterfaceByApplicationModuleId(
applicationId
);
@@ -17,7 +22,7 @@ const createExperiment = async function ({
applicationName
);
} else {
- throw new Error("Either applicationName or applicationId is required");
+ throw new Error("Either applicationInterfaceId or applicationId or applicationName is required");
}
const applicationModuleId = applicationInterface.applicationModuleId;
let computeResourceId = null;
@@ -90,6 +95,12 @@ const loadApplicationInterfaceByName = async function (applicationName) {
return applicationInterface;
};
+const loadApplicationInterfaceById = async function (applicationInterfaceId) {
+ return await services.ApplicationInterfaceService.retrieve({
+ lookup: applicationInterfaceId,
+ });
+};
+
const loadApplicationInterfaceByApplicationModuleId = async function (
applicationId
) {
diff --git a/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js b/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js
index 8e64229..f57e4af 100644
--- a/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js
+++ b/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js
@@ -8,6 +8,10 @@ import { createExperiment } from "../../js/utils/ExperimentUtils";
// Mock out 'index' so that RESTful service calls can be mocked
jest.mock("../../js/index");
+beforeEach(() => {
+ jest.resetAllMocks();
+});
+
test("error thrown when no applicationName given", async () => {
try {
expect.assertions(2);
@@ -15,7 +19,7 @@ test("error thrown when no applicationName given", async () => {
} catch (e) {
expect(e).toBeInstanceOf(Error);
expect(e.message).toEqual(
- "Either applicationName or applicationId is required"
+ "Either applicationInterfaceId or applicationId or applicationName is required"
);
}
});
@@ -65,6 +69,32 @@ test("verify if applicationId and applicationName are given, applicationInterfac
}
});
+test("verify if applicationInterfaceId and applicationId and applicationName are given, applicationInterface is loaded with applicationId", async () => {
+ services.ApplicationInterfaceService.retrieve.mockResolvedValue(
+ new ApplicationInterfaceDefinition({
+ applicationInterfaceId: "Foo_interface1",
+ applicationName: "Foo",
+ applicationModules: ["Foo_module1"],
+ })
+ );
+ try {
+ expect.assertions(3);
+ await createExperiment({
+ applicationInterfaceId: "Foo_interface1",
+ applicationId: "Foo_module1",
+ applicationName: "Foo",
+ });
+ } catch (e) {
+ expect(services.ApplicationModuleService.getApplicationInterface).not.toHaveBeenCalled();
+ expect(services.ApplicationInterfaceService.list).not.toHaveBeenCalled();
+ expect(
+ services.ApplicationInterfaceService.retrieve
+ ).toHaveBeenCalledWith({
+ lookup: "Foo_interface1",
+ });
+ }
+});
+
test("error thrown when no computeResourceName given", async () => {
services.ApplicationInterfaceService.list.mockResolvedValue([
new ApplicationInterfaceDefinition({