Skip to content

Commit

Permalink
Added update tests for issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ActiveChooN committed Mar 16, 2022
1 parent 8da7121 commit 06f2dcb
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 23 deletions.
34 changes: 14 additions & 20 deletions tests/rest_api/assets/cvat_db/cvat_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 10.19
-- Dumped by pg_dump version 10.19
-- Dumped from database version 10.20
-- Dumped by pg_dump version 10.20

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -394,14 +394,14 @@ COMMENT ON SCHEMA public IS 'standard public schema';


--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
Expand Down Expand Up @@ -2921,19 +2921,6 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;

COPY public.django_session (session_key, session_data, expire_date) FROM stdin;
qje4thj4oqumlmj2fe27gae72jg4j6u8 .eJxVjDsOwjAQBe_iGll2Ev8o6TmDtetd4wCypTipEHeHSCmgfTPzXiLCtpa4dV7iTOIstBKn3xEhPbjuhO5Qb02mVtdlRrkr8qBdXhvx83K4fwcFevnWjDT6KfmRlSEHTmGyOfigKA8aR9TZgiXO3jKlwRAr61JGA2YKgZ0S7w8qsjkD:1mxDjE:ktIwpvhQwj3_BtA8Avyq5WmmpmIJD88pF_vSxFzeetA 2021-12-28 19:44:48.529173+00
ic4rcr36vkoymwaw6p322bjqlryvq2jd .eJxVjMsOwiAQRf-FtSEDFRhcuu83kBkeUjU0Ke3K-O_apAvd3nPOfYlA21rD1vMSpiQuQonT78YUH7ntIN2p3WYZ57YuE8tdkQftcpxTfl4P9--gUq_fWns0mX22NsLZDlE7INLWAzkyODjFyKwzAnExUQNQUamgRnIOkzLi_QHSyzeb:1mxPj7:Bl2FnM4tKrtDftiy20PMjYuIfpHYUK6FG6IYdZjPS6o 2021-12-29 08:33:29.459216+00
mnb97kue40xo05g2rwwkw6d34sxrnesw .eJxVjDsOwjAQBe_iGllO8E-U9JzB2l3v4gBypDipEHfHkVJAOzPvvVWCbS1pa7ykKauLGtTplyHQk-su8gPqfdY013WZUO-JPmzTtznz63q0fwcFWunrgELAEtGgEzcCGTp7I4ZCdA5iN9KRFaA8YARvDXoL7GNgO5Jn9fkCIRs5Sw:1mxQKq:6A9lz-3mKMJukzqDk-DXfGIbDNeLeGul_TgZ7A6Xlf8 2021-12-29 09:12:28.010763+00
po0rbd1yhywmc0i2jfam69r419a66aj8 .eJxVjMsOwiAQRf-FtSE8pB1cuvcbCMMMUjWQlHZl_HdD0oVu7znnvkWI-1bC3nkNC4mL0OL0u2FMT64D0CPWe5Op1W1dUA5FHrTLWyN-XQ_376DEXkY9QeKzIpWVn9gYhEhkI3lyYFg7jTMDg7WkAdF5mCFh9mRZZUhOi88X-eU4dg:1mzwj8:CWx3-u6eXmWLpwiFMK5_yWnoPY3yUSf1QCZY-UdJcF8 2022-01-05 08:11:58.507079+00
v28l0efbrv9x06z97ilwcf7lwtuf4ctc .eJxVjDsOwjAQRO_iGlm22fhDSc8ZrLV3gwPIluKkQtydREoBzRTz3sxbRFyXEtfOc5xIXIRW4vRbJsxPrjuhB9Z7k7nVZZ6S3BV50C5vjfh1Pdy_g4K9bGuLXqMDQqdDTtYN6AHIIoGGMIJlQwxB-VFn3gLPzjil3ABkAIBZfL7_vTer:1nABOV:0UAK9VV6D18QF1-189XQ2T9LrQUSdioGNoHdRUzzt7o 2022-02-02 13:52:59.489923+00
wf6d6vzf4u74l08o0qgbqehei21hibea .eJxVjDEOwjAMRe-SGUUkpHZgZO8ZIttxSAG1UtNOiLtDpQ6w_vfef5lE61LT2nROQzYX48zhd2OSh44byHcab5OVaVzmge2m2J02209Zn9fd_Tuo1Oq3DrGwD040Ro_-nJmJgkgsqAAIioCi0KGKMhU4Mgip6wjRF6JyMu8PBAI5Mw:1nIXJc:oovNJRods5cbviWOWush4H3jDdP8XklEignva_EnQ8Q 2022-02-25 14:54:28.092369+00
9rh2r15lb3xra3kdqjtll5n4zw7ebw95 .eJxVjDsOwjAQBe_iGln-xJ9Q0ucM1q69xgFkS3FSIe5OIqWA9s3Me7MA21rC1mkJc2JXptjld0OIT6oHSA-o98Zjq-syIz8UftLOp5bodTvdv4MCvey1tOiNIpGNATlq55IZvaABd4Ao1RCzARLWJ5dRA2kJGqxU1kfjPRL7fAHVPjfN:1nKDkD:rZM4YHHS9MckfKB5KrsvNBVMegYSRdlMqL3uDJRE0Cg 2022-03-02 06:24:53.914069+00
khn67dfajnzkr0tlusuyyub011gt0aqb .eJxVjMEOwiAQRP-FsyEsobL16N1vIAvLStVAUtqT8d9tkx70OPPezFsFWpcS1p7nMLG6KFCn3y5Seua6A35QvTedWl3mKepd0Qft-tY4v66H-3dQqJdt7UU4MedxGKwFh0RoCBFi4niOTsSAHQFA_JaYmI2nTBEdGRRrSX2-CY443A:1nM5q9:nf3N_nhzYu-XfEC1O2ICYP2Zt9XXPPVziSLrP5uHSVw 2022-03-07 10:22:45.432248+00
5x9v6r58e4l9if78anupog0ittsq2w3j .eJxVjMEOwiAQRP-FsyEsobL16N1vIAvLStVAUtqT8d9tkx70OPPezFsFWpcS1p7nMLG6KFCn3y5Seua6A35QvTedWl3mKepd0Qft-tY4v66H-3dQqJdt7UU4MedxGKwFh0RoCBFi4niOTsSAHQFA_JaYmI2nTBEdGRRrSX2-CY443A:1nM644:zfo0j_Zkrm04UxrDj8g_nnsXrpWtRzL4oRx3hAdqyqI 2022-03-07 10:37:08.963511+00
gcz795933839j3g0t3rjgmikzkzlwse3 .eJxVjEEOwiAQRe_C2hCmUC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8avmbzmdv7kam6gdzp .eJxVjMEOwiAQBf-FsyHAwgIevfsNBMoiVUOT0p6M_64kPej1zcx7sRD3rYa90xrmzM5MstPvluL0oDZAvsd2W_i0tG2dEx8KP2jn1yXT83K4fwc19jpqpXKWKAi0LpTAG0MGyVEELM6SSaScQAXSWCt8QYNWE3wNnTJ4YO8P2cs3MQ:1nSdIB:3RGvht_Mxap4ax-Njbawze8KDaixzUcSYQcnrHZOMwI 2022-03-25 11:18:43.949283+00
\.


Expand Down Expand Up @@ -3354,6 +3341,10 @@ COPY public.engine_comment (id, message, created_date, updated_date, owner_id, i
4 test 2021-12-22 07:21:38.792235+00 2021-12-22 07:21:38.792247+00 1 4
5 I don't know why... 2021-12-22 07:22:53.281391+00 2021-12-22 07:22:53.281407+00 1 1
6 Can you see my comment? 2021-12-22 07:23:04.819354+00 2021-12-22 07:23:04.81937+00 1 4
7 Why are we still here? 2022-03-16 04:03:59.502386+00 2022-03-16 04:03:59.502408+00 2 5
8 Just to suffer? 2022-03-16 04:14:02.542048+00 2022-03-16 04:14:02.542073+00 2 5
9 Something should be here 2022-03-16 04:37:59.564483+00 2022-03-16 04:37:59.564504+00 11 6
10 Another one issue 2022-03-16 04:43:48.426736+00 2022-03-16 04:43:48.426753+00 11 7
\.
Expand Down Expand Up @@ -3760,6 +3751,9 @@ COPY public.engine_issue (id, frame, "position", created_date, updated_date, job
2 51 121.615234375,33.515625,618.193359375,357.7275390625 2021-12-22 07:18:40.432626+00 \N 4 1 \N f
3 52 32.78125,152.4072265625,211.7841796875,766.12890625 2021-12-22 07:19:06.536571+00 \N 4 1 \N f
4 50 18.861328125,225.0771484375,283.755859375,371.0732421875 2021-12-22 07:21:38.787374+00 \N 4 1 \N f
5 0 244.58581235698148,319.63386727689067,326.9656750572103,192.76887871853796,543.6247139588122,175.4691075514893,835.2494279176244,360.0000000000018,609.5286041189956,586.544622425632,364.0361328125,528.87890625,244.58581235698148,319.63386727689067 2022-03-16 04:03:59.498797+00 \N 7 2 \N f
6 0 68.587890625,493.224609375,333.0205078125,662.2314453125 2022-03-16 04:37:59.561+00 \N 9 11 \N f
7 10 215.548828125,158.015625,979.130859375,748.443359375 2022-03-16 04:43:48.423683+00 \N 6 11 \N f
\.
Expand Down Expand Up @@ -4166,7 +4160,7 @@ SELECT pg_catalog.setval('public.auth_permission_id_seq', 88, true);
-- Name: auth_user_groups_id_seq; Type: SEQUENCE SET; Schema: public; Owner: root
--
SELECT pg_catalog.setval('public.auth_user_groups_id_seq', 54, true);
SELECT pg_catalog.setval('public.auth_user_groups_id_seq', 56, true);
--
Expand Down Expand Up @@ -4236,7 +4230,7 @@ SELECT pg_catalog.setval('public.engine_cloudstorage_id_seq', 1, false);
-- Name: engine_comment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: root
--
SELECT pg_catalog.setval('public.engine_comment_id_seq', 6, true);
SELECT pg_catalog.setval('public.engine_comment_id_seq', 10, true);
--
Expand All @@ -4257,7 +4251,7 @@ SELECT pg_catalog.setval('public.engine_image_id_seq', 371, true);
-- Name: engine_issue_id_seq; Type: SEQUENCE SET; Schema: public; Owner: root
--
SELECT pg_catalog.setval('public.engine_issue_id_seq', 4, true);
SELECT pg_catalog.setval('public.engine_issue_id_seq', 7, true);
--
Expand Down
140 changes: 139 additions & 1 deletion tests/rest_api/assets/issues.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,146 @@
{
"count": 4,
"count": 7,
"next": null,
"previous": null,
"results": [
{
"assignee": null,
"comments": [
{
"created_date": "2022-03-16T04:43:48.426736Z",
"id": 10,
"issue": 7,
"message": "Another one issue",
"owner": {
"first_name": "Business",
"id": 11,
"last_name": "Second",
"url": "http://localhost:8080/api/users/11",
"username": "business2"
},
"updated_date": "2022-03-16T04:43:48.426753Z"
}
],
"created_date": "2022-03-16T04:43:48.423683Z",
"frame": 10,
"id": 7,
"job": 6,
"owner": {
"first_name": "Business",
"id": 11,
"last_name": "Second",
"url": "http://localhost:8080/api/users/11",
"username": "business2"
},
"position": [
215.548828125,
158.015625,
979.130859375,
748.443359375
],
"resolved": false,
"updated_date": null
},
{
"assignee": null,
"comments": [
{
"created_date": "2022-03-16T04:37:59.564483Z",
"id": 9,
"issue": 6,
"message": "Something should be here",
"owner": {
"first_name": "Business",
"id": 11,
"last_name": "Second",
"url": "http://localhost:8080/api/users/11",
"username": "business2"
},
"updated_date": "2022-03-16T04:37:59.564504Z"
}
],
"created_date": "2022-03-16T04:37:59.561000Z",
"frame": 0,
"id": 6,
"job": 9,
"owner": {
"first_name": "Business",
"id": 11,
"last_name": "Second",
"url": "http://localhost:8080/api/users/11",
"username": "business2"
},
"position": [
68.587890625,
493.224609375,
333.0205078125,
662.2314453125
],
"resolved": false,
"updated_date": null
},
{
"assignee": null,
"comments": [
{
"created_date": "2022-03-16T04:03:59.502386Z",
"id": 7,
"issue": 5,
"message": "Why are we still here?",
"owner": {
"first_name": "User",
"id": 2,
"last_name": "First",
"url": "http://localhost:8080/api/users/2",
"username": "user1"
},
"updated_date": "2022-03-16T04:03:59.502408Z"
},
{
"created_date": "2022-03-16T04:14:02.542048Z",
"id": 8,
"issue": 5,
"message": "Just to suffer?",
"owner": {
"first_name": "User",
"id": 2,
"last_name": "First",
"url": "http://localhost:8080/api/users/2",
"username": "user1"
},
"updated_date": "2022-03-16T04:14:02.542073Z"
}
],
"created_date": "2022-03-16T04:03:59.498797Z",
"frame": 0,
"id": 5,
"job": 7,
"owner": {
"first_name": "User",
"id": 2,
"last_name": "First",
"url": "http://localhost:8080/api/users/2",
"username": "user1"
},
"position": [
244.58581235698148,
319.63386727689067,
326.9656750572103,
192.76887871853796,
543.6247139588122,
175.4691075514893,
835.2494279176244,
360.0000000000018,
609.5286041189956,
586.544622425632,
364.0361328125,
528.87890625,
244.58581235698148,
319.63386727689067
],
"resolved": false,
"updated_date": null
},
{
"assignee": null,
"comments": [
Expand Down
31 changes: 31 additions & 0 deletions tests/rest_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def annotations():
with open(osp.join(ASSETS_DIR, 'annotations.json')) as f:
return json.load(f)

@pytest.fixture(scope='module')
def issues():
with open(osp.join(ASSETS_DIR, 'issues.json')) as f:
return Container(json.load(f)['results'])

@pytest.fixture(scope='module')
def users_by_name(users):
return {user['username']: user for user in users}
Expand All @@ -134,6 +139,14 @@ def tasks_by_org(tasks):
data[''] = data.pop(None, [])
return data

@pytest.fixture(scope='module')
def issues_by_org(tasks, jobs, issues):
data = {}
for issue in issues:
data.setdefault(tasks[jobs[issue['job']]['task_id']]['organization'], []).append(issue)
data[''] = data.pop(None, [])
return data

@pytest.fixture(scope='module')
def assignee_id():
def get_id(data):
Expand Down Expand Up @@ -174,6 +187,14 @@ def check(user_id, jid):
return check

@pytest.fixture(scope='module')
def is_issue_staff(issues, is_job_staff, assignee_id):
@ownership
def check(user_id, issue_id):
return user_id == issues[issue_id]['owner']['id'] or \
user_id == assignee_id(issues[issue_id]) or \
is_job_staff(user_id, issues[issue_id]['job'])
return check
@pytest.fixture(scope='module')
def find_users(test_db):
def find(**kwargs):
assert len(kwargs) > 0
Expand Down Expand Up @@ -254,6 +275,16 @@ def find(tasks, users, is_staff):
return None, None
return find

@pytest.fixture(scope='module')
def find_issue_staff_user(is_issue_staff):
def find(issues, users, is_staff):
for issue in issues:
for user in users:
if is_staff == is_issue_staff(user['id'], issue['id']):
return user['username'], issue['id']
return None, None
return find

@pytest.fixture(scope='module')
def filter_jobs_with_shapes(annotations):
def find(jobs):
Expand Down
64 changes: 62 additions & 2 deletions tests/rest_api/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#
# SPDX-License-Identifier: MIT

import pytest
from http import HTTPStatus
from deepdiff import DeepDiff
import pytest
from copy import deepcopy

from .utils.config import post_method
from .utils.config import post_method, patch_method

class TestPostIssues:
def _test_check_response(self, user, data, is_allow, **kwargs):
Expand Down Expand Up @@ -77,3 +78,62 @@ def test_member_create_issue(self, org, role, job_staff, is_allow,
}

self._test_check_response(username, data, is_allow, org_id=org)


class TestPatchIssues:
def _test_check_response(self, user, issue_id, data, is_allow, **kwargs):
response = patch_method(user, f'issues/{issue_id}', data,
action='update', **kwargs)

if is_allow:
assert response.status_code == HTTPStatus.OK
assert DeepDiff(data, response.json(),
exclude_regex_paths="root\['updated_date|comments|id|owner'\]") == {}
else:
assert response.status_code == HTTPStatus.FORBIDDEN

@pytest.fixture(scope='class')
def request_data(self, issues):
def get_data(issue_id):
data = deepcopy(issues[issue_id])
data['resolved'] = not data['resolved']
data.pop('comments')
data.pop('updated_date')
data.pop('id')
data.pop('owner')
return data
return get_data

@pytest.mark.parametrize('org', [''])
@pytest.mark.parametrize('privilege, issue_staff, is_allow', [
('admin', True, True), ('admin', False, True),
('business', True, True), ('business', False, False),
('worker', True, True), ('worker', False, False),
('user', True, True), ('user', False, False)
])
def test_user_update_issue(self, org, privilege, issue_staff, is_allow,
find_issue_staff_user, find_users, issues_by_org, request_data):
users = find_users(privilege=privilege)
issues = issues_by_org[org]
username, issue_id = find_issue_staff_user(issues, users, issue_staff)

data = request_data(issue_id)
self._test_check_response(username, issue_id, data, is_allow)

@pytest.mark.parametrize('org', [2])
@pytest.mark.parametrize('role, issue_staff, is_allow', [
('maintainer', False, True), ('owner', False, True),
('supervisor', False, False), ('worker', False, False),
('maintainer', True, True), ('owner', True, True),
('supervisor', True, True), ('worker', True, True)
])
def test_member_update_issue(self, org, role, issue_staff, is_allow,
find_issue_staff_user, find_users, issues_by_org, request_data):
users = find_users(role=role, org=org)
issues = issues_by_org[org]
username, issue_id = find_issue_staff_user(issues, users, issue_staff)

data = request_data(issue_id)
self._test_check_response(username, issue_id, data, is_allow, org_id=org)


0 comments on commit 06f2dcb

Please sign in to comment.