From e8ee6ce72e63d1302d701ede0596c49cdaf8b544 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Mon, 18 Mar 2024 15:52:22 +0200 Subject: [PATCH] Code cleanup --- apiserver/bll/event/event_bll.py | 2 +- apiserver/bll/project/project_bll.py | 2 +- apiserver/database/model/base.py | 1 - .../tests/automated/test_project_tags.py | 2 +- apiserver/tools.py | 33 ++++++++++++------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apiserver/bll/event/event_bll.py b/apiserver/bll/event/event_bll.py index 31c25e8..0dd1b88 100644 --- a/apiserver/bll/event/event_bll.py +++ b/apiserver/bll/event/event_bll.py @@ -374,7 +374,7 @@ class EventBLL(object): if invalid_iterations_count: raise BulkIndexError( f"{invalid_iterations_count} document(s) failed to index.", - [invalid_iteration_error], + [{"_index": invalid_iteration_error}], ) if not added: diff --git a/apiserver/bll/project/project_bll.py b/apiserver/bll/project/project_bll.py index 3a51645..a500c19 100644 --- a/apiserver/bll/project/project_bll.py +++ b/apiserver/bll/project/project_bll.py @@ -869,7 +869,7 @@ class ProjectBLL: company, project_ids: Sequence[str], user_ids: Optional[Sequence[str]] = None, - ) -> Set[str]: + ) -> Set[Union[str, type(None)]]: """ Get the set of user ids that created tasks/models in the given projects If project_ids is empty then all projects are examined diff --git a/apiserver/database/model/base.py b/apiserver/database/model/base.py index 701aefa..238b53c 100644 --- a/apiserver/database/model/base.py +++ b/apiserver/database/model/base.py @@ -1297,7 +1297,6 @@ class GetMixin(PropsMixin): return result - class UpdateMixin(object): __user_set_allowed_fields = None __locked_when_published_fields = None diff --git a/apiserver/tests/automated/test_project_tags.py b/apiserver/tests/automated/test_project_tags.py index 73a81bd..d69b66e 100644 --- a/apiserver/tests/automated/test_project_tags.py +++ b/apiserver/tests/automated/test_project_tags.py @@ -113,7 +113,7 @@ class TestProjectTags(TestService): new_tags = ["New model tag"] self.api.models.update_tags(ids=[model], add_tags=new_tags) data = self.api.projects.get_model_tags(projects=[p]) - self.assertEqual(set(data.tags), set([*new_tags, *initial_tags])) + self.assertEqual(set(data.tags), {*new_tags, *initial_tags}) def new_task(self, **kwargs): self.update_missing( diff --git a/apiserver/tools.py b/apiserver/tools.py index 068759d..96e0ca7 100644 --- a/apiserver/tools.py +++ b/apiserver/tools.py @@ -7,13 +7,17 @@ from humanfriendly import parse_timespan def setup(): from apiserver.database import db + db.initialize() def gen_token(args): from apiserver.bll.auth import AuthBLL - resp = AuthBLL.get_token_for_user(args.user_id, args.company_id, parse_timespan(args.expiration)) - print('Token:\n%s' % resp.token) + + resp = AuthBLL.get_token_for_user( + args.user_id, args.company_id, int(parse_timespan(args.expiration)) + ) + print("Token:\n%s" % resp.token) def safe_get(obj, glob, default=None, separator="/"): @@ -23,19 +27,24 @@ def safe_get(obj, glob, default=None, separator="/"): return default -if __name__ == '__main__': +if __name__ == "__main__": top_parser = ArgumentParser(__doc__) - subparsers = top_parser.add_subparsers(title='Sections') + subparsers = top_parser.add_subparsers(title="Sections") - token = subparsers.add_parser('token') - token_commands = token.add_subparsers(title='Commands') - token_create = token_commands.add_parser('generate', description='Generate a new token') - token_create.add_argument('--user-id', '-u', help='User ID', required=True) - token_create.add_argument('--company-id', '-c', help='Company ID', required=True) - token_create.add_argument('--expiration', '-exp', - help="Token expiration (time span, shorthand suffixes are supported, default 1m)", - default=parse_timespan('1m')) + token = subparsers.add_parser("token") + token_commands = token.add_subparsers(title="Commands") + token_create = token_commands.add_parser( + "generate", description="Generate a new token" + ) + token_create.add_argument("--user-id", "-u", help="User ID", required=True) + token_create.add_argument("--company-id", "-c", help="Company ID", required=True) + token_create.add_argument( + "--expiration", + "-exp", + help="Token expiration (time span, shorthand suffixes are supported, default 1m)", + default=parse_timespan("1m"), + ) token_create.set_defaults(_func=gen_token) args = top_parser.parse_args()