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 bbbf0aa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
9 changes: 9 additions & 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,15 @@ def everest_config_strategies(request) -> list[EverestConfigAdjustmentStrategy]:
additional_configuration_strategies.append(v)
return additional_configuration_strategies



@pytest.fixture
def central_system_port():
if external_central_system:
return 80
else
CentralSystem

@pytest.fixture
def everest_environment(request,
tmp_path,
Expand Down
30 changes: 26 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,29 @@ 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("on_connect not implemented!")
pass

@abstractmethod
async def wait_for_chargepoint(self, timeout=30, wait_for_bootnotification=True):
return None

@abstractmethod
async def start(self, ssl_context=None):
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 +158,7 @@ async def start(self, ssl_context=None):

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

pass # End LocalCentralSystem



Expand Down
5 changes: 3 additions & 2 deletions everest-testing/src/everest/testing/ocpp_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def ocpp_version(request) -> OCPPVersion:


@pytest.fixture
def ocpp_config(request, central_system: CentralSystem, test_config: OcppTestConfiguration, ocpp_version: OCPPVersion):
def ocpp_config(request, central_system: CentalSystem, test_config: OcppTestConfiguration, ocpp_version: OCPPVersion):
#def ocpp_config(request, central_system: CentralSystem, test_config: OcppTestConfiguration, ocpp_version: OCPPVersion):
ocpp_config_marker = request.node.get_closest_marker("ocpp_config")

ocpp_configuration_strategies_marker = request.node.get_closest_marker("ocpp_config_adaptions")
Expand All @@ -49,7 +50,7 @@ def ocpp_config(request, central_system: CentralSystem, test_config: OcppTestCon
ocpp_configuration_strategies.append(v)

return EverestEnvironmentOCPPConfiguration(
central_system_port=central_system.port,
central_system=central_system,
central_system_host="127.0.0.1",
ocpp_version=ocpp_version,
libocpp_path=Path(request.config.getoption("--libocpp")),
Expand Down

0 comments on commit bbbf0aa

Please sign in to comment.