Skip to content

chore: add acceptance testing with microcks mocks #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ coverage

/.idea
temp
__pycache__
__pycache__

microcks-data
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ export function SendEchoMessage() {
return (
<Text newLines={2} indent={2}>
{
`// Method to send an echo message to the server
sendEchoMessage(message) {
`/**
* By default sends a message over a provided WebSocket connection.
* Useful when you already have an established WebSocket connection
* and want to send a message without creating a class instance.
*
* @param {Object} message - The message to send. It will be stringified to JSON.
* @param {WebSocket} socket - An existing WebSocket connection to use for sending the message.
*/
static sendEchoMessage(message, socket) {
if (socket) this.websocket = socket;
this.websocket.send(JSON.stringify(message));
console.log('Sent message to echo server:', message);
}`
}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ components:
summary: A message sent from server with current timestamp.
payload:
$ref: '#/components/schemas/currentTime'
examples:
- name: someRandomDate
payload: 11:13:24 GMT+0000 (Coordinated Universal Time)
echo:
summary: A message exchanged with the echo server.
payload: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ operations:
action: send
channel:
$ref: '#/channels/echo'

messages:
- $ref: '#/channels/echo/messages/echo'
reply:
channel:
$ref: '#/channels/echo'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ class HoppscotchEchoWebSocketClient {
if (cb) cb(message);
}

// Method to send an echo message to the server
sendEchoMessage(message) {
/**
* By default sends a message over a provided WebSocket connection.
* Useful when you already have an established WebSocket connection
* and want to send a message without creating a class instance.
*
* @param {Object} message - The message to send. It will be stringified to JSON.
* @param {WebSocket} socket - An existing WebSocket connection to use for sending the message.
*/
static sendEchoMessage(message, socket) {
if (socket) this.websocket = socket;
this.websocket.send(JSON.stringify(message));
console.log('Sent message to echo server:', message);
}

// Method to close the WebSocket connection
Expand Down Expand Up @@ -204,10 +211,17 @@ class PostmanEchoWebSocketClientClient {
if (cb) cb(message);
}

// Method to send an echo message to the server
sendEchoMessage(message) {
/**
* By default sends a message over a provided WebSocket connection.
* Useful when you already have an established WebSocket connection
* and want to send a message without creating a class instance.
*
* @param {Object} message - The message to send. It will be stringified to JSON.
* @param {WebSocket} socket - An existing WebSocket connection to use for sending the message.
*/
static sendEchoMessage(message, socket) {
if (socket) this.websocket = socket;
this.websocket.send(JSON.stringify(message));
console.log('Sent message to echo server:', message);
}

// Method to close the WebSocket connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,50 @@ export function SendEchoMessage() {
return (
<Text newLines={2} indent={2}>
{
`def send_message(self, message):
`async def send_message(self, message):
"""
Automatically process the outgoing message with registered processors and send it
using the active WebSocket connection.
Send a message using the WebSocket connection attached to this instance.

Args:
message (dict or str): The message to send. Will be serialized to JSON if it's a dictionary.

Raises:
Exception: If sending fails or the socket is not connected.
"""
await self._send(message, self.ws_app)

@staticmethod
async def send_message_static(message, socket):
"""
Send a message using a provided WebSocket connection, without needing an instance.

Args:
message (dict or str): The message to send.
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.

Raises:
Exception: If sending fails or the socket is not connected.
"""
await HoppscotchEchoWebSocketClient._send(message, socket)

@staticmethod
async def _send(message, socket):
"""
Internal helper to handle the actual sending logic.

Args:
message (dict or str): The message to send.
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.

Notes:
If message is a dictionary, it will be automatically converted to JSON.
"""
# Apply outgoing processors sequentially.
for processor in self.outgoing_processors:
message = processor(message)

if self.ws_app and self.ws_app.sock and self.ws_app.sock.connected:
try:
self.ws_app.send(json.dumps(message))
print("\\033[92mSent:\\033[0m", message)
except Exception as error:
self.handle_error(error)
else:
print("Error: WebSocket is not connected.")`
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
except Exception as e:
print("Error sending:", e)`
}
</Text>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,50 @@ class HoppscotchEchoWebSocketClient:
for handler in self.error_handlers:
handler(error)

def send_message(self, message):
async def send_message(self, message):
\\"\\"\\"
Automatically process the outgoing message with registered processors and send it
using the active WebSocket connection.
Send a message using the WebSocket connection attached to this instance.

Args:
message (dict or str): The message to send. Will be serialized to JSON if it's a dictionary.

Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
# Apply outgoing processors sequentially.
for processor in self.outgoing_processors:
message = processor(message)

if self.ws_app and self.ws_app.sock and self.ws_app.sock.connected:
try:
self.ws_app.send(json.dumps(message))
print(\\"\\\\033[92mSent:\\\\033[0m\\", message)
except Exception as error:
self.handle_error(error)
else:
print(\\"Error: WebSocket is not connected.\\")
await self._send(message, self.ws_app)

@staticmethod
async def send_message_static(message, socket):
\\"\\"\\"
Send a message using a provided WebSocket connection, without needing an instance.

Args:
message (dict or str): The message to send.
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.

Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await HoppscotchEchoWebSocketClient._send(message, socket)

@staticmethod
async def _send(message, socket):
\\"\\"\\"
Internal helper to handle the actual sending logic.

Args:
message (dict or str): The message to send.
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.

Notes:
If message is a dictionary, it will be automatically converted to JSON.
\\"\\"\\"
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
except Exception as e:
print(\\"Error sending:\\", e)

def close(self):
\\"\\"\\"Cleanly close the WebSocket connection.\\"\\"\\"
Expand Down Expand Up @@ -250,23 +277,50 @@ class PostmanEchoWebSocketClientClient:
for handler in self.error_handlers:
handler(error)

def send_message(self, message):
async def send_message(self, message):
\\"\\"\\"
Automatically process the outgoing message with registered processors and send it
using the active WebSocket connection.
Send a message using the WebSocket connection attached to this instance.

Args:
message (dict or str): The message to send. Will be serialized to JSON if it's a dictionary.

Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
# Apply outgoing processors sequentially.
for processor in self.outgoing_processors:
message = processor(message)

if self.ws_app and self.ws_app.sock and self.ws_app.sock.connected:
try:
self.ws_app.send(json.dumps(message))
print(\\"\\\\033[92mSent:\\\\033[0m\\", message)
except Exception as error:
self.handle_error(error)
else:
print(\\"Error: WebSocket is not connected.\\")
await self._send(message, self.ws_app)

@staticmethod
async def send_message_static(message, socket):
\\"\\"\\"
Send a message using a provided WebSocket connection, without needing an instance.

Args:
message (dict or str): The message to send.
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.

Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await HoppscotchEchoWebSocketClient._send(message, socket)

@staticmethod
async def _send(message, socket):
\\"\\"\\"
Internal helper to handle the actual sending logic.

Args:
message (dict or str): The message to send.
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.

Notes:
If message is a dictionary, it will be automatically converted to JSON.
\\"\\"\\"
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
except Exception as e:
print(\\"Error sending:\\", e)

def close(self):
\\"\\"\\"Cleanly close the WebSocket connection.\\"\\"\\"
Expand Down
Loading