From a127c965ad84ff1b044bcbe2977dbee3dbab17d7 Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 8 Jan 2024 20:19:07 +0100 Subject: [PATCH 1/2] add event msg with populate and the right table in swagger --- .../clan_cli/webui/routers/endpoints.py | 28 ++ pkgs/clan-cli/clan_cli/webui/schemas.py | 27 ++ pkgs/clan-cli/clan_cli/webui/sql_app.db | Bin 118784 -> 0 bytes pkgs/clan-cli/clan_cli/webui/sql_crud.py | 23 ++ pkgs/clan-cli/clan_cli/webui/sql_models.py | 29 +- pkgs/clan-cli/clan_cli/webui/tags.py | 5 + .../clan-cli/tests/openapi_client/__init__.py | 3 + .../tests/openapi_client/api/__init__.py | 1 + .../openapi_client/api/eventmessages_api.py | 339 ++++++++++++++++++ .../tests/openapi_client/docs/Eventmessage.md | 34 ++ .../openapi_client/docs/EventmessageCreate.md | 34 ++ .../openapi_client/docs/EventmessagesApi.md | 143 ++++++++ .../tests/openapi_client/models/__init__.py | 2 + .../openapi_client/models/eventmessage.py | 85 +++++ .../models/eventmessage_create.py | 85 +++++ .../openapi_client/test/test_eventmessage.py | 67 ++++ .../test/test_eventmessage_create.py | 67 ++++ .../test/test_eventmessages_api.py | 45 +++ pkgs/clan-cli/tests/test_db_api.py | 70 ++++ 19 files changed, 1079 insertions(+), 8 deletions(-) delete mode 100644 pkgs/clan-cli/clan_cli/webui/sql_app.db create mode 100644 pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py create mode 100644 pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md create mode 100644 pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md create mode 100644 pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md create mode 100644 pkgs/clan-cli/tests/openapi_client/models/eventmessage.py create mode 100644 pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py create mode 100644 pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py create mode 100644 pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py create mode 100644 pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py diff --git a/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py index 4aec32b..2e8848e 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py @@ -12,6 +12,8 @@ from .. import sql_crud, sql_db, sql_models from ..schemas import ( Entity, EntityCreate, + Eventmessage, + EventmessageCreate, Resolution, Service, ServiceCreate, @@ -236,3 +238,29 @@ async def get_all_resolutions( id=1, ) ] + + +######################### +# # +# Eventmessage # +# # +######################### + + +@router.post("/api/v1/send_msg", response_model=Eventmessage, tags=[Tags.eventmessages]) +async def create_eventmessage( + eventmsg: EventmessageCreate, db: Session = Depends(sql_db.get_db) +) -> EventmessageCreate: + return sql_crud.create_eventmessage(db, eventmsg) + + +@router.get( + "/api/v1/event_messages", + response_model=List[Eventmessage], + tags=[Tags.eventmessages], +) +async def get_all_eventmessages( + skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db) +) -> List[sql_models.Eventmessage]: + eventmessages = sql_crud.get_eventmessages(db, skip=skip, limit=limit) + return eventmessages diff --git a/pkgs/clan-cli/clan_cli/webui/schemas.py b/pkgs/clan-cli/clan_cli/webui/schemas.py index bdb1a2e..e227994 100644 --- a/pkgs/clan-cli/clan_cli/webui/schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/schemas.py @@ -103,3 +103,30 @@ class Resolution(ResolutionCreate): class Config: orm_mode = True + + +######################### +# # +# Eventmessage # +# # +######################### +class EventmessageBase(BaseModel): + id: int = Field(..., example=123456) + timestamp: int = Field(..., example=1234123413) + group: int = Field(..., example=1) # event group type (for the label) + group_id: int = Field( + ..., example=12345 + ) # specific to one group needed to enable visually nested groups + msg_type: int = Field(..., example=1) # message type for the label + src_did: str = Field(..., example="did:sov:test:2234") + des_did: str = Field(..., example="did:sov:test:1234") + + +class EventmessageCreate(EventmessageBase): + msg: dict = Field(..., example={"optinal": "values"}) # optional + pass + + +class Eventmessage(EventmessageCreate): + class Config: + orm_mode = True diff --git a/pkgs/clan-cli/clan_cli/webui/sql_app.db b/pkgs/clan-cli/clan_cli/webui/sql_app.db deleted file mode 100644 index 6d1f62ff087420f261feba70882b3ede2aef8603..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 118784 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCV5nkXV31`%fKmnq1{MUDff0#~i&@2> zm$!?T{|AE%6E_3DGXHVDgM8V1(!3{l{_s?D|K)Dt7T`R*95EL&MTm`^grGf!jU#%1`ZI8{R+NQO;ZTb?m9GcP5zBC{esIX|zsG&i-VI6gB4 z&X#o!a&-)GRq*t4ag9(wQ>EbVrvO)}ppluP*<>QcE-o+6*kWFin3R(WmxMEFx*8sevS=5ajCS8szHd>>3Qwk(pYopplZ9f}sh;cuiz|FqvWn4Ul^^ zxik%>*~DGt85zJ)QCyglS&|x`SXz<~<|9RnAv_#qY9-mlT~!$yWx;APE8>e%3-XII zOY(~{Q;Xw^Q;W(nlT+jK5_40LC8VIi506e{Nfce6xJ8y!&_Fg*Gh2dP+)|aXkrli3 zC5a`a#mL$v@mma5kHt!`xMqqto4BbeV=Y#@KtYIXlLTIyK&mnA0f}nXis1{<)V!2} z{LH+P_|l>rWb4H7T8FF)(^_O%&00}>*24n7q_O}dLdEb}kE{#RdSqG6rU+qnaaC2u zmSS+uMfM^xTLfw!B>y7IC}?nTmSpCp#wQo0CYGe8D7ZL=xQ2N8x+=K1x;cjWgeYh@ zhXw_?`h~=UM1w;deFMOm29dj9`5%=3KvAL);u;a6VQi*}QXs&b4NBX{g#b((6hz44 z$f1lZUJOoL$Remk4NBPoat_$FB$o?Zn&u*G;@+ybayN1q#v3B@L<@!3#qH%88wFtr zA6|06vnt55a8Y4s z1EO8CkPoMqkP{tTBR_6ykkzAk30X?BNs0$j!7_uhDcoo{gBNNCB!j|*LAettqaoFu zpvV~}8O@LvUo{F3i+DpgldpiAUEEfgv5^;+Mv794^K(i|GV}9_<3Yt)aYmvG~=6s!)a2g6=u zNzEEgc5zo_lr{sxvqh!kz_UNIoQSBl^Giqv3ne*6qKpK zu7-G>lQ`=^y71T!lGbeWWM>ywR%UF91m_(jOOTixQ2QYH2T1~ygK#ua5kUvC2f0Q; z$e^`Y!3M)34JkLm(+Rx#1XYG8RZ(V&CYNR)8=JVcETZua&fB1tUrJ^QjLi=93OuR8 zBtS6?3M?2O(t!12WfRwwWlV)d4@@>bvjE0q!)an>0jhzS1)3o&Y~s4IjJX)*fdUC; zA}dZ4L8?&A1c_)SFtdr9$|Bl=FoWU~OG*-xGg9HcXTfPQOeL!6Fj37$MMidUSy{#= zQE)PWSpcJ%pyomn2uu`|I*_6mrNIJnH*%uLEI{VL>{W2`_xEvi1ov|AG(rh9vcmT(GVC7 zfzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c4FNb9?f=7rVw5o&0;3@?8UmvsFd71*Aut*O zqaiRF0;3@?8UmvsFd72GHUvid|HC$FM?E$g0;3@?8UmvsFd71*Aut*OqaiRF0;3@? z8UmvsFd72z5E#Ax4;~bwjL{Gn4S~@R7!85Z5Eu=C(GVC7fzc2c4S~@R7!85Z5E!;0 zFgpJ~Y@>G6W1}H38UmvsFd71*Aut*OqaiRF0;3@?8UmvsFd71*Apj47(f&U?C`K8h nAut*OqaiRF0;3@?8UmvsFd71*Aut*OqaiRF0;3@?Y(oG5zzy9P diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py index f18bc4e..433a2f2 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_crud.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -124,3 +124,26 @@ def delete_entity_by_did(db: Session, did: str) -> None: def delete_entity_by_did_recursive(db: Session, did: str) -> None: delete_service_by_entity_did(db, did) delete_entity_by_did(db, did) + + +######################### +# # +# Eventmessage # +# # +######################### + + +def create_eventmessage( + db: Session, eventmsg: schemas.EventmessageCreate +) -> sql_models.Eventmessage: + db_eventmessage = sql_models.Eventmessage(**eventmsg.dict()) + db.add(db_eventmessage) + db.commit() + db.refresh(db_eventmessage) + return db_eventmessage + + +def get_eventmessages( + db: Session, skip: int = 0, limit: int = 100 +) -> List[sql_models.Eventmessage]: + return db.query(sql_models.Eventmessage).offset(skip).limit(limit).all() diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py index b0358ce..597321e 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_models.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -1,11 +1,4 @@ -from sqlalchemy import ( - JSON, - Boolean, - Column, - ForeignKey, - String, - Text, -) +from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String, Text from sqlalchemy.orm import relationship from .sql_db import Base @@ -54,3 +47,23 @@ class Service(ServiceAbstract): # One entity can have many services entity = relationship("Entity", back_populates="services") entity_did = Column(String, ForeignKey("entities.did")) + + +class Eventmessage(Base): + __tablename__ = "eventmessages" + + ## Queryable body ## + id = Column(Integer, primary_key=True, index=True) + timestamp = Column(Integer, unique=True, index=True) + group = Column(Integer, index=True) + group_id = Column(Integer, index=True) + msg_type = Column(Integer, index=True) # message type for the label + src_did = Column(String, index=True) + des_did = Column(String, index=True) + + ## Non queryable body ## + # In here we deposit: Network, Roles, Visible, etc. + msg = Column(JSON) + + ## Relations ## + # One entity can send many messages diff --git a/pkgs/clan-cli/clan_cli/webui/tags.py b/pkgs/clan-cli/clan_cli/webui/tags.py index 034beb7..cccd186 100644 --- a/pkgs/clan-cli/clan_cli/webui/tags.py +++ b/pkgs/clan-cli/clan_cli/webui/tags.py @@ -8,6 +8,7 @@ class Tags(Enum): entities = "entities" repositories = "repositories" resolutions = "resolution" + eventmessages = "eventmessages" def __str__(self) -> str: return self.value @@ -34,4 +35,8 @@ tags_metadata: List[Dict[str, Any]] = [ "name": str(Tags.resolutions), "description": "Operations on a resolution.", }, + { + "name": str(Tags.eventmessages), + "description": "Operations for event messages.", + }, ] diff --git a/pkgs/clan-cli/tests/openapi_client/__init__.py b/pkgs/clan-cli/tests/openapi_client/__init__.py index 638483e..d31566c 100644 --- a/pkgs/clan-cli/tests/openapi_client/__init__.py +++ b/pkgs/clan-cli/tests/openapi_client/__init__.py @@ -19,6 +19,7 @@ __version__ = "1.0.0" # import apis into sdk package from openapi_client.api.default_api import DefaultApi from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.eventmessages_api import EventmessagesApi from openapi_client.api.repositories_api import RepositoriesApi from openapi_client.api.resolution_api import ResolutionApi from openapi_client.api.services_api import ServicesApi @@ -37,6 +38,8 @@ from openapi_client.exceptions import ApiException # import models into sdk package from openapi_client.models.entity import Entity from openapi_client.models.entity_create import EntityCreate +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate from openapi_client.models.http_validation_error import HTTPValidationError from openapi_client.models.machine import Machine from openapi_client.models.resolution import Resolution diff --git a/pkgs/clan-cli/tests/openapi_client/api/__init__.py b/pkgs/clan-cli/tests/openapi_client/api/__init__.py index 39c3f1b..87b34f9 100644 --- a/pkgs/clan-cli/tests/openapi_client/api/__init__.py +++ b/pkgs/clan-cli/tests/openapi_client/api/__init__.py @@ -3,6 +3,7 @@ # import apis into api package from openapi_client.api.default_api import DefaultApi from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.eventmessages_api import EventmessagesApi from openapi_client.api.repositories_api import RepositoriesApi from openapi_client.api.resolution_api import ResolutionApi from openapi_client.api.services_api import ServicesApi diff --git a/pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py b/pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py new file mode 100644 index 0000000..092ef36 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py @@ -0,0 +1,339 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import re # noqa: F401 +import io +import warnings + +from pydantic import validate_arguments, ValidationError + +from pydantic import StrictInt + +from typing import List, Optional + +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate + +from openapi_client.api_client import ApiClient +from openapi_client.api_response import ApiResponse +from openapi_client.exceptions import ( # noqa: F401 + ApiTypeError, + ApiValueError +) + + +class EventmessagesApi: + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + def __init__(self, api_client=None) -> None: + if api_client is None: + api_client = ApiClient.get_default() + self.api_client = api_client + + @validate_arguments + def create_eventmessage(self, eventmessage_create : EventmessageCreate, **kwargs) -> Eventmessage: # noqa: E501 + """Create Eventmessage # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.create_eventmessage(eventmessage_create, async_req=True) + >>> result = thread.get() + + :param eventmessage_create: (required) + :type eventmessage_create: EventmessageCreate + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _request_timeout: timeout setting for this request. + If one number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: Eventmessage + """ + kwargs['_return_http_data_only'] = True + if '_preload_content' in kwargs: + message = "Error! Please call the create_eventmessage_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 + raise ValueError(message) + return self.create_eventmessage_with_http_info(eventmessage_create, **kwargs) # noqa: E501 + + @validate_arguments + def create_eventmessage_with_http_info(self, eventmessage_create : EventmessageCreate, **kwargs) -> ApiResponse: # noqa: E501 + """Create Eventmessage # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.create_eventmessage_with_http_info(eventmessage_create, async_req=True) + >>> result = thread.get() + + :param eventmessage_create: (required) + :type eventmessage_create: EventmessageCreate + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _preload_content: if False, the ApiResponse.data will + be set to none and raw_data will store the + HTTP response body without reading/decoding. + Default is True. + :type _preload_content: bool, optional + :param _return_http_data_only: response data instead of ApiResponse + object with status code, headers, etc + :type _return_http_data_only: bool, optional + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the authentication + in the spec for a single request. + :type _request_auth: dict, optional + :type _content_type: string, optional: force content-type for the request + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: tuple(Eventmessage, status_code(int), headers(HTTPHeaderDict)) + """ + + _params = locals() + + _all_params = [ + 'eventmessage_create' + ] + _all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout', + '_request_auth', + '_content_type', + '_headers' + ] + ) + + # validate the arguments + for _key, _val in _params['kwargs'].items(): + if _key not in _all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method create_eventmessage" % _key + ) + _params[_key] = _val + del _params['kwargs'] + + _collection_formats = {} + + # process the path parameters + _path_params = {} + + # process the query parameters + _query_params = [] + # process the header parameters + _header_params = dict(_params.get('_headers', {})) + # process the form parameters + _form_params = [] + _files = {} + # process the body parameter + _body_params = None + if _params['eventmessage_create'] is not None: + _body_params = _params['eventmessage_create'] + + # set the HTTP header `Accept` + _header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # set the HTTP header `Content-Type` + _content_types_list = _params.get('_content_type', + self.api_client.select_header_content_type( + ['application/json'])) + if _content_types_list: + _header_params['Content-Type'] = _content_types_list + + # authentication setting + _auth_settings = [] # noqa: E501 + + _response_types_map = { + '200': "Eventmessage", + '422': "HTTPValidationError", + } + + return self.api_client.call_api( + '/api/v1/send_msg', 'POST', + _path_params, + _query_params, + _header_params, + body=_body_params, + post_params=_form_params, + files=_files, + response_types_map=_response_types_map, + auth_settings=_auth_settings, + async_req=_params.get('async_req'), + _return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=_params.get('_preload_content', True), + _request_timeout=_params.get('_request_timeout'), + collection_formats=_collection_formats, + _request_auth=_params.get('_request_auth')) + + @validate_arguments + def get_all_eventmessages(self, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> List[Eventmessage]: # noqa: E501 + """Get All Eventmessages # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.get_all_eventmessages(skip, limit, async_req=True) + >>> result = thread.get() + + :param skip: + :type skip: int + :param limit: + :type limit: int + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _request_timeout: timeout setting for this request. + If one number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: List[Eventmessage] + """ + kwargs['_return_http_data_only'] = True + if '_preload_content' in kwargs: + message = "Error! Please call the get_all_eventmessages_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 + raise ValueError(message) + return self.get_all_eventmessages_with_http_info(skip, limit, **kwargs) # noqa: E501 + + @validate_arguments + def get_all_eventmessages_with_http_info(self, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> ApiResponse: # noqa: E501 + """Get All Eventmessages # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.get_all_eventmessages_with_http_info(skip, limit, async_req=True) + >>> result = thread.get() + + :param skip: + :type skip: int + :param limit: + :type limit: int + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _preload_content: if False, the ApiResponse.data will + be set to none and raw_data will store the + HTTP response body without reading/decoding. + Default is True. + :type _preload_content: bool, optional + :param _return_http_data_only: response data instead of ApiResponse + object with status code, headers, etc + :type _return_http_data_only: bool, optional + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the authentication + in the spec for a single request. + :type _request_auth: dict, optional + :type _content_type: string, optional: force content-type for the request + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: tuple(List[Eventmessage], status_code(int), headers(HTTPHeaderDict)) + """ + + _params = locals() + + _all_params = [ + 'skip', + 'limit' + ] + _all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout', + '_request_auth', + '_content_type', + '_headers' + ] + ) + + # validate the arguments + for _key, _val in _params['kwargs'].items(): + if _key not in _all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method get_all_eventmessages" % _key + ) + _params[_key] = _val + del _params['kwargs'] + + _collection_formats = {} + + # process the path parameters + _path_params = {} + + # process the query parameters + _query_params = [] + if _params.get('skip') is not None: # noqa: E501 + _query_params.append(('skip', _params['skip'])) + + if _params.get('limit') is not None: # noqa: E501 + _query_params.append(('limit', _params['limit'])) + + # process the header parameters + _header_params = dict(_params.get('_headers', {})) + # process the form parameters + _form_params = [] + _files = {} + # process the body parameter + _body_params = None + # set the HTTP header `Accept` + _header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # authentication setting + _auth_settings = [] # noqa: E501 + + _response_types_map = { + '200': "List[Eventmessage]", + '422': "HTTPValidationError", + } + + return self.api_client.call_api( + '/api/v1/event_messages', 'GET', + _path_params, + _query_params, + _header_params, + body=_body_params, + post_params=_form_params, + files=_files, + response_types_map=_response_types_map, + auth_settings=_auth_settings, + async_req=_params.get('async_req'), + _return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=_params.get('_preload_content', True), + _request_timeout=_params.get('_request_timeout'), + collection_formats=_collection_formats, + _request_auth=_params.get('_request_auth')) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md b/pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md new file mode 100644 index 0000000..cbe65cb --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md @@ -0,0 +1,34 @@ +# Eventmessage + +## Properties + +| Name | Type | Description | Notes | +| ------------- | ---------- | ----------- | ----- | +| **id** | **int** | | +| **timestamp** | **int** | | +| **group** | **int** | | +| **group_id** | **int** | | +| **msg_type** | **int** | | +| **src_did** | **str** | | +| **des_did** | **str** | | +| **msg** | **object** | | + +## Example + +```python +from openapi_client.models.eventmessage import Eventmessage + +# TODO update the JSON string below +json = "{}" +# create an instance of Eventmessage from a JSON string +eventmessage_instance = Eventmessage.from_json(json) +# print the JSON string representation of the object +print Eventmessage.to_json() + +# convert the object into a dict +eventmessage_dict = eventmessage_instance.to_dict() +# create an instance of Eventmessage from a dict +eventmessage_form_dict = eventmessage.from_dict(eventmessage_dict) +``` + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md b/pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md new file mode 100644 index 0000000..eb6f16d --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md @@ -0,0 +1,34 @@ +# EventmessageCreate + +## Properties + +| Name | Type | Description | Notes | +| ------------- | ---------- | ----------- | ----- | +| **id** | **int** | | +| **timestamp** | **int** | | +| **group** | **int** | | +| **group_id** | **int** | | +| **msg_type** | **int** | | +| **src_did** | **str** | | +| **des_did** | **str** | | +| **msg** | **object** | | + +## Example + +```python +from openapi_client.models.eventmessage_create import EventmessageCreate + +# TODO update the JSON string below +json = "{}" +# create an instance of EventmessageCreate from a JSON string +eventmessage_create_instance = EventmessageCreate.from_json(json) +# print the JSON string representation of the object +print EventmessageCreate.to_json() + +# convert the object into a dict +eventmessage_create_dict = eventmessage_create_instance.to_dict() +# create an instance of EventmessageCreate from a dict +eventmessage_create_form_dict = eventmessage_create.from_dict(eventmessage_create_dict) +``` + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md b/pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md new file mode 100644 index 0000000..d6affb9 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md @@ -0,0 +1,143 @@ +# openapi_client.EventmessagesApi + +All URIs are relative to _http://localhost_ + +| Method | HTTP request | Description | +| ---------------------------------------------------------------------- | ------------------------------ | --------------------- | +| [**create_eventmessage**](EventmessagesApi.md#create_eventmessage) | **POST** /api/v1/send_msg | Create Eventmessage | +| [**get_all_eventmessages**](EventmessagesApi.md#get_all_eventmessages) | **GET** /api/v1/event_messages | Get All Eventmessages | + +# **create_eventmessage** + +> Eventmessage create_eventmessage(eventmessage_create) + +Create Eventmessage + +### Example + +```python +import time +import os +import openapi_client +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate +from openapi_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = openapi_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with openapi_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = openapi_client.EventmessagesApi(api_client) + eventmessage_create = openapi_client.EventmessageCreate() # EventmessageCreate | + + try: + # Create Eventmessage + api_response = api_instance.create_eventmessage(eventmessage_create) + print("The response of EventmessagesApi->create_eventmessage:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling EventmessagesApi->create_eventmessage: %s\n" % e) +``` + +### Parameters + +| Name | Type | Description | Notes | +| ----------------------- | ----------------------------------------------- | ----------- | ----- | +| **eventmessage_create** | [**EventmessageCreate**](EventmessageCreate.md) | | + +### Return type + +[**Eventmessage**](Eventmessage.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +| ----------- | ------------------- | ---------------- | +| **200** | Successful Response | - | +| **422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **get_all_eventmessages** + +> List[Eventmessage] get_all_eventmessages(skip=skip, limit=limit) + +Get All Eventmessages + +### Example + +```python +import time +import os +import openapi_client +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = openapi_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with openapi_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = openapi_client.EventmessagesApi(api_client) + skip = 0 # int | (optional) (default to 0) + limit = 100 # int | (optional) (default to 100) + + try: + # Get All Eventmessages + api_response = api_instance.get_all_eventmessages(skip=skip, limit=limit) + print("The response of EventmessagesApi->get_all_eventmessages:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling EventmessagesApi->get_all_eventmessages: %s\n" % e) +``` + +### Parameters + +| Name | Type | Description | Notes | +| --------- | ------- | ----------- | --------------------------- | +| **skip** | **int** | | [optional] [default to 0] | +| **limit** | **int** | | [optional] [default to 100] | + +### Return type + +[**List[Eventmessage]**](Eventmessage.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +| ----------- | ------------------- | ---------------- | +| **200** | Successful Response | - | +| **422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/models/__init__.py b/pkgs/clan-cli/tests/openapi_client/models/__init__.py index 822cc4e..b6c094b 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/__init__.py +++ b/pkgs/clan-cli/tests/openapi_client/models/__init__.py @@ -16,6 +16,8 @@ # import models into model package from openapi_client.models.entity import Entity from openapi_client.models.entity_create import EntityCreate +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate from openapi_client.models.http_validation_error import HTTPValidationError from openapi_client.models.machine import Machine from openapi_client.models.resolution import Resolution diff --git a/pkgs/clan-cli/tests/openapi_client/models/eventmessage.py b/pkgs/clan-cli/tests/openapi_client/models/eventmessage.py new file mode 100644 index 0000000..ece8617 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/models/eventmessage.py @@ -0,0 +1,85 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictInt, StrictStr + +class Eventmessage(BaseModel): + """ + Eventmessage + """ + id: StrictInt = Field(...) + timestamp: StrictInt = Field(...) + group: StrictInt = Field(...) + group_id: StrictInt = Field(...) + msg_type: StrictInt = Field(...) + src_did: StrictStr = Field(...) + des_did: StrictStr = Field(...) + msg: Dict[str, Any] = Field(...) + __properties = ["id", "timestamp", "group", "group_id", "msg_type", "src_did", "des_did", "msg"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Eventmessage: + """Create an instance of Eventmessage from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Eventmessage: + """Create an instance of Eventmessage from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return Eventmessage.parse_obj(obj) + + _obj = Eventmessage.parse_obj({ + "id": obj.get("id"), + "timestamp": obj.get("timestamp"), + "group": obj.get("group"), + "group_id": obj.get("group_id"), + "msg_type": obj.get("msg_type"), + "src_did": obj.get("src_did"), + "des_did": obj.get("des_did"), + "msg": obj.get("msg") + }) + return _obj + + diff --git a/pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py b/pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py new file mode 100644 index 0000000..34915bb --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py @@ -0,0 +1,85 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictInt, StrictStr + +class EventmessageCreate(BaseModel): + """ + EventmessageCreate + """ + id: StrictInt = Field(...) + timestamp: StrictInt = Field(...) + group: StrictInt = Field(...) + group_id: StrictInt = Field(...) + msg_type: StrictInt = Field(...) + src_did: StrictStr = Field(...) + des_did: StrictStr = Field(...) + msg: Dict[str, Any] = Field(...) + __properties = ["id", "timestamp", "group", "group_id", "msg_type", "src_did", "des_did", "msg"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> EventmessageCreate: + """Create an instance of EventmessageCreate from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> EventmessageCreate: + """Create an instance of EventmessageCreate from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return EventmessageCreate.parse_obj(obj) + + _obj = EventmessageCreate.parse_obj({ + "id": obj.get("id"), + "timestamp": obj.get("timestamp"), + "group": obj.get("group"), + "group_id": obj.get("group_id"), + "msg_type": obj.get("msg_type"), + "src_did": obj.get("src_did"), + "des_did": obj.get("des_did"), + "msg": obj.get("msg") + }) + return _obj + + diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py new file mode 100644 index 0000000..21852d5 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py @@ -0,0 +1,67 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from openapi_client.models.eventmessage import Eventmessage # noqa: E501 + +class TestEventmessage(unittest.TestCase): + """Eventmessage unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> Eventmessage: + """Test Eventmessage + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `Eventmessage` + """ + model = Eventmessage() # noqa: E501 + if include_optional: + return Eventmessage( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values} + ) + else: + return Eventmessage( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values}, + ) + """ + + def testEventmessage(self): + """Test Eventmessage""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py new file mode 100644 index 0000000..8bc282d --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py @@ -0,0 +1,67 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from openapi_client.models.eventmessage_create import EventmessageCreate # noqa: E501 + +class TestEventmessageCreate(unittest.TestCase): + """EventmessageCreate unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> EventmessageCreate: + """Test EventmessageCreate + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `EventmessageCreate` + """ + model = EventmessageCreate() # noqa: E501 + if include_optional: + return EventmessageCreate( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values} + ) + else: + return EventmessageCreate( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values}, + ) + """ + + def testEventmessageCreate(self): + """Test EventmessageCreate""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py new file mode 100644 index 0000000..e2841ab --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py @@ -0,0 +1,45 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from openapi_client.api.eventmessages_api import EventmessagesApi # noqa: E501 + + +class TestEventmessagesApi(unittest.TestCase): + """EventmessagesApi unit test stubs""" + + def setUp(self) -> None: + self.api = EventmessagesApi() # noqa: E501 + + def tearDown(self) -> None: + pass + + def test_create_eventmessage(self) -> None: + """Test case for create_eventmessage + + Create Eventmessage # noqa: E501 + """ + pass + + def test_get_all_eventmessages(self) -> None: + """Test case for get_all_eventmessages + + Get All Eventmessages # noqa: E501 + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index 2bb519d..26b48fa 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -1,13 +1,17 @@ import random +import time import uuid from openapi_client import ApiClient from openapi_client.api import DefaultApi from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.eventmessages_api import EventmessagesApi from openapi_client.api.services_api import ServicesApi from openapi_client.models import ( Entity, EntityCreate, + Eventmessage, + EventmessageCreate, Machine, ServiceCreate, Status, @@ -76,3 +80,69 @@ def test_create_services(api_client: ApiClient) -> None: service_obj = create_service(idx + 4 * midx, entity) service = sapi.create_service(service_obj) assert service.uuid == service_obj.uuid + + +random.seed(77) + + +def create_eventmessages(num: int = 2) -> list[EventmessageCreate]: + res = [] + starttime = int(time.time()) + for i in range(num): + group_id = i % 5 + random.getrandbits(6) + em_req_send = EventmessageCreate( + id=random.getrandbits(18), + timestamp=starttime + i * 10, + group=i % 5, + group_id=group_id, + msg_type=1, + src_did=f"did:sov:test:12{i}", + des_did=f"did:sov:test:12{i+1}", + msg={}, + ) + res.append(em_req_send) + em_req_rec = EventmessageCreate( + id=random.getrandbits(18), + timestamp=starttime + (i * 10) + 2, + group=i % 5, + group_id=group_id, + msg_type=2, + src_did=f"did:sov:test:12{i}", + des_did=f"did:sov:test:12{i+1}", + msg={}, + ) + res.append(em_req_rec) + group_id = i % 5 + random.getrandbits(6) + em_res_send = EventmessageCreate( + id=random.getrandbits(18), + timestamp=starttime + i * 10 + 4, + group=i % 5, + group_id=group_id, + msg_type=3, + src_did=f"did:sov:test:12{i+1}", + des_did=f"did:sov:test:12{i}", + msg={}, + ) + res.append(em_res_send) + em_res_rec = EventmessageCreate( + id=random.getrandbits(6), + timestamp=starttime + (i * 10) + 8, + group=i % 5, + group_id=group_id, + msg_type=4, + src_did=f"did:sov:test:12{i+1}", + des_did=f"did:sov:test:12{i}", + msg={}, + ) + res.append(em_res_rec) + return res + + +def test_create_eventmessages(api_client: ApiClient) -> None: + api = EventmessagesApi(api_client=api_client) + assert [] == api.get_all_eventmessages() + for own_eventmsg in create_eventmessages(): + res: Eventmessage = api.create_eventmessage(own_eventmsg) + # breakpoint() + assert res.id == own_eventmsg.id + assert [] != api.get_all_eventmessages() -- 2.51.0 From 8fba3e6a5e02613e5dfbd2d10343c0104beddd6f Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 8 Jan 2024 20:19:07 +0100 Subject: [PATCH 2/2] add event msg with populate and the right table in swagger --- .../clan_cli/webui/routers/endpoints.py | 28 ++ pkgs/clan-cli/clan_cli/webui/schemas.py | 27 ++ pkgs/clan-cli/clan_cli/webui/sql_crud.py | 23 ++ pkgs/clan-cli/clan_cli/webui/sql_models.py | 29 +- pkgs/clan-cli/clan_cli/webui/tags.py | 5 + .../clan-cli/tests/openapi_client/__init__.py | 3 + .../tests/openapi_client/api/__init__.py | 1 + .../openapi_client/api/eventmessages_api.py | 339 ++++++++++++++++++ .../tests/openapi_client/docs/Eventmessage.md | 34 ++ .../openapi_client/docs/EventmessageCreate.md | 34 ++ .../openapi_client/docs/EventmessagesApi.md | 143 ++++++++ .../tests/openapi_client/models/__init__.py | 2 + .../openapi_client/models/eventmessage.py | 85 +++++ .../models/eventmessage_create.py | 85 +++++ .../openapi_client/test/test_eventmessage.py | 67 ++++ .../test/test_eventmessage_create.py | 67 ++++ .../test/test_eventmessages_api.py | 45 +++ pkgs/clan-cli/tests/test_db_api.py | 70 ++++ 18 files changed, 1079 insertions(+), 8 deletions(-) create mode 100644 pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py create mode 100644 pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md create mode 100644 pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md create mode 100644 pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md create mode 100644 pkgs/clan-cli/tests/openapi_client/models/eventmessage.py create mode 100644 pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py create mode 100644 pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py create mode 100644 pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py create mode 100644 pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py diff --git a/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py index 625d03b..6a16fda 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py @@ -12,6 +12,8 @@ from .. import sql_crud, sql_db, sql_models from ..schemas import ( Entity, EntityCreate, + Eventmessage, + EventmessageCreate, Resolution, Service, ServiceCreate, @@ -262,3 +264,29 @@ async def get_all_resolutions( id=1, ) ] + + +######################### +# # +# Eventmessage # +# # +######################### + + +@router.post("/api/v1/send_msg", response_model=Eventmessage, tags=[Tags.eventmessages]) +async def create_eventmessage( + eventmsg: EventmessageCreate, db: Session = Depends(sql_db.get_db) +) -> EventmessageCreate: + return sql_crud.create_eventmessage(db, eventmsg) + + +@router.get( + "/api/v1/event_messages", + response_model=List[Eventmessage], + tags=[Tags.eventmessages], +) +async def get_all_eventmessages( + skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db) +) -> List[sql_models.Eventmessage]: + eventmessages = sql_crud.get_eventmessages(db, skip=skip, limit=limit) + return eventmessages diff --git a/pkgs/clan-cli/clan_cli/webui/schemas.py b/pkgs/clan-cli/clan_cli/webui/schemas.py index f43e8dd..b3175f0 100644 --- a/pkgs/clan-cli/clan_cli/webui/schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/schemas.py @@ -104,3 +104,30 @@ class Resolution(ResolutionCreate): class Config: orm_mode = True + + +######################### +# # +# Eventmessage # +# # +######################### +class EventmessageBase(BaseModel): + id: int = Field(..., example=123456) + timestamp: int = Field(..., example=1234123413) + group: int = Field(..., example=1) # event group type (for the label) + group_id: int = Field( + ..., example=12345 + ) # specific to one group needed to enable visually nested groups + msg_type: int = Field(..., example=1) # message type for the label + src_did: str = Field(..., example="did:sov:test:2234") + des_did: str = Field(..., example="did:sov:test:1234") + + +class EventmessageCreate(EventmessageBase): + msg: dict = Field(..., example={"optinal": "values"}) # optional + pass + + +class Eventmessage(EventmessageCreate): + class Config: + orm_mode = True diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py index 3f5fdc0..64b968c 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_crud.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -136,3 +136,26 @@ def delete_entity_by_did(db: Session, did: str) -> None: def delete_entity_by_did_recursive(db: Session, did: str) -> None: delete_service_by_entity_did(db, did) delete_entity_by_did(db, did) + + +######################### +# # +# Eventmessage # +# # +######################### + + +def create_eventmessage( + db: Session, eventmsg: schemas.EventmessageCreate +) -> sql_models.Eventmessage: + db_eventmessage = sql_models.Eventmessage(**eventmsg.dict()) + db.add(db_eventmessage) + db.commit() + db.refresh(db_eventmessage) + return db_eventmessage + + +def get_eventmessages( + db: Session, skip: int = 0, limit: int = 100 +) -> List[sql_models.Eventmessage]: + return db.query(sql_models.Eventmessage).offset(skip).limit(limit).all() diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py index 792b8cc..742b237 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_models.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -1,11 +1,4 @@ -from sqlalchemy import ( - JSON, - Boolean, - Column, - ForeignKey, - String, - Text, -) +from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String, Text from sqlalchemy.orm import relationship from .sql_db import Base @@ -55,3 +48,23 @@ class Service(ServiceAbstract): # One entity can have many services entity = relationship("Entity", back_populates="services") entity_did = Column(String, ForeignKey("entities.did")) + + +class Eventmessage(Base): + __tablename__ = "eventmessages" + + ## Queryable body ## + id = Column(Integer, primary_key=True, index=True) + timestamp = Column(Integer, unique=True, index=True) + group = Column(Integer, index=True) + group_id = Column(Integer, index=True) + msg_type = Column(Integer, index=True) # message type for the label + src_did = Column(String, index=True) + des_did = Column(String, index=True) + + ## Non queryable body ## + # In here we deposit: Network, Roles, Visible, etc. + msg = Column(JSON) + + ## Relations ## + # One entity can send many messages diff --git a/pkgs/clan-cli/clan_cli/webui/tags.py b/pkgs/clan-cli/clan_cli/webui/tags.py index 712f09b..3d52367 100644 --- a/pkgs/clan-cli/clan_cli/webui/tags.py +++ b/pkgs/clan-cli/clan_cli/webui/tags.py @@ -7,6 +7,7 @@ class Tags(Enum): entities = "entities" repositories = "repositories" resolutions = "resolution" + eventmessages = "eventmessages" def __str__(self) -> str: return self.value @@ -29,4 +30,8 @@ tags_metadata: List[Dict[str, Any]] = [ "name": str(Tags.resolutions), "description": "Operations on a resolution.", }, + { + "name": str(Tags.eventmessages), + "description": "Operations for event messages.", + }, ] diff --git a/pkgs/clan-cli/tests/openapi_client/__init__.py b/pkgs/clan-cli/tests/openapi_client/__init__.py index 8263f8b..c30337b 100644 --- a/pkgs/clan-cli/tests/openapi_client/__init__.py +++ b/pkgs/clan-cli/tests/openapi_client/__init__.py @@ -19,6 +19,7 @@ __version__ = "1.0.0" # import apis into sdk package from openapi_client.api.default_api import DefaultApi from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.eventmessages_api import EventmessagesApi from openapi_client.api.repositories_api import RepositoriesApi from openapi_client.api.resolution_api import ResolutionApi from openapi_client.api.services_api import ServicesApi @@ -37,6 +38,8 @@ from openapi_client.exceptions import ApiException # import models into sdk package from openapi_client.models.entity import Entity from openapi_client.models.entity_create import EntityCreate +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate from openapi_client.models.http_validation_error import HTTPValidationError from openapi_client.models.machine import Machine from openapi_client.models.resolution import Resolution diff --git a/pkgs/clan-cli/tests/openapi_client/api/__init__.py b/pkgs/clan-cli/tests/openapi_client/api/__init__.py index 39c3f1b..87b34f9 100644 --- a/pkgs/clan-cli/tests/openapi_client/api/__init__.py +++ b/pkgs/clan-cli/tests/openapi_client/api/__init__.py @@ -3,6 +3,7 @@ # import apis into api package from openapi_client.api.default_api import DefaultApi from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.eventmessages_api import EventmessagesApi from openapi_client.api.repositories_api import RepositoriesApi from openapi_client.api.resolution_api import ResolutionApi from openapi_client.api.services_api import ServicesApi diff --git a/pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py b/pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py new file mode 100644 index 0000000..092ef36 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/api/eventmessages_api.py @@ -0,0 +1,339 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import re # noqa: F401 +import io +import warnings + +from pydantic import validate_arguments, ValidationError + +from pydantic import StrictInt + +from typing import List, Optional + +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate + +from openapi_client.api_client import ApiClient +from openapi_client.api_response import ApiResponse +from openapi_client.exceptions import ( # noqa: F401 + ApiTypeError, + ApiValueError +) + + +class EventmessagesApi: + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + def __init__(self, api_client=None) -> None: + if api_client is None: + api_client = ApiClient.get_default() + self.api_client = api_client + + @validate_arguments + def create_eventmessage(self, eventmessage_create : EventmessageCreate, **kwargs) -> Eventmessage: # noqa: E501 + """Create Eventmessage # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.create_eventmessage(eventmessage_create, async_req=True) + >>> result = thread.get() + + :param eventmessage_create: (required) + :type eventmessage_create: EventmessageCreate + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _request_timeout: timeout setting for this request. + If one number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: Eventmessage + """ + kwargs['_return_http_data_only'] = True + if '_preload_content' in kwargs: + message = "Error! Please call the create_eventmessage_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 + raise ValueError(message) + return self.create_eventmessage_with_http_info(eventmessage_create, **kwargs) # noqa: E501 + + @validate_arguments + def create_eventmessage_with_http_info(self, eventmessage_create : EventmessageCreate, **kwargs) -> ApiResponse: # noqa: E501 + """Create Eventmessage # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.create_eventmessage_with_http_info(eventmessage_create, async_req=True) + >>> result = thread.get() + + :param eventmessage_create: (required) + :type eventmessage_create: EventmessageCreate + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _preload_content: if False, the ApiResponse.data will + be set to none and raw_data will store the + HTTP response body without reading/decoding. + Default is True. + :type _preload_content: bool, optional + :param _return_http_data_only: response data instead of ApiResponse + object with status code, headers, etc + :type _return_http_data_only: bool, optional + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the authentication + in the spec for a single request. + :type _request_auth: dict, optional + :type _content_type: string, optional: force content-type for the request + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: tuple(Eventmessage, status_code(int), headers(HTTPHeaderDict)) + """ + + _params = locals() + + _all_params = [ + 'eventmessage_create' + ] + _all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout', + '_request_auth', + '_content_type', + '_headers' + ] + ) + + # validate the arguments + for _key, _val in _params['kwargs'].items(): + if _key not in _all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method create_eventmessage" % _key + ) + _params[_key] = _val + del _params['kwargs'] + + _collection_formats = {} + + # process the path parameters + _path_params = {} + + # process the query parameters + _query_params = [] + # process the header parameters + _header_params = dict(_params.get('_headers', {})) + # process the form parameters + _form_params = [] + _files = {} + # process the body parameter + _body_params = None + if _params['eventmessage_create'] is not None: + _body_params = _params['eventmessage_create'] + + # set the HTTP header `Accept` + _header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # set the HTTP header `Content-Type` + _content_types_list = _params.get('_content_type', + self.api_client.select_header_content_type( + ['application/json'])) + if _content_types_list: + _header_params['Content-Type'] = _content_types_list + + # authentication setting + _auth_settings = [] # noqa: E501 + + _response_types_map = { + '200': "Eventmessage", + '422': "HTTPValidationError", + } + + return self.api_client.call_api( + '/api/v1/send_msg', 'POST', + _path_params, + _query_params, + _header_params, + body=_body_params, + post_params=_form_params, + files=_files, + response_types_map=_response_types_map, + auth_settings=_auth_settings, + async_req=_params.get('async_req'), + _return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=_params.get('_preload_content', True), + _request_timeout=_params.get('_request_timeout'), + collection_formats=_collection_formats, + _request_auth=_params.get('_request_auth')) + + @validate_arguments + def get_all_eventmessages(self, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> List[Eventmessage]: # noqa: E501 + """Get All Eventmessages # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.get_all_eventmessages(skip, limit, async_req=True) + >>> result = thread.get() + + :param skip: + :type skip: int + :param limit: + :type limit: int + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _request_timeout: timeout setting for this request. + If one number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: List[Eventmessage] + """ + kwargs['_return_http_data_only'] = True + if '_preload_content' in kwargs: + message = "Error! Please call the get_all_eventmessages_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 + raise ValueError(message) + return self.get_all_eventmessages_with_http_info(skip, limit, **kwargs) # noqa: E501 + + @validate_arguments + def get_all_eventmessages_with_http_info(self, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> ApiResponse: # noqa: E501 + """Get All Eventmessages # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.get_all_eventmessages_with_http_info(skip, limit, async_req=True) + >>> result = thread.get() + + :param skip: + :type skip: int + :param limit: + :type limit: int + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _preload_content: if False, the ApiResponse.data will + be set to none and raw_data will store the + HTTP response body without reading/decoding. + Default is True. + :type _preload_content: bool, optional + :param _return_http_data_only: response data instead of ApiResponse + object with status code, headers, etc + :type _return_http_data_only: bool, optional + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the authentication + in the spec for a single request. + :type _request_auth: dict, optional + :type _content_type: string, optional: force content-type for the request + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: tuple(List[Eventmessage], status_code(int), headers(HTTPHeaderDict)) + """ + + _params = locals() + + _all_params = [ + 'skip', + 'limit' + ] + _all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout', + '_request_auth', + '_content_type', + '_headers' + ] + ) + + # validate the arguments + for _key, _val in _params['kwargs'].items(): + if _key not in _all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method get_all_eventmessages" % _key + ) + _params[_key] = _val + del _params['kwargs'] + + _collection_formats = {} + + # process the path parameters + _path_params = {} + + # process the query parameters + _query_params = [] + if _params.get('skip') is not None: # noqa: E501 + _query_params.append(('skip', _params['skip'])) + + if _params.get('limit') is not None: # noqa: E501 + _query_params.append(('limit', _params['limit'])) + + # process the header parameters + _header_params = dict(_params.get('_headers', {})) + # process the form parameters + _form_params = [] + _files = {} + # process the body parameter + _body_params = None + # set the HTTP header `Accept` + _header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # authentication setting + _auth_settings = [] # noqa: E501 + + _response_types_map = { + '200': "List[Eventmessage]", + '422': "HTTPValidationError", + } + + return self.api_client.call_api( + '/api/v1/event_messages', 'GET', + _path_params, + _query_params, + _header_params, + body=_body_params, + post_params=_form_params, + files=_files, + response_types_map=_response_types_map, + auth_settings=_auth_settings, + async_req=_params.get('async_req'), + _return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=_params.get('_preload_content', True), + _request_timeout=_params.get('_request_timeout'), + collection_formats=_collection_formats, + _request_auth=_params.get('_request_auth')) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md b/pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md new file mode 100644 index 0000000..cbe65cb --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/docs/Eventmessage.md @@ -0,0 +1,34 @@ +# Eventmessage + +## Properties + +| Name | Type | Description | Notes | +| ------------- | ---------- | ----------- | ----- | +| **id** | **int** | | +| **timestamp** | **int** | | +| **group** | **int** | | +| **group_id** | **int** | | +| **msg_type** | **int** | | +| **src_did** | **str** | | +| **des_did** | **str** | | +| **msg** | **object** | | + +## Example + +```python +from openapi_client.models.eventmessage import Eventmessage + +# TODO update the JSON string below +json = "{}" +# create an instance of Eventmessage from a JSON string +eventmessage_instance = Eventmessage.from_json(json) +# print the JSON string representation of the object +print Eventmessage.to_json() + +# convert the object into a dict +eventmessage_dict = eventmessage_instance.to_dict() +# create an instance of Eventmessage from a dict +eventmessage_form_dict = eventmessage.from_dict(eventmessage_dict) +``` + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md b/pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md new file mode 100644 index 0000000..eb6f16d --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/docs/EventmessageCreate.md @@ -0,0 +1,34 @@ +# EventmessageCreate + +## Properties + +| Name | Type | Description | Notes | +| ------------- | ---------- | ----------- | ----- | +| **id** | **int** | | +| **timestamp** | **int** | | +| **group** | **int** | | +| **group_id** | **int** | | +| **msg_type** | **int** | | +| **src_did** | **str** | | +| **des_did** | **str** | | +| **msg** | **object** | | + +## Example + +```python +from openapi_client.models.eventmessage_create import EventmessageCreate + +# TODO update the JSON string below +json = "{}" +# create an instance of EventmessageCreate from a JSON string +eventmessage_create_instance = EventmessageCreate.from_json(json) +# print the JSON string representation of the object +print EventmessageCreate.to_json() + +# convert the object into a dict +eventmessage_create_dict = eventmessage_create_instance.to_dict() +# create an instance of EventmessageCreate from a dict +eventmessage_create_form_dict = eventmessage_create.from_dict(eventmessage_create_dict) +``` + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md b/pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md new file mode 100644 index 0000000..d6affb9 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/docs/EventmessagesApi.md @@ -0,0 +1,143 @@ +# openapi_client.EventmessagesApi + +All URIs are relative to _http://localhost_ + +| Method | HTTP request | Description | +| ---------------------------------------------------------------------- | ------------------------------ | --------------------- | +| [**create_eventmessage**](EventmessagesApi.md#create_eventmessage) | **POST** /api/v1/send_msg | Create Eventmessage | +| [**get_all_eventmessages**](EventmessagesApi.md#get_all_eventmessages) | **GET** /api/v1/event_messages | Get All Eventmessages | + +# **create_eventmessage** + +> Eventmessage create_eventmessage(eventmessage_create) + +Create Eventmessage + +### Example + +```python +import time +import os +import openapi_client +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate +from openapi_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = openapi_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with openapi_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = openapi_client.EventmessagesApi(api_client) + eventmessage_create = openapi_client.EventmessageCreate() # EventmessageCreate | + + try: + # Create Eventmessage + api_response = api_instance.create_eventmessage(eventmessage_create) + print("The response of EventmessagesApi->create_eventmessage:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling EventmessagesApi->create_eventmessage: %s\n" % e) +``` + +### Parameters + +| Name | Type | Description | Notes | +| ----------------------- | ----------------------------------------------- | ----------- | ----- | +| **eventmessage_create** | [**EventmessageCreate**](EventmessageCreate.md) | | + +### Return type + +[**Eventmessage**](Eventmessage.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +| ----------- | ------------------- | ---------------- | +| **200** | Successful Response | - | +| **422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **get_all_eventmessages** + +> List[Eventmessage] get_all_eventmessages(skip=skip, limit=limit) + +Get All Eventmessages + +### Example + +```python +import time +import os +import openapi_client +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = openapi_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with openapi_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = openapi_client.EventmessagesApi(api_client) + skip = 0 # int | (optional) (default to 0) + limit = 100 # int | (optional) (default to 100) + + try: + # Get All Eventmessages + api_response = api_instance.get_all_eventmessages(skip=skip, limit=limit) + print("The response of EventmessagesApi->get_all_eventmessages:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling EventmessagesApi->get_all_eventmessages: %s\n" % e) +``` + +### Parameters + +| Name | Type | Description | Notes | +| --------- | ------- | ----------- | --------------------------- | +| **skip** | **int** | | [optional] [default to 0] | +| **limit** | **int** | | [optional] [default to 100] | + +### Return type + +[**List[Eventmessage]**](Eventmessage.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +| ----------- | ------------------- | ---------------- | +| **200** | Successful Response | - | +| **422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/models/__init__.py b/pkgs/clan-cli/tests/openapi_client/models/__init__.py index 4955602..4460d22 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/__init__.py +++ b/pkgs/clan-cli/tests/openapi_client/models/__init__.py @@ -16,6 +16,8 @@ # import models into model package from openapi_client.models.entity import Entity from openapi_client.models.entity_create import EntityCreate +from openapi_client.models.eventmessage import Eventmessage +from openapi_client.models.eventmessage_create import EventmessageCreate from openapi_client.models.http_validation_error import HTTPValidationError from openapi_client.models.machine import Machine from openapi_client.models.resolution import Resolution diff --git a/pkgs/clan-cli/tests/openapi_client/models/eventmessage.py b/pkgs/clan-cli/tests/openapi_client/models/eventmessage.py new file mode 100644 index 0000000..ece8617 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/models/eventmessage.py @@ -0,0 +1,85 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictInt, StrictStr + +class Eventmessage(BaseModel): + """ + Eventmessage + """ + id: StrictInt = Field(...) + timestamp: StrictInt = Field(...) + group: StrictInt = Field(...) + group_id: StrictInt = Field(...) + msg_type: StrictInt = Field(...) + src_did: StrictStr = Field(...) + des_did: StrictStr = Field(...) + msg: Dict[str, Any] = Field(...) + __properties = ["id", "timestamp", "group", "group_id", "msg_type", "src_did", "des_did", "msg"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Eventmessage: + """Create an instance of Eventmessage from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Eventmessage: + """Create an instance of Eventmessage from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return Eventmessage.parse_obj(obj) + + _obj = Eventmessage.parse_obj({ + "id": obj.get("id"), + "timestamp": obj.get("timestamp"), + "group": obj.get("group"), + "group_id": obj.get("group_id"), + "msg_type": obj.get("msg_type"), + "src_did": obj.get("src_did"), + "des_did": obj.get("des_did"), + "msg": obj.get("msg") + }) + return _obj + + diff --git a/pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py b/pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py new file mode 100644 index 0000000..34915bb --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/models/eventmessage_create.py @@ -0,0 +1,85 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictInt, StrictStr + +class EventmessageCreate(BaseModel): + """ + EventmessageCreate + """ + id: StrictInt = Field(...) + timestamp: StrictInt = Field(...) + group: StrictInt = Field(...) + group_id: StrictInt = Field(...) + msg_type: StrictInt = Field(...) + src_did: StrictStr = Field(...) + des_did: StrictStr = Field(...) + msg: Dict[str, Any] = Field(...) + __properties = ["id", "timestamp", "group", "group_id", "msg_type", "src_did", "des_did", "msg"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> EventmessageCreate: + """Create an instance of EventmessageCreate from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> EventmessageCreate: + """Create an instance of EventmessageCreate from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return EventmessageCreate.parse_obj(obj) + + _obj = EventmessageCreate.parse_obj({ + "id": obj.get("id"), + "timestamp": obj.get("timestamp"), + "group": obj.get("group"), + "group_id": obj.get("group_id"), + "msg_type": obj.get("msg_type"), + "src_did": obj.get("src_did"), + "des_did": obj.get("des_did"), + "msg": obj.get("msg") + }) + return _obj + + diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py new file mode 100644 index 0000000..21852d5 --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage.py @@ -0,0 +1,67 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from openapi_client.models.eventmessage import Eventmessage # noqa: E501 + +class TestEventmessage(unittest.TestCase): + """Eventmessage unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> Eventmessage: + """Test Eventmessage + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `Eventmessage` + """ + model = Eventmessage() # noqa: E501 + if include_optional: + return Eventmessage( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values} + ) + else: + return Eventmessage( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values}, + ) + """ + + def testEventmessage(self): + """Test Eventmessage""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py new file mode 100644 index 0000000..8bc282d --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessage_create.py @@ -0,0 +1,67 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from openapi_client.models.eventmessage_create import EventmessageCreate # noqa: E501 + +class TestEventmessageCreate(unittest.TestCase): + """EventmessageCreate unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> EventmessageCreate: + """Test EventmessageCreate + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `EventmessageCreate` + """ + model = EventmessageCreate() # noqa: E501 + if include_optional: + return EventmessageCreate( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values} + ) + else: + return EventmessageCreate( + id = 123456, + timestamp = 1234123413, + group = 1, + group_id = 12345, + msg_type = 1, + src_did = 'did:sov:test:2234', + des_did = 'did:sov:test:1234', + msg = {optinal=values}, + ) + """ + + def testEventmessageCreate(self): + """Test EventmessageCreate""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py new file mode 100644 index 0000000..e2841ab --- /dev/null +++ b/pkgs/clan-cli/tests/openapi_client/test/test_eventmessages_api.py @@ -0,0 +1,45 @@ +# coding: utf-8 + +""" + FastAPI + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from openapi_client.api.eventmessages_api import EventmessagesApi # noqa: E501 + + +class TestEventmessagesApi(unittest.TestCase): + """EventmessagesApi unit test stubs""" + + def setUp(self) -> None: + self.api = EventmessagesApi() # noqa: E501 + + def tearDown(self) -> None: + pass + + def test_create_eventmessage(self) -> None: + """Test case for create_eventmessage + + Create Eventmessage # noqa: E501 + """ + pass + + def test_get_all_eventmessages(self) -> None: + """Test case for get_all_eventmessages + + Get All Eventmessages # noqa: E501 + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index cf8f479..b619729 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -1,13 +1,17 @@ import random +import time import uuid from openapi_client import ApiClient from openapi_client.api import DefaultApi from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.eventmessages_api import EventmessagesApi from openapi_client.api.services_api import ServicesApi from openapi_client.models import ( Entity, EntityCreate, + Eventmessage, + EventmessageCreate, Machine, ServiceCreate, Status, @@ -70,3 +74,69 @@ def test_create_services(api_client: ApiClient) -> None: service_obj = create_service(idx + 4 * midx, entity) service = sapi.create_service(service_obj) assert service.uuid == service_obj.uuid + + +random.seed(77) + + +def create_eventmessages(num: int = 2) -> list[EventmessageCreate]: + res = [] + starttime = int(time.time()) + for i in range(num): + group_id = i % 5 + random.getrandbits(6) + em_req_send = EventmessageCreate( + id=random.getrandbits(18), + timestamp=starttime + i * 10, + group=i % 5, + group_id=group_id, + msg_type=1, + src_did=f"did:sov:test:12{i}", + des_did=f"did:sov:test:12{i+1}", + msg={}, + ) + res.append(em_req_send) + em_req_rec = EventmessageCreate( + id=random.getrandbits(18), + timestamp=starttime + (i * 10) + 2, + group=i % 5, + group_id=group_id, + msg_type=2, + src_did=f"did:sov:test:12{i}", + des_did=f"did:sov:test:12{i+1}", + msg={}, + ) + res.append(em_req_rec) + group_id = i % 5 + random.getrandbits(6) + em_res_send = EventmessageCreate( + id=random.getrandbits(18), + timestamp=starttime + i * 10 + 4, + group=i % 5, + group_id=group_id, + msg_type=3, + src_did=f"did:sov:test:12{i+1}", + des_did=f"did:sov:test:12{i}", + msg={}, + ) + res.append(em_res_send) + em_res_rec = EventmessageCreate( + id=random.getrandbits(6), + timestamp=starttime + (i * 10) + 8, + group=i % 5, + group_id=group_id, + msg_type=4, + src_did=f"did:sov:test:12{i+1}", + des_did=f"did:sov:test:12{i}", + msg={}, + ) + res.append(em_res_rec) + return res + + +def test_create_eventmessages(api_client: ApiClient) -> None: + api = EventmessagesApi(api_client=api_client) + assert [] == api.get_all_eventmessages() + for own_eventmsg in create_eventmessages(): + res: Eventmessage = api.create_eventmessage(own_eventmsg) + # breakpoint() + assert res.id == own_eventmsg.id + assert [] != api.get_all_eventmessages() -- 2.51.0