Fix SDK tests: login once per class (#5123)

main
Kirill Sizov 3 years ago committed by GitHub
parent 94eb6cb5f1
commit ce09f28512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -162,8 +162,10 @@ jobs:
- name: Running REST API tests - name: Running REST API tests
run: | run: |
pip3 install --user /tmp/cvat_sdk/ pip3 install --user /tmp/cvat_sdk/
pip3 install --user cvat-cli/
pip3 install --user -r tests/python/requirements.txt pip3 install --user -r tests/python/requirements.txt
pytest tests/python/rest_api -k 'GET' -s pytest tests/python/rest_api -k 'GET' -s
pytest tests/python/sdk tests/python/cli
- name: Creating a log file from cvat containers - name: Creating a log file from cvat containers
if: failure() if: failure()

@ -176,7 +176,7 @@ REST_FRAMEWORK = {
'rest_framework.throttling.AnonRateThrottle', 'rest_framework.throttling.AnonRateThrottle',
], ],
'DEFAULT_THROTTLE_RATES': { 'DEFAULT_THROTTLE_RATES': {
'anon': '150/minute', 'anon': '100/minute',
}, },
'DEFAULT_METADATA_CLASS': 'rest_framework.metadata.SimpleMetadata', 'DEFAULT_METADATA_CLASS': 'rest_framework.metadata.SimpleMetadata',
'DEFAULT_SCHEMA_CLASS': 'cvat.apps.iam.schema.CustomAutoSchema', 'DEFAULT_SCHEMA_CLASS': 'cvat.apps.iam.schema.CustomAutoSchema',

@ -26,7 +26,7 @@ class TestCLI:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup restore_db_per_function, # force fixture call order to allow DB setup
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,
tmp_path: Path, tmp_path: Path,
admin_user: str, admin_user: str,

@ -10,7 +10,7 @@ import pytest
from shared.utils.config import server_get from shared.utils.config import server_get
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetAnalytics: class TestGetAnalytics:
endpoint = "analytics/app/kibana" endpoint = "analytics/app/kibana"

@ -11,7 +11,7 @@ from cvat_sdk.api_client import ApiClient, Configuration, models
from shared.utils.config import BASE_URL, USER_PASS, make_api_client from shared.utils.config import BASE_URL, USER_PASS, make_api_client
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestBasicAuth: class TestBasicAuth:
def test_can_do_basic_auth(self, admin_user: str): def test_can_do_basic_auth(self, admin_user: str):
username = admin_user username = admin_user
@ -22,7 +22,7 @@ class TestBasicAuth:
assert user.username == username assert user.username == username
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestTokenAuth: class TestTokenAuth:
@staticmethod @staticmethod
def login(client: ApiClient, username: str) -> models.Token: def login(client: ApiClient, username: str) -> models.Token:
@ -87,7 +87,7 @@ class TestTokenAuth:
assert response.status == HTTPStatus.UNAUTHORIZED assert response.status == HTTPStatus.UNAUTHORIZED
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestCredentialsManagement: class TestCredentialsManagement:
def test_can_register(self): def test_can_register(self):
username = "newuser" username = "newuser"

@ -13,7 +13,7 @@ from deepdiff import DeepDiff
from shared.utils import config from shared.utils import config
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetResources: class TestGetResources:
@pytest.mark.parametrize("path", glob.glob(osp.join(config.ASSETS_DIR, "*.json"))) @pytest.mark.parametrize("path", glob.glob(osp.join(config.ASSETS_DIR, "*.json")))
def test_check_objects_integrity(self, path): def test_check_objects_integrity(self, path):

@ -11,7 +11,7 @@ from deepdiff import DeepDiff
from shared.utils.config import get_method, patch_method, post_method from shared.utils.config import get_method, patch_method, post_method
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetCloudStorage: class TestGetCloudStorage:
def _test_can_see(self, user, storage_id, data, **kwargs): def _test_can_see(self, user, storage_id, data, **kwargs):
response = get_method(user, f"cloudstorages/{storage_id}", **kwargs) response = get_method(user, f"cloudstorages/{storage_id}", **kwargs)
@ -92,7 +92,7 @@ class TestGetCloudStorage:
self._test_cannot_see(username, storage_id, org_id=org_id) self._test_cannot_see(username, storage_id, org_id=org_id)
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPostCloudStorage: class TestPostCloudStorage:
_SPEC = { _SPEC = {
"provider_type": "AWS_S3_BUCKET", "provider_type": "AWS_S3_BUCKET",
@ -167,7 +167,7 @@ class TestPostCloudStorage:
self._test_cannot_create(username, self._SPEC, org_id=org_id) self._test_cannot_create(username, self._SPEC, org_id=org_id)
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchCloudStorage: class TestPatchCloudStorage:
_SPEC = { _SPEC = {
"display_name": "New display name", "display_name": "New display name",

@ -10,7 +10,7 @@ import pytest
from shared.utils.config import post_method from shared.utils.config import post_method
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestCreateInvitations: class TestCreateInvitations:
def _test_post_invitation_201(self, user, data, invitee, **kwargs): def _test_post_invitation_201(self, user, data, invitee, **kwargs):
response = post_method(user, "invitations", data, **kwargs) response = post_method(user, "invitations", data, **kwargs)

@ -15,7 +15,7 @@ from deepdiff import DeepDiff
from shared.utils.config import make_api_client from shared.utils.config import make_api_client
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPostIssues: class TestPostIssues:
def _test_check_response(self, user, data, is_allow, **kwargs): def _test_check_response(self, user, data, is_allow, **kwargs):
with make_api_client(user) as client: with make_api_client(user) as client:
@ -120,7 +120,7 @@ class TestPostIssues:
self._test_check_response(username, data, is_allow, org_id=org) self._test_check_response(username, data, is_allow, org_id=org)
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchIssues: class TestPatchIssues:
def _test_check_response(self, user, issue_id, data, is_allow, **kwargs): def _test_check_response(self, user, issue_id, data, is_allow, **kwargs):
with make_api_client(user) as client: with make_api_client(user) as client:
@ -242,7 +242,7 @@ class TestPatchIssues:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestDeleteIssues: class TestDeleteIssues:
def _test_check_response(self, user, issue_id, expect_success, **kwargs): def _test_check_response(self, user, issue_id, expect_success, **kwargs):
with make_api_client(user) as client: with make_api_client(user) as client:

@ -47,7 +47,7 @@ def filter_jobs(jobs, tasks, org):
return jobs, kwargs return jobs, kwargs
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetJobs: class TestGetJobs:
def _test_get_job_200(self, user, jid, data, **kwargs): def _test_get_job_200(self, user, jid, data, **kwargs):
with make_api_client(user) as client: with make_api_client(user) as client:
@ -97,7 +97,7 @@ class TestGetJobs:
self._test_get_job_403(user["username"], job["id"], **kwargs) self._test_get_job_403(user["username"], job["id"], **kwargs)
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestListJobs: class TestListJobs:
def _test_list_jobs_200(self, user, data, **kwargs): def _test_list_jobs_200(self, user, data, **kwargs):
with make_api_client(user) as client: with make_api_client(user) as client:
@ -142,7 +142,7 @@ class TestListJobs:
self._test_list_jobs_403(user["username"], **kwargs) self._test_list_jobs_403(user["username"], **kwargs)
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetAnnotations: class TestGetAnnotations:
def _test_get_job_annotations_200(self, user, jid, data, **kwargs): def _test_get_job_annotations_200(self, user, jid, data, **kwargs):
with make_api_client(user) as client: with make_api_client(user) as client:
@ -266,7 +266,7 @@ class TestGetAnnotations:
self._test_get_job_annotations_403(username, job_id, **kwargs) self._test_get_job_annotations_403(username, job_id, **kwargs)
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchJobAnnotations: class TestPatchJobAnnotations:
def _check_respone(self, username, jid, expect_success, data=None, org=None): def _check_respone(self, username, jid, expect_success, data=None, org=None):
kwargs = {} kwargs = {}
@ -402,7 +402,7 @@ class TestPatchJobAnnotations:
self._check_respone(username, jid, expect_success, data, org=org) self._check_respone(username, jid, expect_success, data, org=org)
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchJob: class TestPatchJob:
@pytest.fixture(scope="class") @pytest.fixture(scope="class")
def find_task_staff_user(self, is_task_staff): def find_task_staff_user(self, is_task_staff):
@ -489,7 +489,7 @@ class TestPatchJob:
assert response.status == HTTPStatus.FORBIDDEN assert response.status == HTTPStatus.FORBIDDEN
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestJobDataset: class TestJobDataset:
def _export_dataset(self, username, jid, **kwargs): def _export_dataset(self, username, jid, **kwargs):
with make_api_client(username) as api_client: with make_api_client(username) as api_client:

@ -11,7 +11,7 @@ from deepdiff import DeepDiff
from shared.utils.config import get_method, patch_method from shared.utils.config import get_method, patch_method
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetMemberships: class TestGetMemberships:
def _test_can_see_memberships(self, user, data, **kwargs): def _test_can_see_memberships(self, user, data, **kwargs):
response = get_method(user, "memberships", **kwargs) response = get_method(user, "memberships", **kwargs)
@ -44,7 +44,7 @@ class TestGetMemberships:
self._test_cannot_see_memberships(user, org_id=1) self._test_cannot_see_memberships(user, org_id=1)
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchMemberships: class TestPatchMemberships:
_ORG = 2 _ORG = 2

@ -42,7 +42,7 @@ class TestMetadataOrganizations:
assert response.status_code == HTTPStatus.OK assert response.status_code == HTTPStatus.OK
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetOrganizations: class TestGetOrganizations:
_ORG = 2 _ORG = 2
@ -76,7 +76,7 @@ class TestGetOrganizations:
assert response.status_code == HTTPStatus.NOT_FOUND assert response.status_code == HTTPStatus.NOT_FOUND
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchOrganizations: class TestPatchOrganizations:
_ORG = 2 _ORG = 2
@ -128,7 +128,7 @@ class TestPatchOrganizations:
assert response.status_code != HTTPStatus.OK assert response.status_code != HTTPStatus.OK
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestDeleteOrganizations: class TestDeleteOrganizations:
_ORG = 2 _ORG = 2

@ -17,7 +17,7 @@ from shared.utils.config import get_method, make_api_client, patch_method
from .utils import export_dataset from .utils import export_dataset
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetProjects: class TestGetProjects:
def _find_project_by_user_org(self, user, projects, is_project_staff_flag, is_project_staff): def _find_project_by_user_org(self, user, projects, is_project_staff_flag, is_project_staff):
for p in projects: for p in projects:
@ -265,7 +265,7 @@ class TestGetProjectBackup:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPostProjects: class TestPostProjects:
def _test_create_project_201(self, user, spec, **kwargs): def _test_create_project_201(self, user, spec, **kwargs):
with make_api_client(user) as api_client: with make_api_client(user) as api_client:
@ -351,7 +351,7 @@ class TestPostProjects:
self._test_create_project_201(user["username"], spec, org_id=user["org"]) self._test_create_project_201(user["username"], spec, org_id=user["org"])
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestImportExportDatasetProject: class TestImportExportDatasetProject:
def _test_export_project(self, username, pid, format_name): def _test_export_project(self, username, pid, format_name):
with make_api_client(username) as api_client: with make_api_client(username) as api_client:
@ -459,7 +459,7 @@ class TestImportExportDatasetProject:
assert response.status == HTTPStatus.ACCEPTED assert response.status == HTTPStatus.ACCEPTED
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchProjectLabel: class TestPatchProjectLabel:
def test_admin_can_delete_label(self, projects): def test_admin_can_delete_label(self, projects):
project = deepcopy(list(projects)[1]) project = deepcopy(list(projects)[1])

@ -32,7 +32,7 @@ def _wait_until_task_is_created(username, task_id):
raise Exception("Cannot create task") raise Exception("Cannot create task")
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestCreateFromRemote: class TestCreateFromRemote:
task_id = 12 task_id = 12

@ -103,7 +103,7 @@ def _idempotent_saving_resource_to_cloud_storage(*args, **kwargs):
remove_asset(args[1]["resource"], kwargs["filename"]) remove_asset(args[1]["resource"], kwargs["filename"])
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestSaveResource: class TestSaveResource:
_USERNAME = "admin1" _USERNAME = "admin1"
_ORG = 2 _ORG = 2
@ -213,7 +213,7 @@ def _import_dataset_from_cloud_storage(user, obj_id, obj, **kwargs):
status = response.status_code status = response.status_code
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
@pytest.mark.usefixtures("restore_cvat_data") @pytest.mark.usefixtures("restore_cvat_data")
class TestImportResource: class TestImportResource:
_USERNAME = "admin1" _USERNAME = "admin1"

@ -10,7 +10,7 @@ import pytest
from shared.utils.config import make_api_client from shared.utils.config import make_api_client
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetServer: class TestGetServer:
def test_can_retrieve_about_unauthorized(self): def test_can_retrieve_about_unauthorized(self):
with make_api_client(user=None, password=None) as api_client: with make_api_client(user=None, password=None) as api_client:
@ -28,7 +28,7 @@ class TestGetServer:
assert len(data.exporters) != 0 assert len(data.exporters) != 0
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetSchema: class TestGetSchema:
def test_can_get_schema_unauthorized(self): def test_can_get_schema_unauthorized(self):
with make_api_client(user=None, password=None) as api_client: with make_api_client(user=None, password=None) as api_client:

@ -27,7 +27,7 @@ def get_cloud_storage_content(username, cloud_storage_id, manifest):
return data return data
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetTasks: class TestGetTasks:
def _test_task_list_200(self, user, project_id, data, exclude_paths="", **kwargs): def _test_task_list_200(self, user, project_id, data, exclude_paths="", **kwargs):
with make_api_client(user) as api_client: with make_api_client(user) as api_client:
@ -142,7 +142,7 @@ class TestGetTasks:
self._test_assigned_users_to_see_task_data(tasks, users, is_task_staff, org=org["slug"]) self._test_assigned_users_to_see_task_data(tasks, users, is_task_staff, org=org["slug"])
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPostTasks: class TestPostTasks:
def _test_create_task_201(self, user, spec, **kwargs): def _test_create_task_201(self, user, spec, **kwargs):
with make_api_client(user) as api_client: with make_api_client(user) as api_client:
@ -264,7 +264,7 @@ class TestPostTasks:
self._test_create_task_201(username, spec) self._test_create_task_201(username, spec)
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetData: class TestGetData:
_USERNAME = "user1" _USERNAME = "user1"
@ -285,7 +285,7 @@ class TestGetData:
assert response.headers["Content-Type"] == content_type assert response.headers["Content-Type"] == content_type
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchTaskAnnotations: class TestPatchTaskAnnotations:
def _test_check_response(self, is_allow, response, data=None): def _test_check_response(self, is_allow, response, data=None):
if is_allow: if is_allow:
@ -391,7 +391,7 @@ class TestPatchTaskAnnotations:
self._test_check_response(is_allow, response, data) self._test_check_response(is_allow, response, data)
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetTaskDataset: class TestGetTaskDataset:
def _test_export_task(self, username, tid, **kwargs): def _test_export_task(self, username, tid, **kwargs):
with make_api_client(username) as api_client: with make_api_client(username) as api_client:
@ -403,7 +403,7 @@ class TestGetTaskDataset:
assert response.data assert response.data
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
@pytest.mark.usefixtures("restore_cvat_data") @pytest.mark.usefixtures("restore_cvat_data")
class TestPostTaskData: class TestPostTaskData:
_USERNAME = "admin1" _USERNAME = "admin1"

@ -14,7 +14,7 @@ from deepdiff import DeepDiff
from shared.utils.config import make_api_client from shared.utils.config import make_api_client
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetUsers: class TestGetUsers:
def _test_can_see( def _test_can_see(
self, self,

@ -12,7 +12,7 @@ from deepdiff import DeepDiff
from shared.utils.config import delete_method, get_method, patch_method, post_method from shared.utils.config import delete_method, get_method, patch_method, post_method
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPostWebhooks: class TestPostWebhooks:
proj_webhook = { proj_webhook = {
"description": "webhook description", "description": "webhook description",
@ -370,7 +370,7 @@ class TestPostWebhooks:
assert response.status_code == HTTPStatus.BAD_REQUEST assert response.status_code == HTTPStatus.BAD_REQUEST
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetWebhooks: class TestGetWebhooks:
def test_admin_can_get_webhook(self, webhooks, users, projects): def test_admin_can_get_webhook(self, webhooks, users, projects):
proj_webhooks = [w for w in webhooks if w["type"] == "project"] proj_webhooks = [w for w in webhooks if w["type"] == "project"]
@ -528,7 +528,7 @@ class TestGetWebhooks:
assert DeepDiff(webhook, response.json(), ignore_order=True) == {} assert DeepDiff(webhook, response.json(), ignore_order=True) == {}
@pytest.mark.usefixtures("dontchangedb") @pytest.mark.usefixtures("restore_db_per_class")
class TestGetListWebhooks: class TestGetListWebhooks:
def test_can_get_webhooks_list(self, webhooks): def test_can_get_webhooks_list(self, webhooks):
response = get_method("admin2", "webhooks") response = get_method("admin2", "webhooks")
@ -732,7 +732,7 @@ class TestGetListWebhooks:
assert DeepDiff(expected_response, response.json()["results"], ignore_order=True) == {} assert DeepDiff(expected_response, response.json()["results"], ignore_order=True) == {}
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestPatchWebhooks: class TestPatchWebhooks:
WID = 2 WID = 2
@ -977,7 +977,7 @@ class TestPatchWebhooks:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestDeleteWebhooks: class TestDeleteWebhooks:
@pytest.mark.parametrize( @pytest.mark.parametrize(
"privilege, allow", [("user", False), ("business", False), ("admin", True)] "privilege, allow", [("user", False), ("business", False), ("admin", True)]

@ -72,7 +72,7 @@ def get_deliveries(webhook_id):
return deliveries, last_payload return deliveries, last_payload
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookProjectEvents: class TestWebhookProjectEvents:
def test_webhook_update_project_name(self): def test_webhook_update_project_name(self):
response = post_method("admin1", "projects", {"name": "project"}) response = post_method("admin1", "projects", {"name": "project"})
@ -173,7 +173,7 @@ class TestWebhookProjectEvents:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookIntersection: class TestWebhookIntersection:
# Test case description: # Test case description:
# few webhooks are triggered by the same event # few webhooks are triggered by the same event
@ -284,7 +284,7 @@ class TestWebhookIntersection:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookTaskEvents: class TestWebhookTaskEvents:
def test_webhook_update_task_assignee(self, users, tasks): def test_webhook_update_task_assignee(self, users, tasks):
task_id, project_id = next( task_id, project_id = next(
@ -382,7 +382,7 @@ class TestWebhookTaskEvents:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookJobEvents: class TestWebhookJobEvents:
def test_webhook_update_job_assignee(self, jobs, tasks, users): def test_webhook_update_job_assignee(self, jobs, tasks, users):
job = next( job = next(
@ -449,7 +449,7 @@ class TestWebhookJobEvents:
assert payload["job"]["state"] == patch_data["state"] assert payload["job"]["state"] == patch_data["state"]
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookIssueEvents: class TestWebhookIssueEvents:
def test_webhook_update_issue_resolved(self, issues, jobs, tasks): def test_webhook_update_issue_resolved(self, issues, jobs, tasks):
issue = next( issue = next(
@ -545,7 +545,7 @@ class TestWebhookIssueEvents:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookMembershipEvents: class TestWebhookMembershipEvents:
def test_webhook_update_membership_role(self, memberships): def test_webhook_update_membership_role(self, memberships):
roles = {"worker", "supervisor", "maintainer"} roles = {"worker", "supervisor", "maintainer"}
@ -594,7 +594,7 @@ class TestWebhookMembershipEvents:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookOrganizationEvents: class TestWebhookOrganizationEvents:
def test_webhook_update_organization_name(self, organizations): def test_webhook_update_organization_name(self, organizations):
org_id = list(organizations)[0]["id"] org_id = list(organizations)[0]["id"]
@ -611,7 +611,7 @@ class TestWebhookOrganizationEvents:
assert payload["organization"]["name"] == patch_data["name"] assert payload["organization"]["name"] == patch_data["name"]
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookCommentEvents: class TestWebhookCommentEvents:
def test_webhook_update_comment_message(self, comments, issues, jobs, tasks): def test_webhook_update_comment_message(self, comments, issues, jobs, tasks):
org_comments = list( org_comments = list(
@ -684,7 +684,7 @@ class TestWebhookCommentEvents:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookPing: class TestWebhookPing:
def test_ping_webhook(self, projects): def test_ping_webhook(self, projects):
project_id = list(projects)[0]["id"] project_id = list(projects)[0]["id"]
@ -709,7 +709,7 @@ class TestWebhookPing:
) )
@pytest.mark.usefixtures("changedb") @pytest.mark.usefixtures("restore_db_per_function")
class TestWebhookRedelivery: class TestWebhookRedelivery:
def test_webhook_redelivery(self, projects): def test_webhook_redelivery(self, projects):
project = list(projects)[0] project = list(projects)[0]

@ -8,7 +8,7 @@ import pytest
from cvat_sdk import Client from cvat_sdk import Client
from PIL import Image from PIL import Image
from shared.utils.config import BASE_URL from shared.utils.config import BASE_URL, USER_PASS
from shared.utils.helpers import generate_image_file from shared.utils.helpers import generate_image_file
from .util import generate_coco_json from .util import generate_coco_json
@ -45,3 +45,14 @@ def fxt_coco_file(tmp_path: Path, fxt_image_file: Path):
generate_coco_json(ann_filename, img_info=(img_filename, *img_size)) generate_coco_json(ann_filename, img_info=(img_filename, *img_size))
yield ann_filename yield ann_filename
@pytest.fixture(scope="class")
def fxt_login(admin_user: str, restore_db_per_class):
client = Client(BASE_URL)
client.config.status_check_period = 0.01
user = admin_user
with client:
client.login((user, USER_PASS))
yield (client, user)

@ -21,7 +21,7 @@ class TestClientUsecases:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup restore_db_per_function, # force fixture call order to allow DB setup
fxt_logger: Tuple[Logger, io.StringIO], fxt_logger: Tuple[Logger, io.StringIO],
fxt_client: Client, fxt_client: Client,
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,

@ -12,26 +12,25 @@ from cvat_sdk import Client
from cvat_sdk.api_client import exceptions, models from cvat_sdk.api_client import exceptions, models
from cvat_sdk.core.proxies.tasks import ResourceType, Task from cvat_sdk.core.proxies.tasks import ResourceType, Task
from shared.utils.config import USER_PASS
class TestIssuesUsecases: class TestIssuesUsecases:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup
tmp_path: Path, tmp_path: Path,
fxt_login: Tuple[Client, str],
fxt_logger: Tuple[Logger, io.StringIO], fxt_logger: Tuple[Logger, io.StringIO],
fxt_client: Client,
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,
admin_user: str,
): ):
self.tmp_path = tmp_path self.tmp_path = tmp_path
_, self.logger_stream = fxt_logger logger, self.logger_stream = fxt_logger
self.client = fxt_client
self.stdout = fxt_stdout self.stdout = fxt_stdout
self.user = admin_user self.client, self.user = fxt_login
self.client.login((self.user, USER_PASS)) self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield yield
@ -138,19 +137,20 @@ class TestCommentsUsecases:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup
tmp_path: Path, tmp_path: Path,
fxt_login: Tuple[Client, str],
fxt_logger: Tuple[Logger, io.StringIO], fxt_logger: Tuple[Logger, io.StringIO],
fxt_client: Client,
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,
admin_user: str,
): ):
self.tmp_path = tmp_path self.tmp_path = tmp_path
_, self.logger_stream = fxt_logger logger, self.logger_stream = fxt_logger
self.client = fxt_client
self.stdout = fxt_stdout self.stdout = fxt_stdout
self.user = admin_user self.client, self.user = fxt_login
self.client.login((self.user, USER_PASS)) self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield yield

@ -14,8 +14,6 @@ from cvat_sdk.api_client import models
from cvat_sdk.core.proxies.tasks import ResourceType, Task from cvat_sdk.core.proxies.tasks import ResourceType, Task
from PIL import Image from PIL import Image
from shared.utils.config import USER_PASS
from .util import make_pbar from .util import make_pbar
@ -23,19 +21,20 @@ class TestJobUsecases:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup
tmp_path: Path, tmp_path: Path,
fxt_login: Tuple[Client, str],
fxt_logger: Tuple[Logger, io.StringIO], fxt_logger: Tuple[Logger, io.StringIO],
fxt_client: Client,
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,
admin_user: str,
): ):
self.tmp_path = tmp_path self.tmp_path = tmp_path
_, self.logger_stream = fxt_logger logger, self.logger_stream = fxt_logger
self.client = fxt_client
self.stdout = fxt_stdout self.stdout = fxt_stdout
self.user = admin_user self.client, self.user = fxt_login
self.client.login((self.user, USER_PASS)) self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield yield

@ -14,7 +14,6 @@ from cvat_sdk.api_client import exceptions
from cvat_sdk.core.proxies.tasks import ResourceType, Task from cvat_sdk.core.proxies.tasks import ResourceType, Task
from PIL import Image from PIL import Image
from shared.utils.config import USER_PASS
from shared.utils.helpers import generate_image_files from shared.utils.helpers import generate_image_files
from .util import make_pbar from .util import make_pbar
@ -24,19 +23,20 @@ class TestTaskUsecases:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup
tmp_path: Path, tmp_path: Path,
fxt_login: Tuple[Client, str],
fxt_logger: Tuple[Logger, io.StringIO], fxt_logger: Tuple[Logger, io.StringIO],
fxt_client: Client,
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,
admin_user: str,
): ):
self.tmp_path = tmp_path self.tmp_path = tmp_path
_, self.logger_stream = fxt_logger logger, self.logger_stream = fxt_logger
self.client = fxt_client
self.stdout = fxt_stdout self.stdout = fxt_stdout
self.user = admin_user self.client, self.user = fxt_login
self.client.login((self.user, USER_PASS)) self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield yield

@ -11,26 +11,25 @@ import pytest
from cvat_sdk import Client, models from cvat_sdk import Client, models
from cvat_sdk.api_client import exceptions from cvat_sdk.api_client import exceptions
from shared.utils.config import USER_PASS
class TestUserUsecases: class TestUserUsecases:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup( def setup(
self, self,
changedb, # force fixture call order to allow DB setup
tmp_path: Path, tmp_path: Path,
fxt_login: Tuple[Client, str],
fxt_logger: Tuple[Logger, io.StringIO], fxt_logger: Tuple[Logger, io.StringIO],
fxt_client: Client,
fxt_stdout: io.StringIO, fxt_stdout: io.StringIO,
admin_user: str,
): ):
self.tmp_path = tmp_path self.tmp_path = tmp_path
_, self.logger_stream = fxt_logger logger, self.logger_stream = fxt_logger
self.client = fxt_client
self.stdout = fxt_stdout self.stdout = fxt_stdout
self.user = admin_user self.client, self.user = fxt_login
self.client.login((self.user, USER_PASS)) self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield yield

@ -311,7 +311,7 @@ def services(request):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def changedb(request): def restore_db_per_function(request):
# Note that autouse fixtures are executed first within their scope, so be aware of the order # Note that autouse fixtures are executed first within their scope, so be aware of the order
# Pre-test DB setups (eg. with class-declared autouse setup() method) may be cleaned. # Pre-test DB setups (eg. with class-declared autouse setup() method) may be cleaned.
# https://docs.pytest.org/en/stable/reference/fixtures.html#autouse-fixtures-are-executed-first-within-their-scope # https://docs.pytest.org/en/stable/reference/fixtures.html#autouse-fixtures-are-executed-first-within-their-scope
@ -323,7 +323,7 @@ def changedb(request):
@pytest.fixture(scope="class") @pytest.fixture(scope="class")
def dontchangedb(request): def restore_db_per_class(request):
platform = request.config.getoption("--platform") platform = request.config.getoption("--platform")
if platform == "local": if platform == "local":
docker_restore_db() docker_restore_db()

Loading…
Cancel
Save