Skip to content

Commit 36687c2

Browse files
Merge pull request #481 from CedricProfessionnel/AwsUtilities
Cypress command for aws utilities (Feature Aws Part)
2 parents 468ccd6 + 78fa161 commit 36687c2

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import datasetManagerCognito from "udt-dataset-managers/dist/CognitoDatasetManager"
2+
import mime from "mime-types"
3+
const command = () => {
4+
Cypress.Commands.add("addAssetToAwsProject", (nameProject, nameAsset) => {
5+
var credentials = Cypress.env()
6+
cy.log("Add test files : " + nameAsset)
7+
cy.fixture("assets-dummies/" + nameAsset, "base64").then(
8+
{ timeout: 100000 },
9+
async (asset) => {
10+
var blob
11+
if (nameAsset.match(".*\\.json")) {
12+
blob = asset
13+
} else {
14+
blob = await Cypress.Blob.base64StringToBlob(
15+
asset,
16+
mime.lookup(nameAsset)
17+
)
18+
}
19+
const authConfig = {
20+
Auth: {
21+
identityPoolId: credentials.AWS_IDENTITY_POOL_ID,
22+
region: credentials.AWS_AUTH_REGION,
23+
userPoolId: credentials.AWS_USER_POOL_ID,
24+
userPoolWebClientId: credentials.AWS_USER_POOL_WEB_CLIENT_ID,
25+
mandatorySignIn: credentials.AWS_MANDATORY_SIGN_IN,
26+
authenticationFlowType: credentials.AWS_AUTHENTICATION_FLOW_TYPE,
27+
},
28+
Storage: {
29+
AWSS3: {
30+
bucket: credentials.AWS_STORAGE_BUCKET,
31+
region: credentials.AWS_STORAGE_REGION,
32+
},
33+
},
34+
}
35+
const ds = await new datasetManagerCognito({ authConfig })
36+
ds.setProject(nameProject)
37+
await ds.addAsset(nameAsset, blob)
38+
}
39+
)
40+
})
41+
}
42+
export default command
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import datasetManagerCognito from "udt-dataset-managers/dist/CognitoDatasetManager"
2+
const command = () => {
3+
Cypress.Commands.add("addProjectToAws", (nameDummies) => {
4+
var credentials = Cypress.env()
5+
cy.log("Add test files : " + nameDummies)
6+
cy.fixture("samples-dummies/" + nameDummies).then(
7+
{ timeout: 100000 },
8+
async (dummies) => {
9+
const authConfig = {
10+
Auth: {
11+
identityPoolId: credentials.AWS_IDENTITY_POOL_ID,
12+
region: credentials.AWS_AUTH_REGION,
13+
userPoolId: credentials.AWS_USER_POOL_ID,
14+
userPoolWebClientId: credentials.AWS_USER_POOL_WEB_CLIENT_ID,
15+
mandatorySignIn: credentials.AWS_MANDATORY_SIGN_IN,
16+
authenticationFlowType: credentials.AWS_AUTHENTICATION_FLOW_TYPE,
17+
},
18+
Storage: {
19+
AWSS3: {
20+
bucket: credentials.AWS_STORAGE_BUCKET,
21+
region: credentials.AWS_STORAGE_REGION,
22+
},
23+
},
24+
}
25+
const ds = await new datasetManagerCognito({ authConfig })
26+
await ds.setDataset(dummies)
27+
}
28+
)
29+
})
30+
}
31+
export default command
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import commandRemoveAwsProject from "./remove-aws-project"
2+
const command = () => {
3+
commandRemoveAwsProject()
4+
Cypress.Commands.add("cleanAws", () => {
5+
cy.log("Start cleaning aws")
6+
cy.removeAwsProject("Not Supported")
7+
cy.removeAwsProject("Image Classification")
8+
cy.removeAwsProject("Image Segmentation")
9+
cy.removeAwsProject("Time Series")
10+
cy.removeAwsProject("Time Series 2")
11+
cy.removeAwsProject("Data Entry")
12+
cy.removeAwsProject("Text Classification")
13+
cy.removeAwsProject("Video Segmentation")
14+
cy.removeAwsProject("Audio Transcription")
15+
cy.removeAwsProject("Empty")
16+
cy.removeAwsProject("Rename Test")
17+
cy.removeAwsProject("CypressTestExportAnnotationOnlyTime")
18+
cy.removeAwsProject("CypressTestExportAnnotationOnlyImage")
19+
cy.removeAwsProject("CypressTestExportAnnotationOnlyVideo")
20+
cy.removeAwsProject("CypressTestExportAnnotationOnlyPDF")
21+
cy.removeAwsProject("CypressTestExportAnnotationOnlyAudio")
22+
cy.removeAwsProject("CypressTestExportAnnotationOnlyText")
23+
cy.removeAwsProject("CypressTestExportAssetsTime")
24+
cy.removeAwsProject("CypressTestExportAssetsTime2")
25+
cy.removeAwsProject("CypressTestExportAssetsImage")
26+
cy.removeAwsProject("CypressTestExportAssetsVideo")
27+
cy.removeAwsProject("CypressTestExportAssetsPDF")
28+
cy.removeAwsProject("CypressTestExportAssetsAudio")
29+
cy.removeAwsProject("CypressTestExportAssetsText")
30+
cy.log("End cleaning aws")
31+
})
32+
}
33+
export default command
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import Amplify, { Auth } from "aws-amplify"
2+
3+
const command = () => {
4+
Cypress.Commands.add("createCredentialsAws", () => {
5+
cy.then({ timeout: 10000 }, async () => {
6+
const app_config = {
7+
"auth.cognito.identityPoolId": Cypress.env().AWS_IDENTITY_POOL_ID,
8+
"auth.cognito.region": Cypress.env().AWS_AUTH_REGION,
9+
"auth.cognito.userPoolId": Cypress.env().AWS_USER_POOL_ID,
10+
"auth.cognito.userPoolWebClientId": Cypress.env()
11+
.AWS_USER_POOL_WEB_CLIENT_ID,
12+
"auth.cognito.storage.awsS3.bucket": Cypress.env().AWS_STORAGE_BUCKET,
13+
"auth.cognito.storage.awsS3.region": Cypress.env().AWS_STORAGE_REGION,
14+
"auth.cognito.password.minimumLength": Cypress.env()
15+
.COGNITO_USER_PASS_LENGTH,
16+
"auth.cognito.password.requireLowercase":
17+
Cypress.env().COGNITO_USER_PASS_REQUIRE_LOWERCASE === "TRUE"
18+
? true
19+
: false,
20+
"auth.cognito.password.requireUppercase":
21+
Cypress.env().COGNITO_USER_PASS_REQUIRE_UPPERCASE === "TRUE"
22+
? true
23+
: false,
24+
"auth.cognito.password.requireNumbers":
25+
Cypress.env().COGNITO_USER_PASS_REQUIRE_NUMBER === "TRUE"
26+
? true
27+
: false,
28+
"auth.cognito.password.requireSymbols":
29+
Cypress.env().COGNITO_USER_PASS_REQUIRE_SYMBOL === "TRUE"
30+
? true
31+
: false,
32+
"auth.provider": "cognito",
33+
provider: "cognito",
34+
}
35+
const json = {
36+
Auth: {
37+
identityPoolId: Cypress.env().AWS_IDENTITY_POOL_ID,
38+
region: Cypress.env().AWS_AUTH_REGION,
39+
userPoolId: Cypress.env().AWS_USER_POOL_ID,
40+
userPoolWebClientId: Cypress.env().AWS_USER_POOL_WEB_CLIENT_ID,
41+
mandatorySignIn: true,
42+
authenticationFlowType: "USER_PASSWORD_AUTH",
43+
minimumLength: Cypress.env().COGNITO_USER_PASS_LENGTH,
44+
requireNumbers:
45+
Cypress.env().COGNITO_USER_PASS_REQUIRE_NUMBER === "TRUE"
46+
? true
47+
: false,
48+
requireSymbols:
49+
Cypress.env().COGNITO_USER_PASS_REQUIRE_SYMBOL === "TRUE"
50+
? true
51+
: false,
52+
requireUppercase:
53+
Cypress.env().COGNITO_USER_PASS_REQUIRE_UPPERCASE === "TRUE"
54+
? true
55+
: false,
56+
requireLowercase:
57+
Cypress.env().COGNITO_USER_PASS_REQUIRE_LOWERCASE === "TRUE"
58+
? true
59+
: false,
60+
},
61+
Storage: {
62+
AWSS3: {
63+
bucket: Cypress.env().AWS_STORAGE_BUCKET,
64+
region: Cypress.env().AWS_STORAGE_REGION,
65+
},
66+
},
67+
}
68+
localStorage.setItem("app_config", JSON.stringify(app_config))
69+
Amplify.configure(json)
70+
await Auth.signIn(
71+
Cypress.env().COGNITO_USER_NAME,
72+
Cypress.env().COGNITO_USER_PASS
73+
)
74+
})
75+
cy.reload()
76+
})
77+
}
78+
export default command
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import datasetManagerCognito from "udt-dataset-managers/dist/CognitoDatasetManager"
2+
3+
const command = () => {
4+
Cypress.Commands.add("removeAwsProject", async (name) => {
5+
var credentials = Cypress.env()
6+
const authConfig = {
7+
Auth: {
8+
identityPoolId: credentials.AWS_IDENTITY_POOL_ID,
9+
region: credentials.AWS_AUTH_REGION,
10+
userPoolId: credentials.AWS_USER_POOL_ID,
11+
userPoolWebClientId: credentials.AWS_USER_POOL_WEB_CLIENT_ID,
12+
mandatorySignIn: credentials.AWS_MANDATORY_SIGN_IN,
13+
authenticationFlowType: credentials.AWS_AUTHENTICATION_FLOW_TYPE,
14+
},
15+
Storage: {
16+
AWSS3: {
17+
bucket: credentials.AWS_STORAGE_BUCKET,
18+
region: credentials.AWS_STORAGE_REGION,
19+
},
20+
},
21+
}
22+
const ds = await new datasetManagerCognito({ authConfig })
23+
await ds.removeProject(name)
24+
})
25+
}
26+
export default command
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import commandAddAssetToAwsProject from "./add-asset-to-aws-project"
2+
import commandAddProjectToAws from "./add-project-to-aws"
3+
const command = () => {
4+
commandAddAssetToAwsProject()
5+
commandAddProjectToAws()
6+
Cypress.Commands.add("setUpAws", () => {
7+
cy.addProjectToAws("ImageClassification.json")
8+
cy.addProjectToAws("Empty.json")
9+
cy.addProjectToAws("AudioTranscription.json")
10+
cy.addProjectToAws("VideoSegmentation.json")
11+
cy.addProjectToAws("TextClassification.json")
12+
cy.addProjectToAws("TimeSeriesTimeData.json")
13+
cy.addProjectToAws("TimeSeriesAudioUrl.json")
14+
cy.addProjectToAws("DataEntry.json")
15+
cy.addProjectToAws("NotSupported.json")
16+
cy.addAssetToAwsProject("Image Classification", "image1.jpg")
17+
cy.addAssetToAwsProject("Image Classification", "image2.jpg")
18+
cy.addAssetToAwsProject("Audio Transcription", "audio.mp3")
19+
cy.addAssetToAwsProject("Video Segmentation", "video.mp4")
20+
cy.addAssetToAwsProject("Data Entry", "pdf1.pdf")
21+
cy.addAssetToAwsProject("Data Entry", "pdf2.pdf")
22+
cy.addAssetToAwsProject("Text Classification", "text1.txt")
23+
cy.addAssetToAwsProject("Text Classification", "text2.txt")
24+
cy.addAssetToAwsProject("Text Classification", "text3.txt")
25+
cy.addAssetToAwsProject("Time Series", "audio.mp3")
26+
cy.addAssetToAwsProject("Time Series 2", "timeSeries.json")
27+
})
28+
}
29+
export default command

0 commit comments

Comments
 (0)