ansible-collection-famedly-.../tests/unit/mock_nio/utils/ClientSimulator.py

22 lines
528 B
Python
Raw Normal View History

import json
from typing import List
class ClientSimulator:
2022-08-24 11:54:46 +00:00
INITIAL_DATA = {"rooms": []}
def __init__(self, data: str = json.dumps(INITIAL_DATA)):
try:
self.data = json.loads(data)
except (json.JSONDecodeError, TypeError):
self.data = self.INITIAL_DATA
def export(self) -> str:
return json.dumps(self.data)
def join(self, room_id: str):
2022-08-24 11:54:46 +00:00
self.data["rooms"].append(room_id)
def get_joined_rooms(self) -> List[str]:
2022-08-24 11:54:46 +00:00
return self.data["rooms"]