Skip to content

Commit

Permalink
added .xml, .json file types, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov committed Nov 30, 2022
1 parent 2ecd8c7 commit 0dbf236
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Visibility and ignored information fail to be loaded (MOT dataset format) (<https://github.com/opencv/cvat/pull/5270>)
- Added force logout on CVAT app start if token is missing (<https://github.com/opencv/cvat/pull/5331>)
- Missed token with using social account authentication (<https://github.com/opencv/cvat/pull/5344>)
- Uploading non-zip annotaion files (<https://github.com/opencv/cvat/pull/5386>)

### Security
- TDB
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "7.2.1",
"version": "7.2.2",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions cvat-core/src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,18 @@ export function importDataset(
if (!(typeof convMaskToPoly === 'boolean')) {
throw new ArgumentError('Option "convMaskToPoly" must be a boolean');
}
if (typeof file === 'string' && !file.toLowerCase().endsWith('.zip')) {
const allowedFileExtensions = [
'.zip', '.xml', '.json',
];
if (typeof file === 'string' && !(allowedFileExtensions.some((ext) => file.toLowerCase().endsWith(ext)))) {
throw new ArgumentError('File must be file instance with ZIP extension');
}
if (file instanceof File && !(['application/zip', 'application/x-zip-compressed'].includes(file.type))) {
const allowedMimeTypes = [
'application/zip', 'application/x-zip-compressed',
'application/xml', 'text/xml',
'application/json',
];
if (file instanceof File && !(allowedMimeTypes.includes(file.type))) {
throw new ArgumentError('File must be file instance with ZIP extension');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -39,7 +40,7 @@ context('Export project dataset.', { browser: '!firefox' }, () => {
function checkCounTasksInXML(projectParams, expectedCount) {
cy.exportProject(projectParams);
cy.waitForDownload();
cy.unpackZipArchive(`cypress/fixtures/${projectParams.archiveCustomeName}.zip`);
cy.unpackZipArchive(`cypress/fixtures/${projectParams.archiveCustomName}.zip`);
cy.readFile('cypress/fixtures/annotations.xml').should('exist').then((xml) => {
const tasks = Cypress.$(Cypress.$.parseXML(xml)).find('task').find('name');
expect(tasks.length).to.be.eq(expectedCount);
Expand Down Expand Up @@ -120,7 +121,7 @@ context('Export project dataset.', { browser: '!firefox' }, () => {
as: 'exportAnnotationsRenameArchive',
type: 'annotations',
dumpType: 'CVAT for images',
archiveCustomeName: 'export_project_annotation',
archiveCustomName: 'export_project_annotation',
};
// Check issue 3810
checkCounTasksInXML(exportAnnotationsRenameArchive, 2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -86,7 +87,7 @@ context('Export project dataset with 3D task.', { browser: '!firefox' }, () => {
as: 'exportAnnotations3dRenameArchive',
type: 'annotations',
dumpType: 'Datumaro 3D',
archiveCustomeName: 'export_project_3d_annotation',
archiveCustomName: 'export_project_3d_annotation',
};
cy.exportProject(exportAnnotations3dRenameArchive);
cy.waitForDownload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -36,7 +37,7 @@ context('Dump/Upload annotation.', { browser: '!firefox' }, () => {

const exportFormat = 'CVAT for images';
let annotationArchiveName = '';
let annotationArchiveNameCustomeName = '';
let annotationArchiveNameCustomName = '';

function uploadToTask(toTaskName) {
cy.contains('.cvat-item-task-name', toTaskName)
Expand All @@ -47,8 +48,8 @@ context('Dump/Upload annotation.', { browser: '!firefox' }, () => {
cy.get('.cvat-modal-import-dataset').find('.cvat-modal-import-select').click();
cy.contains('.cvat-modal-import-dataset-option-item', exportFormat.split(' ')[0]).click();
cy.get('.cvat-modal-import-select').should('contain.text', exportFormat.split(' ')[0]);
cy.get('input[type="file"]').attachFile(annotationArchiveNameCustomeName, { subjectType: 'drag-n-drop' });
cy.get(`[title="${annotationArchiveNameCustomeName}"]`).should('be.visible');
cy.get('input[type="file"]').attachFile(annotationArchiveNameCustomName, { subjectType: 'drag-n-drop' });
cy.get(`[title="${annotationArchiveNameCustomName}"]`).should('be.visible');
cy.contains('button', 'OK').click();
}

Expand All @@ -72,12 +73,12 @@ context('Dump/Upload annotation.', { browser: '!firefox' }, () => {
as: 'exportAnnotationsRenameArchive',
type: 'annotations',
format: exportFormat,
archiveCustomeName: 'task_export_annotation_custome_name',
archiveCustomName: 'task_export_annotation_custome_name',
};
cy.exportJob(exportAnnotationRenameArchive);
cy.getDownloadFileName().then((file) => {
annotationArchiveNameCustomeName = file;
cy.verifyDownload(annotationArchiveNameCustomeName);
annotationArchiveNameCustomName = file;
cy.verifyDownload(annotationArchiveNameCustomName);
});
cy.verifyNotification();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ context('Tests for source and target storage.', () => {
const exportParams = {
type: 'annotations',
format,
archiveCustomeName: 'job_annotations',
archiveCustomName: 'job_annotations',
targetStorage: project.advancedConfiguration.targetStorage,
};
cy.exportJob(exportParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ context('Tests for source and target storage.', () => {
const exportParams = {
type: 'annotations',
format,
archiveCustomeName: 'job_annotations',
archiveCustomName: 'job_annotations',
targetStorage: project.advancedConfiguration.targetStorage,
};
cy.exportJob(exportParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ context('Import and export annotations: specify source and target storage in mod
const exportParams = {
type: 'annotations',
format,
archiveCustomeName: 'job_annotations',
archiveCustomName: 'job_annotations',
targetStorage: {
location: 'Cloud storage',
cloudStorageId: createdCloudStorageId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -41,7 +42,7 @@ context('Export task dataset.', () => {
as: 'exportDatasetRenameArchive',
type: 'dataset',
format: exportFormat,
archiveCustomeName: 'job_export_dataset_custome_name',
archiveCustomName: 'job_export_dataset_custome_name',
};
cy.exportJob(exportDataset);
cy.waitForDownload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -13,7 +14,7 @@ context('Canvas 3D functionality. Dump/upload annotation. "Point Cloud" format',
};
const dumpTypePC = 'Sly Point Cloud Format';
let annotationPCArchiveName = '';
let annotationPCArchiveCustomeName = '';
let annotationPCArchiveCustomName = '';

function confirmUpdate(modalWindowClassName) {
cy.get(modalWindowClassName).should('be.visible').within(() => {
Expand Down Expand Up @@ -63,12 +64,12 @@ context('Canvas 3D functionality. Dump/upload annotation. "Point Cloud" format',
as: 'exportAnnotationsRenameArchive',
type: 'annotations',
format: dumpTypePC,
archiveCustomeName: 'job_export_3d_annotation_custome_name_pc_format',
archiveCustomName: 'job_export_3d_annotation_custome_name_pc_format',
};
cy.exportJob(exportAnnotationRenameArchive);
cy.getDownloadFileName().then((file) => {
annotationPCArchiveCustomeName = file;
cy.verifyDownload(annotationPCArchiveCustomeName);
annotationPCArchiveCustomName = file;
cy.verifyDownload(annotationPCArchiveCustomName);
});
cy.verifyNotification();
cy.removeAnnotations();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -13,7 +14,7 @@ context('Canvas 3D functionality. Dump/upload annotation. "Velodyne Points" form
};
const dumpTypeVC = 'Kitti Raw Format';
let annotationVCArchiveName = '';
let annotationVCArchiveNameCustomeName = '';
let annotationVCArchiveNameCustomName = '';

function confirmUpdate(modalWindowClassName) {
cy.get(modalWindowClassName).should('be.visible').within(() => {
Expand Down Expand Up @@ -63,12 +64,12 @@ context('Canvas 3D functionality. Dump/upload annotation. "Velodyne Points" form
as: 'exportAnnotationsRenameArchive',
type: 'annotations',
format: dumpTypeVC,
archiveCustomeName: 'job_export_3d_annotation_custome_name_vc_format',
archiveCustomName: 'job_export_3d_annotation_custome_name_vc_format',
};
cy.exportJob(exportAnnotationRenameArchive);
cy.getDownloadFileName().then((file) => {
annotationVCArchiveNameCustomeName = file;
cy.verifyDownload(annotationVCArchiveNameCustomeName);
annotationVCArchiveNameCustomName = file;
cy.verifyDownload(annotationVCArchiveNameCustomName);
});
cy.verifyNotification();
cy.removeAnnotations();
Expand Down Expand Up @@ -101,7 +102,7 @@ context('Canvas 3D functionality. Dump/upload annotation. "Velodyne Points" form
cy.contains('Upload annotations').click();
uploadAnnotation(
dumpTypeVC.split(' ')[0],
annotationVCArchiveNameCustomeName,
annotationVCArchiveNameCustomName,
'.cvat-modal-content-load-task-annotation',
);
cy.contains('Annotations have been loaded').should('be.visible');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -50,7 +51,7 @@ context('Canvas 3D functionality. Export as a dataset.', () => {
as: 'exportDatasetVCFormatRenameArchive',
type: 'dataset',
format: dumpTypeVC,
archiveCustomeName: 'job_export_3d_dataset_custome_name_vc_format',
archiveCustomName: 'job_export_3d_dataset_custome_name_vc_format',
};
cy.exportJob(exportDatasetVCFormatRenameArchive);
cy.waitForDownload();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

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

import { taskName, labelName } from '../../support/const';

context('Upload annotations in different file formats', () => {
const issueId = '5274';
const createRectangleTrack2Points = {
points: 'By 2 Points',
type: 'Track',
labelName,
firstX: 250,
firstY: 350,
secondX: 350,
secondY: 450,
};

const archives = [
{
type: 'annotations',
format: 'CVAT for images',
archiveCustomName: 'issue5274-cvat-for-images',
annotationsPath: 'annotations.xml',
},
{
type: 'annotations',
format: 'COCO',
archiveCustomName: 'issue5274-coco',
annotationsPath: 'annotations/instances_default.json',
},
];

before(() => {
cy.openTaskJob(taskName);
cy.createRectangle(createRectangleTrack2Points);
cy.saveJob('PATCH', 200, 'saveJobDump');
for (const archive of archives) {
cy.exportJob(archive);
cy.waitForDownload();
cy.unpackZipArchive(`cypress/fixtures/${archive.archiveCustomName}.zip`, archive.archiveCustomName);
}
});

describe(`Testing issue "${issueId}"`, () => {
it('Dump annotations. Upload different file formats.', () => {
cy.removeAnnotations();
cy.intercept('GET', '/api/jobs/**/annotations?**').as('uploadAnnotationsGet');
for (const archive of archives) {
cy.interactMenu('Upload annotations');
cy.uploadAnnotations(
archive.format.split(' ')[0],
`${archive.archiveCustomName}/${archive.annotationsPath}`,
'.cvat-modal-content-load-job-annotation',
);

cy.get('.cvat-notification-notice-upload-annotations-fail').should('not.exist');
cy.get('#cvat_canvas_shape_1').should('exist');
cy.get('#cvat-objects-sidebar-state-item-1').should('exist');

cy.removeAnnotations();
}
});
});
});
5 changes: 3 additions & 2 deletions tests/cypress/plugins/unpackZipArchive/addPlugin.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

const path = require('path');
const extract = require('extract-zip');

async function unpackZipArchive(args) {
const { arhivePath } = args;
const { arhivePath, extractPath } = args;
const absolutePath = path.dirname(path.resolve(arhivePath));
await extract(arhivePath, { dir: absolutePath });
await extract(arhivePath, { dir: extractPath ? `${absolutePath}/${extractPath}/` : absolutePath });
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Cypress.Commands.add('unpackZipArchive', (arhivePath) => cy.task('unpackZipArchive', {
Cypress.Commands.add('unpackZipArchive', (arhivePath, extractPath) => cy.task('unpackZipArchive', {
arhivePath,
extractPath,
}));
Loading

0 comments on commit 0dbf236

Please sign in to comment.