Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test code for cli upload function #986

Merged
merged 4 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions utils/cli/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def tasks_upload(self, task_id, fileformat, filename, **kwargs):
if response.status_code == 201:
break

log.info('Upload job for Task ID {} \
with annotation file {} finished'.format(task_id, filename))
logger_string = "Upload job for Task ID {} ".format(task_id) +\
"with annotation file {} finished".format(filename)
log.info(logger_string)


class CVAT_API_V1():
Expand Down
62 changes: 61 additions & 1 deletion utils/cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework.test import APITestCase, RequestsClient
from cvat.apps.engine.tests.test_rest_api import create_db_users
from cvat.apps.engine.tests.test_rest_api import generate_image_file
from PIL import Image


class TestCLI(APITestCase):
Expand All @@ -22,7 +23,7 @@ def setUp(self, mock_stdout):
self.cli = CLI(self.client, self.api)
self.taskname = 'test_task'
self.cli.tasks_create(self.taskname,
[],
[{'name' : 'car'}, {'name': 'person'}],
'',
ResourceType.LOCAL,
[self.img_file])
Expand Down Expand Up @@ -69,3 +70,62 @@ def test_tasks_frame(self):
self.cli.tasks_frame(1, [0], outdir=settings.SHARE_ROOT)
self.assertTrue(os.path.exists(path))
os.remove(path)

def test_tasks_upload(self):
test_image = Image.open(self.img_file)
width, height = test_image.size

# Using generate_coco_anno() from:
# https://github.com/opencv/cvat/blob/develop/cvat/apps/engine/tests/test_rest_api.py
def generate_coco_anno():
return b"""{
"categories": [
{
"id": 1,
"name": "car",
"supercategory": ""
},
{
"id": 2,
"name": "person",
"supercategory": ""
}
],
"images": [
{
"coco_url": "",
"date_captured": "",
"flickr_url": "",
"license": 0,
"id": 0,
"file_name": "test_cli.jpg",
"height": %d,
"width": %d
}
],
"annotations": [
{
"category_id": 1,
"id": 1,
"image_id": 0,
"iscrowd": 0,
"segmentation": [
[]
],
"area": 17702.0,
"bbox": [
574.0,
407.0,
167.0,
106.0
]
}
]
}"""
content = generate_coco_anno() % (height, width)
path = os.path.join(settings.SHARE_ROOT, 'test_cli.json')
with open(path, "wb") as coco:
coco.write(content)
self.cli.tasks_upload(1, 'COCO JSON 1.0', path)
self.assertRegex(self.mock_stdout.getvalue(), '.*{}.*'.format("annotation file"))
os.remove(path)