Skip to content

Commit

Permalink
Refactor for abstract central system usage
Browse files Browse the repository at this point in the history
Signed-off-by: AssemblyJohn <[email protected]>
  • Loading branch information
AssemblyJohn committed Nov 11, 2024
1 parent 8ca7ba7 commit afa8463
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions everest-testing/src/everest/testing/core_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def everest_config_strategies(request) -> list[EverestConfigAdjustmentStrategy]:
additional_configuration_strategies.append(v)
return additional_configuration_strategies


@pytest.fixture
def everest_environment(request,
tmp_path,
Expand Down
32 changes: 28 additions & 4 deletions everest-testing/src/everest/testing/ocpp_utils/central_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ssl
import time
import logging
from abc import ABC, abstractmethod
from contextlib import asynccontextmanager
from functools import wraps
from typing import Union, Optional
Expand All @@ -24,10 +25,8 @@

logging.basicConfig(level=logging.debug)


class CentralSystem:

"""Wrapper for CSMS websocket server. Holds a reference to a single connected chargepoint
"""Base central system used for tests to connect
"""

def __init__(self, chargepoint_id, ocpp_version, port: Optional[int] = None):
Expand All @@ -39,6 +38,31 @@ def __init__(self, chargepoint_id, ocpp_version, port: Optional[int] = None):
self.chargepoint = None
self.chargepoint_set_event = asyncio.Event()
self.function_overrides = []

@abstractmethod
async def on_connect(self, websocket, path):
logging.error("'CentralSystem' did not implement 'on_connect'!")
pass

@abstractmethod
async def wait_for_chargepoint(self, timeout=30, wait_for_bootnotification=True):
logging.error("'CentralSystem' did not implement 'wait_for_chargepoint'!")
return None

@abstractmethod
async def start(self, ssl_context=None):
logging.error("'CentralSystem' did not implement 'start'!")
pass

pass # End CentralSystem

class LocalCentralSystem(CentralSystem):
"""Wrapper for CSMS websocket server. Holds a reference to a single connected chargepoint
"""

def __init__(self, chargepoint_id, ocpp_version, port: Optional[int] = None):
super().__init__(chargepoint_id, ocpp_version, port)
self.name = "LocalCentralSystem"

async def on_connect(self, websocket, path):
""" For every new charge point that connects, create a ChargePoint
Expand Down Expand Up @@ -136,7 +160,7 @@ async def start(self, ssl_context=None):

self.ws_server.close()
await self.ws_server.wait_closed()

pass # End LocalCentralSystem



Expand Down
12 changes: 9 additions & 3 deletions everest-testing/src/everest/testing/ocpp_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from everest.testing.core_utils.common import OCPPVersion
from everest.testing.core_utils._configuration.everest_environment_setup import EverestEnvironmentOCPPConfiguration
from everest.testing.core_utils.controller.everest_test_controller import EverestTestController
from everest.testing.ocpp_utils.central_system import CentralSystem, inject_csms_v201_mock, inject_csms_v16_mock, \
from everest.testing.ocpp_utils.central_system import CentralSystem, LocalCentralSystem, inject_csms_v201_mock, inject_csms_v16_mock, \
determine_ssl_context
from everest.testing.ocpp_utils.charge_point_utils import TestUtility, OcppTestConfiguration

Expand Down Expand Up @@ -66,8 +66,14 @@ async def central_system(request, ocpp_version: OCPPVersion, test_config):

ssl_context = determine_ssl_context(request, test_config)

cs = CentralSystem(test_config.charge_point_info.charge_point_id,
ocpp_version=ocpp_version)
central_system_marker = request.node.get_closest_marker('custom_central_system')

if central_system_marker:
assert isinstance(central_system_marker.args[0], CentralSystem)
cs = central_system_marker.args[0]
else:
cs = LocalCentralSystem(test_config.charge_point_info.charge_point_id,
ocpp_version=ocpp_version)

if request.node.get_closest_marker('inject_csms_mock'):
if ocpp_version == OCPPVersion.ocpp201:
Expand Down

0 comments on commit afa8463

Please sign in to comment.