Skip to content

Commit

Permalink
Fixed tests according to the #4436
Browse files Browse the repository at this point in the history
  • Loading branch information
ActiveChooN committed Mar 16, 2022
1 parent 06f2dcb commit a85ee7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
20 changes: 15 additions & 5 deletions tests/rest_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,21 @@ def check(user_id, jid):
return check

@pytest.fixture(scope='module')
def is_issue_staff(issues, is_job_staff, assignee_id):
def is_issue_staff(issues, jobs, 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'])
user_id == assignee_id(jobs[issues[issue_id]['job']])
return check

@pytest.fixture(scope='module')
def is_issue_admin(issues, jobs, is_task_staff):
@ownership
def check(user_id, issue_id):
return is_task_staff(user_id, jobs[issues[issue_id]['job']]['task_id'])
return check

@pytest.fixture(scope='module')
def find_users(test_db):
def find(**kwargs):
Expand Down Expand Up @@ -276,11 +284,13 @@ def find(tasks, users, is_staff):
return find

@pytest.fixture(scope='module')
def find_issue_staff_user(is_issue_staff):
def find(issues, users, is_staff):
def find_issue_staff_user(is_issue_staff, is_issue_admin):
def find(issues, users, is_staff, is_admin):
for issue in issues:
for user in users:
if is_staff == is_issue_staff(user['id'], issue['id']):
i_admin, i_staff = is_issue_admin(user['id'], issue['id']), is_issue_staff(user['id'], issue['id'])
if (is_admin is None and (i_staff or i_admin) == is_staff) \
or (is_admin == i_admin and is_staff == i_staff):
return user['username'], issue['id']
return None, None
return find
Expand Down
34 changes: 18 additions & 16 deletions tests/rest_api/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _test_check_response(self, user, data, is_allow, **kwargs):
assert user == response.json()['owner']['username']
assert data['message'] == response.json()['comments'][0]['message']
assert DeepDiff(data, response.json(),
exclude_regex_paths="root\['created_date|updated_date|comments|id|owner|message'\]") == {}
exclude_regex_paths=r"root\['created_date|updated_date|comments|id|owner|message'\]") == {}
else:
assert response.status_code == HTTPStatus.FORBIDDEN

Expand Down Expand Up @@ -88,7 +88,7 @@ def _test_check_response(self, user, issue_id, data, is_allow, **kwargs):
if is_allow:
assert response.status_code == HTTPStatus.OK
assert DeepDiff(data, response.json(),
exclude_regex_paths="root\['updated_date|comments|id|owner'\]") == {}
exclude_regex_paths=r"root\['updated_date|comments|id|owner'\]") == {}
else:
assert response.status_code == HTTPStatus.FORBIDDEN

Expand All @@ -105,33 +105,35 @@ def get_data(issue_id):
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)
@pytest.mark.parametrize('privilege, issue_staff, issue_admin, is_allow', [
('admin', True, None, True), ('admin', False, None, True),
('business', True, None, True), ('business', False, None, False),
('user', True, None, True), ('user', False, None, False),
('worker', False, True, True), ('worker', True, False, False),
('worker', False, False, False)
])
def test_user_update_issue(self, org, privilege, issue_staff, is_allow,
def test_user_update_issue(self, org, privilege, issue_staff, issue_admin, 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)
username, issue_id = find_issue_staff_user(issues, users, issue_staff, issue_admin)

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)
@pytest.mark.parametrize('role, issue_staff, issue_admin, is_allow', [
('maintainer', True, None, True), ('maintainer', False, None, True),
('supervisor', True, None, True), ('supervisor', False, None, False),
('owner', True, None, True), ('owner', False, None, True),
('worker', False, True, True), ('worker', True, False, False),
('worker', False, False, False)
])
def test_member_update_issue(self, org, role, issue_staff, is_allow,
def test_member_update_issue(self, org, role, issue_staff, issue_admin, 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)
username, issue_id = find_issue_staff_user(issues, users, issue_staff, issue_admin)

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

0 comments on commit a85ee7e

Please sign in to comment.