From 86eef84717fc901a1910a0c0290758b774835164 Mon Sep 17 00:00:00 2001 From: Dmitry Kruchinin <33020454+dvkruchinin@users.noreply.github.com> Date: Fri, 12 Mar 2021 15:56:45 +0300 Subject: [PATCH] Rework Cypress test "Register user, change password, login with new password". (#2933) * Rework Cypress test "case 2". * Add command to deleting a registered users. * Tests adaptation. * Update cypress command * Test adaptation * Apply comments. --- .../base_actions_project_task_user.js | 24 +++++------- .../case_39_issue_2572_rename_task.js | 1 + .../case_28_review_pipeline_feature.js | 2 + .../case_2_register_user_change_pass.js | 31 ++++++++-------- .../case_4_assign_taks_job_users.js | 1 + .../issue_1599_ch_user_registration.js | 7 +++- .../issue_1599_pl_user_registration.js | 7 +++- tests/cypress/support/commands.js | 37 +++++++++++++++++++ 8 files changed, 78 insertions(+), 32 deletions(-) diff --git a/tests/cypress/integration/actions_projects/registration_involved/base_actions_project_task_user.js b/tests/cypress/integration/actions_projects/registration_involved/base_actions_project_task_user.js index 847da80d..6d93a0f6 100644 --- a/tests/cypress/integration/actions_projects/registration_involved/base_actions_project_task_user.js +++ b/tests/cypress/integration/actions_projects/registration_involved/base_actions_project_task_user.js @@ -6,15 +6,6 @@ import { projectName } from '../../../support/const_project'; -const randomString = (isPassword) => { - let result = ''; - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - for (let i = 0; i <= 8; i++) { - result += characters.charAt(Math.floor(Math.random() * characters.length)); - } - return isPassword ? `${result}${Math.floor(Math.random() * 10)}` : result; -}; - context('Base actions on the project', () => { const labelName = `Base label for ${projectName}`; const taskName = { @@ -45,11 +36,11 @@ context('Base actions on the project', () => { const newLabelName2 = `Second label ${projectName}`; const newLabelName3 = `Third label ${projectName}`; const newLabelName4 = `Fourth label ${projectName}`; - const firstName = `${randomString()}`; - const lastName = `${randomString()}`; - const userName = `${randomString()}`; + const firstName = 'Seconduser fm'; + const lastName = 'Seconduser lm'; + const userName = 'Seconduser'; const emailAddr = `${userName}@local.local`; - const password = `${randomString(true)}`; + const password = 'GDrb41RguF!'; let projectID = ''; function getProjectID(projectName) { @@ -65,6 +56,10 @@ context('Base actions on the project', () => { cy.openProject(projectName); }); + after(() => { + cy.deletingRegisteredUsers([userName]); + }); + describe(`Testing "Base actions on the project"`, () => { it('Add some labels to project.', () => { cy.addNewLabel(newLabelName1); @@ -125,7 +120,7 @@ context('Base actions on the project', () => { cy.userRegistration(firstName, lastName, userName, emailAddr, password); cy.goToProjectsList(); // tries to create project - const failProjectName = `${randomString()}`; + const failProjectName = 'failProject'; cy.createProjects(failProjectName, labelName, attrName, textDefaultValue, null, 'fail'); cy.closeNotification('.cvat-notification-notice-create-project-failed'); cy.goToProjectsList(); @@ -159,6 +154,7 @@ context('Base actions on the project', () => { cy.goToTaskList(); cy.contains('strong', taskName.firstTask).should('not.exist'); cy.contains('strong', taskName.secondTask).should('not.exist'); + cy.logout(); }); }); }); diff --git a/tests/cypress/integration/actions_tasks_objects/registration_involved/case_39_issue_2572_rename_task.js b/tests/cypress/integration/actions_tasks_objects/registration_involved/case_39_issue_2572_rename_task.js index f8875499..289ebf44 100644 --- a/tests/cypress/integration/actions_tasks_objects/registration_involved/case_39_issue_2572_rename_task.js +++ b/tests/cypress/integration/actions_tasks_objects/registration_involved/case_39_issue_2572_rename_task.js @@ -47,6 +47,7 @@ context('Rename a task.', () => { }); after(() => { + cy.deletingRegisteredUsers([secondUserName]); cy.login(); cy.deleteTask(newNaskName); }); diff --git a/tests/cypress/integration/actions_users/registration_involved/case_28_review_pipeline_feature.js b/tests/cypress/integration/actions_users/registration_involved/case_28_review_pipeline_feature.js index 29c6c554..1c2242bd 100644 --- a/tests/cypress/integration/actions_users/registration_involved/case_28_review_pipeline_feature.js +++ b/tests/cypress/integration/actions_users/registration_involved/case_28_review_pipeline_feature.js @@ -130,6 +130,8 @@ context('Review pipeline feature', () => { after(() => { cy.goToTaskList(); cy.deleteTask(taskName); + cy.logout(); + cy.deletingRegisteredUsers([secondUserName, thirdUserName]); }); describe(`Testing "${labelName}"`, () => { diff --git a/tests/cypress/integration/actions_users/registration_involved/case_2_register_user_change_pass.js b/tests/cypress/integration/actions_users/registration_involved/case_2_register_user_change_pass.js index adf65255..609755a9 100644 --- a/tests/cypress/integration/actions_users/registration_involved/case_2_register_user_change_pass.js +++ b/tests/cypress/integration/actions_users/registration_involved/case_2_register_user_change_pass.js @@ -1,26 +1,19 @@ -// Copyright (C) 2020 Intel Corporation +// Copyright (C) 2020-2021 Intel Corporation // // SPDX-License-Identifier: MIT /// -const randomString = (isPassword) => { - let result = ''; - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - for (let i = 0; i <= 8; i++) { - result += characters.charAt(Math.floor(Math.random() * characters.length)); - } - return isPassword ? `${result}${Math.floor(Math.random() * 10)}` : result; -}; - context('Register user, change password, login with new password', () => { const caseId = '2'; - const firstName = `${randomString()}`; - const lastName = `${randomString()}`; - const userName = `${randomString()}`; + const firstName = 'SecuserfmCaseTwo'; + const lastName = 'SecuserlmCaseTwo'; + const userName = 'SecuserCase2'; const emailAddr = `${userName}@local.local`; - const password = `${randomString(true)}`; - const newPassword = `${randomString(true)}`; + const password = 'GDrb41RguF!'; + const incorrectCurrentPassword = 'gDrb41RguF!'; + const newPassword = 'bYdOk8#eEd'; + const secondNewPassword = 'ndTh48@yVY'; function changePassword(userName, password, newPassword) { cy.get('.cvat-right-header') @@ -41,6 +34,12 @@ context('Register user, change password, login with new password', () => { cy.url().should('include', '/auth/register'); }); + after(() => { + cy.get('.cvat-modal-change-password').find('[aria-label="Close"]').click(); + cy.logout(userName); + cy.deletingRegisteredUsers([userName]); + }); + describe(`Testing "Case ${caseId}"`, () => { it('Register user, change password', () => { cy.userRegistration(firstName, lastName, userName, emailAddr, password); @@ -55,7 +54,7 @@ context('Register user, change password, login with new password', () => { cy.login(userName, newPassword); }); it('Change password with incorrect current password', () => { - changePassword(userName, `${randomString(true)}`, newPassword); + changePassword(userName, incorrectCurrentPassword, secondNewPassword); cy.get('.cvat-notification-notice-change-password-failed').should('exist'); }); }); diff --git a/tests/cypress/integration/actions_users/registration_involved/case_4_assign_taks_job_users.js b/tests/cypress/integration/actions_users/registration_involved/case_4_assign_taks_job_users.js index e2be6d57..be9e5acf 100644 --- a/tests/cypress/integration/actions_users/registration_involved/case_4_assign_taks_job_users.js +++ b/tests/cypress/integration/actions_users/registration_involved/case_4_assign_taks_job_users.js @@ -43,6 +43,7 @@ context('Multiple users. Assign task, job.', () => { }); after(() => { + cy.deletingRegisteredUsers([secondUserName, thirdUserName]); cy.login(); cy.deleteTask(taskName); }); diff --git a/tests/cypress/integration/actions_users/registration_involved/issue_1599_ch_user_registration.js b/tests/cypress/integration/actions_users/registration_involved/issue_1599_ch_user_registration.js index bbcb5db7..37842cee 100644 --- a/tests/cypress/integration/actions_users/registration_involved/issue_1599_ch_user_registration.js +++ b/tests/cypress/integration/actions_users/registration_involved/issue_1599_ch_user_registration.js @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Intel Corporation +// Copyright (C) 2020-2021 Intel Corporation // // SPDX-License-Identifier: MIT @@ -16,6 +16,11 @@ context('Issue 1599 (Chinese alphabet).', () => { cy.url().should('include', '/auth/register'); }); + after(() => { + cy.logout(userName); + cy.deletingRegisteredUsers([userName]); + }); + describe('User registration using the Chinese alphabet.', () => { it('Filling in the placeholder "First name"', () => { cy.get('[placeholder="First name"]').type(firstName).should('not.have.class', 'has-error'); diff --git a/tests/cypress/integration/actions_users/registration_involved/issue_1599_pl_user_registration.js b/tests/cypress/integration/actions_users/registration_involved/issue_1599_pl_user_registration.js index 2ee411d9..e0605bf9 100644 --- a/tests/cypress/integration/actions_users/registration_involved/issue_1599_pl_user_registration.js +++ b/tests/cypress/integration/actions_users/registration_involved/issue_1599_pl_user_registration.js @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Intel Corporation +// Copyright (C) 2020-2021 Intel Corporation // // SPDX-License-Identifier: MIT @@ -16,6 +16,11 @@ context('Issue 1599 (Polish alphabet).', () => { cy.url().should('include', '/auth/register'); }); + after(() => { + cy.logout(userName); + cy.deletingRegisteredUsers([userName]); + }); + describe('User registration using the Polish alphabet.', () => { it('Filling in the placeholder "First name"', () => { cy.get('[placeholder="First name"]').type(firstName).should('not.have.class', 'has-error'); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 0d73528e..ae179d1a 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -41,6 +41,43 @@ Cypress.Commands.add('userRegistration', (firstName, lastName, userName, emailAd } }); +Cypress.Commands.add('deletingRegisteredUsers', (accountToDelete) => { + cy.request({ + method: 'POST', + url: '/api/v1/auth/login', + body: { + username: Cypress.env('user'), + email: Cypress.env('email'), + password: Cypress.env('password'), + }, + }).then((responce) => { + const authKey = responce['body']['key']; + cy.request({ + url: '/api/v1/users?page_size=all', + headers: { + Authorization: `Token ${authKey}`, + }, + }).then((responce) => { + const responceResult = responce['body']['results']; + for (const user of responceResult) { + const userId = user['id']; + const userName = user['username']; + for (const account of accountToDelete) { + if (userName === account) { + cy.request({ + method: 'DELETE', + url: `/api/v1/users/${userId}`, + headers: { + Authorization: `Token ${authKey}`, + }, + }); + } + } + } + }); + }); +}); + Cypress.Commands.add( 'createAnnotationTask', (