Skip to content

Commit

Permalink
[Dependent] Cypress test. Project functionality. (#2459)
Browse files Browse the repository at this point in the history
* init server changes
  • Loading branch information
dvkruchinin authored Nov 26, 2020
1 parent cffd897 commit 75d2826
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 45 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added basic projects implementation (<https://github.com/openvinotoolkit/cvat/pull/2255>)


### Changed

- PATCH requests from cvat-core submit only changed fields (<https://github.com/openvinotoolkit/cvat/pull/2445>)
Expand Down
8 changes: 7 additions & 1 deletion tests/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
"user": "admin",
"password": "12qwaszx"
},
"testFiles": ["auth_page.js", "actions_tasks_objects/*", "actions_users/*", "remove_users_tasks.js"]
"testFiles": [
"auth_page.js",
"actions_tasks_objects/*",
"actions_users/*",
"actions_projects/*",
"remove_users_tasks_projects.js"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT

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

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 = {
firstTask: `First task for ${projectName}`,
secondTask: `Second task for ${projectName}`,
};
const attrName = `Attr for ${labelName}`;
const textDefaultValue = 'Some default value for type Text';
const imagesCount = 1;
const imageFileName = `image_${taskName.firstTask.replace(/\s+/g, '_').toLowerCase()}`;
const width = 800;
const height = 800;
const posX = 10;
const posY = 10;
const color = 'white';
const archiveName = `${imageFileName}.zip`;
const archivePath = `cypress/fixtures/${archiveName}`;
const imagesFolder = `cypress/fixtures/${imageFileName}`;
const directoryToArchive = imagesFolder;
const advancedConfigurationParams = false;
const forProject = true;
const attachToProject = {
yes: true,
no: false,
};
const multiAttrParams = false;
const newLabelName1 = `First label ${projectName}`;
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 emailAddr = `${userName}@local.local`;
const password = `${randomString(true)}`;
let projectID = '';

before(() => {
cy.openProject(projectName);
});

describe(`Testing "Base actions on the project"`, () => {
it('Add some labels to project.', () => {
cy.addNewLabel(newLabelName1);
cy.addNewLabel(newLabelName2);
cy.addNewLabel(newLabelName3);
cy.addNewLabel(newLabelName4);
});
it('Create a first task for the project. Project field is completed with proper project name and labels editor is not accessible.', () => {
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.createAnnotationTask(
taskName.firstTask,
labelName,
attrName,
textDefaultValue,
archiveName,
multiAttrParams,
advancedConfigurationParams,
forProject,
attachToProject.no,
projectName,
);
});
it('Create a second task from task list page and attach to the created project. Assign first user.', () => {
cy.goToTaskList();
cy.createAnnotationTask(
taskName.secondTask,
labelName,
attrName,
textDefaultValue,
archiveName,
multiAttrParams,
advancedConfigurationParams,
forProject,
attachToProject.yes,
projectName,
);
cy.goToProjectsList();
cy.openProject(projectName);
cy.openTask(taskName.secondTask);
cy.assignTaskToUser(Cypress.env('user'));
});
it('The task is successfully opened. No label editor on task page.', () => {
cy.goToProjectsList();
cy.openProject(projectName);
cy.getProjectID(projectName).then(($projectID) => {
projectID = $projectID;
});
cy.get('.cvat-tasks-list-item').then((countTasks) => {
// The number of created tasks is greater than zero
expect(countTasks.length).to.be.gt(0);
});
cy.openTask(taskName.firstTask);
cy.get('.cvat-constructor-viewer').should('not.exist');
});
it('Logout first user, register second user, logout.', () => {
cy.logout();
cy.goToRegisterPage();
cy.userRegistration(firstName, lastName, userName, emailAddr, password);
cy.logout(userName);
});
it('Login first user. Assing project to second user. Logout.', () => {
cy.login();
cy.goToProjectsList();
cy.openProject(projectName);
cy.assignProjectToUser(userName);
cy.logout();
});
it('Login second user. The project and first tasks available for that user. Logout.', () => {
cy.login(userName, password);
cy.goToProjectsList();
cy.openProject(projectName);
cy.goToTaskList();
cy.contains('strong', taskName.secondTask).should('not.exist');
cy.openTask(taskName.firstTask);
cy.logout(userName);
});
it('Delete the project. Deleted project not exist. Checking the availability of tasks.', () => {
cy.login();
cy.goToProjectsList();
cy.deleteProject(projectName, projectID);
cy.goToTaskList();
cy.contains('strong', taskName.firstTask).should('not.exist');
cy.contains('strong', taskName.secondTask).should('not.exist');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ context('Check if parameters "startFrame", "stopFrame", "frameStep" works as exp
cy.login();
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.goToTaskList();
});

after(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ context('Create and delete a annotation task', () => {
cy.login();
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.goToTaskList();
});

describe(`Testing "${labelName}"`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ context('Register user, change password, login with new password', () => {
describe(`Testing "Case ${caseId}"`, () => {
it('Register user, change password', () => {
cy.userRegistration(firstName, lastName, userName, emailAddr, password);
cy.url().should('include', '/tasks');
cy.get('.cvat-right-header')
.find('.cvat-header-menu-dropdown')
.should('have.text', userName)
Expand All @@ -46,11 +45,9 @@ context('Register user, change password, login with new password', () => {
});
it('Logout', () => {
cy.logout(userName);
cy.url().should('include', '/auth/login');
});
it('Login with the new password', () => {
cy.login(userName, newPassword);
cy.url().should('include', '/tasks');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ context('Multiple users. Assign task, job.', () => {

after(() => {
cy.login();
cy.goToTaskList();
cy.getTaskID(taskName).then(($taskID) => {
cy.deleteTask(taskName, $taskID);
});
Expand All @@ -57,9 +56,7 @@ context('Multiple users. Assign task, job.', () => {
secondUser.emailAddr,
secondUser.password,
);
cy.url().should('include', '/tasks');
cy.logout(secondUserName);
cy.url().should('include', '/auth/login');
});
it('Register third user and logout.', () => {
cy.get('a[href="/auth/register"]').click();
Expand All @@ -71,14 +68,10 @@ context('Multiple users. Assign task, job.', () => {
thirdUser.emailAddr,
thirdUser.password,
);
cy.url().should('include', '/tasks');
cy.logout(thirdUserName);
cy.url().should('include', '/auth/login');
});
it('First user login and create a task', () => {
cy.login();
cy.url().should('include', '/tasks');
cy.goToTaskList();
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, labelName, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.createAnnotationTask(taskName, labelName, attrName, textDefaultValue, archiveName);
Expand All @@ -93,23 +86,17 @@ context('Multiple users. Assign task, job.', () => {
});
it('Second user login. The task can be opened. Logout', () => {
cy.login(secondUserName, secondUser.password);
cy.url().should('include', '/tasks');
cy.goToTaskList();
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.url().should('include', '/tasks');
cy.goToTaskList();
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.url().should('include', '/tasks');
cy.goToTaskList();
cy.openTask(taskName);
cy.get('.cvat-task-job-list').within(() => {
cy.get('.cvat-user-search-field').click({ force: true });
Expand All @@ -119,8 +106,6 @@ context('Multiple users. Assign task, job.', () => {
});
it('Third user login. The task can be opened.', () => {
cy.login(thirdUserName, thirdUser.password);
cy.url().should('include', '/tasks');
cy.goToTaskList();
cy.contains('strong', taskName).should('exist');
cy.openTask(taskName);
cy.logout(thirdUserName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ context('When clicking on the Logout button, get the user session closed.', () =
describe(`Testing issue "${issueId}"`, () => {
it('Login', () => {
cy.login();
cy.url().should('include', '/tasks');
});
it('Logout', () => {
cy.logout();
cy.url().should('include', '/auth/login');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@ describe('Delete users and tasks created during the test run.', () => {
}
});
});
it('Get a list of projects and delete them all', () => {
cy.request({
url: '/api/v1/projects?page_size=all',
headers: {
Authorization: `Token ${authKey}`,
},
}).then(async (responce) => {
const responceResult = await responce['body']['results'];
for (let tasks of responceResult) {
let taskId = tasks['id'];
cy.request({
method: 'DELETE',
url: `/api/v1/projects/${taskId}`,
headers: {
Authorization: `Token ${authKey}`,
},
});
}
});
});
});
Loading

0 comments on commit 75d2826

Please sign in to comment.