Skip to content

Commit 87b1f87

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Fixed wrong imports
1 parent 6a421a1 commit 87b1f87

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

src/superannotate/lib/app/interface/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Union
44

55
from lib.core.enums import AnnotationStatus
6-
from lib.core.exceptions import AppException
76
from pydantic import constr
87
from pydantic import StrictStr
98
from pydantic import validate_arguments as pydantic_validate_arguments

src/superannotate/lib/app/mixp/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import functools
22
import sys
33

4+
from lib.infrastructure.controller import Controller
45
from mixpanel import Mixpanel
5-
from superannotate.lib.infrastructure.controller import Controller
6-
from superannotate.version import __version__
6+
from version import __version__
77

88
from .config import TOKEN
99
from .utils import parsers

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22

3-
import superannotate.lib.core as constances
4-
from superannotate.lib.app.helpers import extract_project_folder
5-
from superannotate.lib.core.enums import ProjectType
6-
from superannotate.lib.infrastructure.controller import Controller
3+
import lib.core as constances
4+
from lib.app.helpers import extract_project_folder
5+
from lib.core.enums import ProjectType
6+
from lib.infrastructure.controller import Controller
77

88
controller = Controller(logger=logging.getLogger())
99

src/superannotate/lib/core/usecases/projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ def execute(self):
833833
try:
834834
self._response.data = self._teams.get_one(self._team_id)
835835
except Exception:
836-
raise AppException("Can't get team data.")
836+
raise AppException("Can't get team data.") from None
837837
return self._response
838838

839839

src/superannotate/lib/infrastructure/controller.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ def init(self, config_path):
6868
self.configs.get_one("token"),
6969
self.configs.get_one("main_endpoint"),
7070
)
71-
if token:
72-
token = token.value
73-
if main_endpoint:
74-
main_endpoint = main_endpoint.value
71+
token = None if not token else token.value
72+
main_endpoint = None if not main_endpoint else main_endpoint.value
7573
if not main_endpoint:
7674
self.configs.insert(ConfigEntity("main_endpoint", constances.BACKEND_URL))
75+
main_endpoint = constances.BACKEND_URL
7776
if not token:
7877
self.configs.insert(ConfigEntity("token", ""))
7978
self._logger.warning("Fill config.json")
@@ -94,9 +93,18 @@ def init(self, config_path):
9493
self._backend_client.api_url = main_endpoint
9594
self._backend_client._auth_token = token
9695
self._backend_client.get_session.cache_clear()
97-
self._team_id = int(self.configs.get_one("token").value.split("=")[-1])
96+
token = self.configs.get_one("token").value
97+
self.validate_token(token)
98+
self._team_id = int(token.split("=")[-1])
9899
self._team = None
99100

101+
@staticmethod
102+
def validate_token(token: str):
103+
try:
104+
return int(token.split("=")[-1])
105+
except Exception:
106+
raise AppException("Invalid token.")
107+
100108
@property
101109
def config_path(self):
102110
return self._config_path

tests/unit/test_controller_init.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
from contextlib import contextmanager
55
import pkg_resources
6+
import tempfile
67
from unittest import TestCase
78
from unittest.mock import mock_open
89
from unittest.mock import patch
@@ -65,3 +66,15 @@ def test_init_create(self, input_mock):
6566
)
6667
)
6768
self.assertEqual(out.getvalue().strip(), "Configuration file successfully created.")
69+
70+
71+
class SKDInitTest(TestCase):
72+
73+
def test_init_flow(self):
74+
with tempfile.TemporaryDirectory() as temp_dir:
75+
token_path = f"{temp_dir}/config.json"
76+
with open(token_path, "w") as temp_config:
77+
json.dump({"token": "token=1234"}, temp_config)
78+
temp_config.close()
79+
import src.superannotate as sa
80+
sa.init(token_path)

0 commit comments

Comments
 (0)