Skip to content

Commit

Permalink
Cypress test. Update "Multiple users. Assign task, job." (cvat-ai#3347)
Browse files Browse the repository at this point in the history
* Added cypress commands

* Updated cypress test case 4 for check issue 3339

* Apply comments. Some rework cypress commands.
  • Loading branch information
dvkruchinin authored Jun 30, 2021
1 parent 961bc58 commit 3e93f95
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// <reference types="cypress" />

context('Multiple users. Assign task, job.', () => {
context('Multiple users. Assign task, job. Deactivating users.', () => {
const caseId = '4';
const labelName = `Case ${caseId}`;
const taskName = `New annotation task for ${labelName}`;
Expand Down Expand Up @@ -37,12 +37,29 @@ context('Multiple users. Assign task, job.', () => {
password: 'Fv5Df3#f55g',
};

let authKey;
const isStaff = false;
const isSuperuser = false;
const isActive = false;

function changeCheckUserStatusOpenTask(userName) {
cy.changeUserActiveStatus(authKey, userName, isActive);
cy.checkUserStatuses(authKey, userName, isStaff, isSuperuser, isActive);
cy.intercept('GET', `/api/v1/users*${thirdUserName}*`).as('users');
cy.openTask(taskName);
cy.wait('@users');
cy.get('.cvat-global-boundary').should('not.exist');
cy.contains('.cvat-task-details-task-name', taskName).should('exist');
}


before(() => {
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
});

after(() => {
cy.logout();
cy.deletingRegisteredUsers([secondUserName, thirdUserName]);
cy.login();
cy.deleteTask(taskName);
Expand Down Expand Up @@ -77,6 +94,7 @@ context('Multiple users. Assign task, job.', () => {
cy.contains('.cvat-item-task-name', `${taskName}`).should('not.exist');
cy.logout(secondUserName);
});

it('Register third user and logout.', () => {
cy.get('a[href="/auth/register"]').click();
cy.url().should('include', '/auth/register');
Expand All @@ -89,11 +107,13 @@ context('Multiple users. Assign task, job.', () => {
);
cy.logout(thirdUserName);
});

it('First user login, create a task and logout', () => {
cy.login();
cy.createAnnotationTask(taskName, labelName, attrName, textDefaultValue, archiveName);
cy.logout();
});

it('Second user login, tries to add label and logout', () => {
cy.login(secondUserName, secondUser.password);
cy.openTask(taskName);
Expand All @@ -102,29 +122,34 @@ context('Multiple users. Assign task, job.', () => {
cy.contains('.cvat-constructor-viewer-item', 'failAddLabel').should('not.exist');
cy.logout(secondUserName);
});

it('Assign the task to the second user and logout', () => {
cy.login();
cy.openTask(taskName);
cy.assignTaskToUser(secondUserName);
cy.logout();
});

it('Second user login. The task can be opened. Logout', () => {
cy.login(secondUserName, secondUser.password);
cy.contains('strong', taskName).should('exist');
cy.openTask(taskName);
cy.logout(secondUserName);
});

it('Third user login. The task not exist. Logout', () => {
cy.login(thirdUserName, thirdUser.password);
cy.contains('strong', taskName).should('not.exist');
cy.logout(thirdUserName);
});

it('First user login and assign the job to the third user. Logout', () => {
cy.login();
cy.openTask(taskName);
cy.assignJobToUser(0, thirdUserName);
cy.logout();
});

it('Third user login. Tries to delete task. The task can be opened.', () => {
cy.login(thirdUserName, thirdUser.password);
cy.contains('strong', taskName).should('exist');
Expand All @@ -133,5 +158,23 @@ context('Multiple users. Assign task, job.', () => {
cy.openTask(taskName);
cy.logout(thirdUserName);
});

it('First user login. Getting authKey.', () => {
cy.visit('/');
cy.intercept('POST', '/api/v1/auth/login').as('login');
cy.login();
cy.wait('@login').then((response) => {
authKey = response['response']['body']['key'];
});
});

it('Deactivate the second user (task assigned). Trying to open the task. Should be succefull.', () => {
changeCheckUserStatusOpenTask(secondUserName);
cy.goToTaskList();
});

it('Deactivate the third user (job assigned). Trying to open the task. Should be succefull.', () => {
changeCheckUserStatusOpenTask(thirdUserName);
});
});
});
46 changes: 46 additions & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ Cypress.Commands.add('deletingRegisteredUsers', (accountToDelete) => {
});
});

Cypress.Commands.add('changeUserActiveStatus', (authKey, accountsToChangeActiveStatus, isActive) => {
cy.request({
url: '/api/v1/users?page_size=all',
headers: {
Authorization: `Token ${authKey}`,
},
}).then((response) => {
const responceResult = response['body']['results'];
responceResult.forEach((user) => {
const userId = user['id'];
const userName = user['username'];
if (userName.includes(accountsToChangeActiveStatus)) {
cy.request({
method: 'PATCH',
url: `/api/v1/users/${userId}`,
headers: {
Authorization: `Token ${authKey}`,
},
body: {
is_active: isActive,
},
});
}
});
});
});

Cypress.Commands.add('checkUserStatuses', (authKey, userName, staffStatus, superuserStatus, activeStatus) => {
cy.request({
url: '/api/v1/users?page_size=all',
headers: {
Authorization: `Token ${authKey}`,
},
}).then((response) => {
const responceResult = response['body']['results'];
responceResult.forEach((user) => {
if (user['username'].includes(userName)) {
expect(staffStatus).to.be.equal(user['is_staff']);
expect(superuserStatus).to.be.equal(user['is_superuser']);
expect(activeStatus).to.be.equal(user['is_active']);
}

});
});
});

Cypress.Commands.add(
'createAnnotationTask',
(
Expand Down

0 comments on commit 3e93f95

Please sign in to comment.