This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK: Add organization support to the high-level layer (cvat-ai#5718)
This consists of two parts: * API to work with organizations; * API to work with other resources in the context of an organization.
- Loading branch information
1 parent
6f14ec5
commit 635a6a6
Showing
6 changed files
with
253 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (C) 2022 CVAT.ai Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from __future__ import annotations | ||
|
||
from cvat_sdk.api_client import apis, models | ||
from cvat_sdk.core.proxies.model_proxy import ( | ||
ModelCreateMixin, | ||
ModelDeleteMixin, | ||
ModelListMixin, | ||
ModelRetrieveMixin, | ||
ModelUpdateMixin, | ||
build_model_bases, | ||
) | ||
|
||
_OrganizationEntityBase, _OrganizationRepoBase = build_model_bases( | ||
models.OrganizationRead, apis.OrganizationsApi, api_member_name="organizations_api" | ||
) | ||
|
||
|
||
class Organization( | ||
models.IOrganizationRead, | ||
_OrganizationEntityBase, | ||
ModelUpdateMixin[models.IPatchedOrganizationWriteRequest], | ||
ModelDeleteMixin, | ||
): | ||
_model_partial_update_arg = "patched_organization_write_request" | ||
|
||
|
||
class OrganizationsRepo( | ||
_OrganizationRepoBase, | ||
ModelCreateMixin[Organization, models.IOrganizationWriteRequest], | ||
ModelListMixin[Organization], | ||
ModelRetrieveMixin[Organization], | ||
): | ||
_entity_type = Organization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright (C) 2022 CVAT.ai Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import io | ||
from logging import Logger | ||
from typing import Tuple | ||
|
||
import pytest | ||
from cvat_sdk import Client, models | ||
from cvat_sdk.api_client import exceptions | ||
from cvat_sdk.core.proxies.organizations import Organization | ||
|
||
|
||
class TestOrganizationUsecases: | ||
@pytest.fixture(autouse=True) | ||
def setup( | ||
self, | ||
fxt_login: Tuple[Client, str], | ||
fxt_logger: Tuple[Logger, io.StringIO], | ||
fxt_stdout: io.StringIO, | ||
): | ||
logger, self.logger_stream = fxt_logger | ||
self.client, self.user = fxt_login | ||
self.client.logger = logger | ||
|
||
api_client = self.client.api_client | ||
for k in api_client.configuration.logger: | ||
api_client.configuration.logger[k] = logger | ||
|
||
yield | ||
|
||
assert fxt_stdout.getvalue() == "" | ||
|
||
@pytest.fixture() | ||
def fxt_organization(self) -> Organization: | ||
org = self.client.organizations.create( | ||
models.OrganizationWriteRequest( | ||
slug="testorg", | ||
name="Test Organization", | ||
description="description", | ||
contact={"email": "[email protected]"}, | ||
) | ||
) | ||
|
||
try: | ||
yield org | ||
finally: | ||
# It's not allowed to create multiple orgs with the same slug, | ||
# so we have to remove the org at the end of each test. | ||
org.remove() | ||
|
||
def test_can_create_organization(self, fxt_organization: Organization): | ||
assert fxt_organization.slug == "testorg" | ||
assert fxt_organization.name == "Test Organization" | ||
assert fxt_organization.description == "description" | ||
assert fxt_organization.contact == {"email": "[email protected]"} | ||
|
||
def test_can_retrieve_organization(self, fxt_organization: Organization): | ||
org = self.client.organizations.retrieve(fxt_organization.id) | ||
|
||
assert org.id == fxt_organization.id | ||
assert org.slug == fxt_organization.slug | ||
|
||
def test_can_list_organizations(self, fxt_organization: Organization): | ||
orgs = self.client.organizations.list() | ||
|
||
assert fxt_organization.slug in set(o.slug for o in orgs) | ||
|
||
def test_can_update_organization(self, fxt_organization: Organization): | ||
fxt_organization.update( | ||
models.PatchedOrganizationWriteRequest(description="new description") | ||
) | ||
assert fxt_organization.description == "new description" | ||
|
||
retrieved_org = self.client.organizations.retrieve(fxt_organization.id) | ||
assert retrieved_org.description == "new description" | ||
|
||
def test_can_remove_organization(self): | ||
org = self.client.organizations.create(models.OrganizationWriteRequest(slug="testorg2")) | ||
org.remove() | ||
|
||
with pytest.raises(exceptions.NotFoundException): | ||
org.fetch() |