Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions packages/components/src/components/SendOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const websocketSendOperationConfig = {
const methodName = toSnakeCase(operation.id());
const staticMethodName = `${methodName}_static`;
return {
nonStaticMethod: `async def ${methodName}(self, message):
nonStaticMethod: `def ${methodName}(self, message):
"""
Send a ${methodName} message using the WebSocket connection attached to this instance.

Expand All @@ -25,9 +25,9 @@ const websocketSendOperationConfig = {
Raises:
Exception: If sending fails or the socket is not connected.
"""
await self._send(message, self.ws_app)`,
self._send(message, self.ws_app)`,
staticMethod: `@staticmethod
async def ${staticMethodName}(message, socket):
def ${staticMethodName}(message, socket):
"""
Send a ${methodName} message using a provided WebSocket connection, without needing an instance.

Expand All @@ -38,7 +38,7 @@ async def ${staticMethodName}(message, socket):
Raises:
Exception: If sending fails or the socket is not connected.
"""
await ${clientName}._send(message, socket)`
${clientName}._send(message, socket)`
};
},
javascript: (operation, clientName) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports[`Testing of SendOperation function render js websockets without send ope

exports[`Testing of SendOperation function render websockets without send operations 1`] = `
"@staticmethod
async def send_user_signedup_static(message, socket):
def send_user_signedup_static(message, socket):
\\"\\"\\"
Send a send_user_signedup message using a provided WebSocket connection, without needing an instance.

Expand All @@ -75,9 +75,9 @@ exports[`Testing of SendOperation function render websockets without send operat
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await AccountServiceAPI._send(message, socket)
AccountServiceAPI._send(message, socket)

async def send_user_signedup(self, message):
def send_user_signedup(self, message):
\\"\\"\\"
Send a send_user_signedup message using the WebSocket connection attached to this instance.

Expand All @@ -87,5 +87,5 @@ exports[`Testing of SendOperation function render websockets without send operat
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await self._send(message, self.ws_app)"
self._send(message, self.ws_app)"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import { getMessageDiscriminatorsFromOperations } from '@asyncapi/generator-help
* @returns {React.Element|null} Rendered initialization code or null.
*/
export function ReceiveOperationsDiscriminators({ receiveOperations }) {
const hasOperations = Array.isArray(receiveOperations) && receiveOperations.length > 0;
if (!hasOperations) {
return null;
}

const operationDiscriminators = getMessageDiscriminatorsFromOperations(receiveOperations);
const operationDiscriminators = Array.isArray(receiveOperations) && receiveOperations.length > 0
? getMessageDiscriminatorsFromOperations(receiveOperations)
: [];
const serializedDiscriminators = JSON.stringify(operationDiscriminators);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function Send({ sendOperations }) {
{
`
@staticmethod
async def _send(message, socket):
def _send(message, socket):
"""
Internal helper to handle the actual sending logic.

Expand All @@ -24,7 +24,7 @@ async def _send(message, socket):
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
socket.send(message)
except Exception as e:
print("Error sending:", e)`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ exports[`Constructor component (integration with AsyncAPI document) renders with
self.outgoing_processors = [] # Callables to process outgoing messages
self._stop_event = threading.Event()

self.receive_operation_handlers = {}
self.receive_operation_discriminators = []



self.url = url"
Expand All @@ -37,6 +40,9 @@ exports[`Constructor component (integration with AsyncAPI document) renders with
self.outgoing_processors = [] # Callables to process outgoing messages
self._stop_event = threading.Event()

self.receive_operation_handlers = {}
self.receive_operation_discriminators = []



self.url = url"
Expand All @@ -62,6 +68,9 @@ exports[`Constructor component (integration with AsyncAPI document) renders with
self.outgoing_processors = [] # Callables to process outgoing messages
self._stop_event = threading.Event()
params = {}
self.receive_operation_handlers = {}
self.receive_operation_discriminators = []

heartbeat = heartbeat or os.getenv(\\"HEARTBEAT\\")
if heartbeat is not None:
params[\\"heartbeat\\"] = heartbeat
Expand Down Expand Up @@ -95,6 +104,9 @@ exports[`Constructor component (integration with AsyncAPI document) renders with
self.outgoing_processors = [] # Callables to process outgoing messages
self._stop_event = threading.Event()

self.receive_operation_handlers = {}
self.receive_operation_discriminators = []



self.url = url"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Requires component (integration with AsyncAPI document) renders correctly with null query 1`] = `
"import json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Testing of Send component render Send component with send operations 1`] = `
"@staticmethod
async def _send(message, socket):
def _send(message, socket):
\\"\\"\\"
Internal helper to handle the actual sending logic.

Expand All @@ -16,7 +16,7 @@ exports[`Testing of Send component render Send component with send operations 1`
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
socket.send(message)
except Exception as e:
print(\\"Error sending:\\", e)"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8752,7 +8752,7 @@ class HoppscotchClient:
self.receive_operation_discriminators.append(discriminator_entry)

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

Expand All @@ -8763,9 +8763,9 @@ class HoppscotchClient:
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await HoppscotchClient._send(message, socket)
HoppscotchClient._send(message, socket)

async def send_echo_message(self, message):
def send_echo_message(self, message):
\\"\\"\\"
Send a send_echo_message message using the WebSocket connection attached to this instance.

Expand All @@ -8775,10 +8775,10 @@ class HoppscotchClient:
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await self._send(message, self.ws_app)
self._send(message, self.ws_app)

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

Expand All @@ -8792,7 +8792,7 @@ class HoppscotchClient:
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
socket.send(message)
except Exception as e:
print(\\"Error sending:\\", e)

Expand Down Expand Up @@ -9133,7 +9133,7 @@ class HoppscotchEchoWebSocketClient:
self.receive_operation_discriminators.append(discriminator_entry)

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

Expand All @@ -9144,9 +9144,9 @@ class HoppscotchEchoWebSocketClient:
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await HoppscotchEchoWebSocketClient._send(message, socket)
HoppscotchEchoWebSocketClient._send(message, socket)

async def send_echo_message(self, message):
def send_echo_message(self, message):
\\"\\"\\"
Send a send_echo_message message using the WebSocket connection attached to this instance.

Expand All @@ -9156,10 +9156,10 @@ class HoppscotchEchoWebSocketClient:
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await self._send(message, self.ws_app)
self._send(message, self.ws_app)

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

Expand All @@ -9173,7 +9173,7 @@ class HoppscotchEchoWebSocketClient:
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
socket.send(message)
except Exception as e:
print(\\"Error sending:\\", e)

Expand Down Expand Up @@ -9314,6 +9314,9 @@ class PostmanEchoWebSocketClientClient:
self.outgoing_processors = [] # Callables to process outgoing messages
self._stop_event = threading.Event()

self.receive_operation_handlers = {}
self.receive_operation_discriminators = []



self.url = url
Expand Down Expand Up @@ -9429,7 +9432,7 @@ class PostmanEchoWebSocketClientClient:
handler(error)

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

Expand All @@ -9440,9 +9443,9 @@ class PostmanEchoWebSocketClientClient:
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await PostmanEchoWebSocketClientClient._send(message, socket)
PostmanEchoWebSocketClientClient._send(message, socket)

async def send_echo_message(self, message):
def send_echo_message(self, message):
\\"\\"\\"
Send a send_echo_message message using the WebSocket connection attached to this instance.

Expand All @@ -9452,10 +9455,10 @@ class PostmanEchoWebSocketClientClient:
Raises:
Exception: If sending fails or the socket is not connected.
\\"\\"\\"
await self._send(message, self.ws_app)
self._send(message, self.ws_app)

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

Expand All @@ -9469,7 +9472,7 @@ class PostmanEchoWebSocketClientClient:
try:
if isinstance(message, dict):
message = json.dumps(message)
await socket.send(message)
socket.send(message)
except Exception as e:
print(\\"Error sending:\\", e)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import sys
import os
import pytest
import asyncio
import websockets
import requests
import json
import threading
from websockets.sync.server import serve

module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../python/test/temp/snapshotTestResult/client_hoppscotch'))

Expand Down Expand Up @@ -43,8 +44,7 @@ def message_handler(message):
f"Expected message '{expected_message}' but got '{received_messages[0]}'"
)

@pytest.mark.asyncio
async def test_hoppscotch_client_sends_message():
def test_hoppscotch_client_sends_message():
port = 8083
expected_outgoing_message = "Sending acceptance test message to Microcks."

Expand All @@ -54,20 +54,33 @@ async def test_hoppscotch_client_sends_message():
"testEndpoint": "ws://websocket-acceptance-tester-py:8083/ws",
"runnerType": "ASYNC_API_SCHEMA",
"timeout": 30000,
"filteredOperations": ["RECEIVE handleEchoMessage"]
"filteredOperations": ["SEND handleEchoMessage"]
}

server_ready = threading.Event()
test_complete = threading.Event()

# Create WebSocket server handler
async def handler(websocket):
def handler(websocket):
###############
#
# Most improtant part of test where we test clients send message
# Most important part of test where we test clients send message
#
###############
await HoppscotchEchoWebSocketClient.send_echo_message_static(expected_outgoing_message, websocket)
HoppscotchEchoWebSocketClient.send_echo_message_static(expected_outgoing_message, websocket)

def run_server():
server = serve(handler, "0.0.0.0", port)
server_ready.set()
while not test_complete.is_set():
time.sleep(0.1)
server.shutdown()

# Start the WebSocket server
server = await websockets.serve(handler, port=port)
await asyncio.sleep(1) # Give server time to start
server_thread = threading.Thread(target=run_server, daemon=True)
server_thread.start()
server_ready.wait(timeout=5)
time.sleep(1) # Give server time to start

# Start test in Microcks
response = requests.post(microcks_test_endpoint, json=payload)
Expand All @@ -83,8 +96,9 @@ async def handler(websocket):
if result.get("success") is True:
success = True
break
await asyncio.sleep(2)
#await asyncio.sleep(1000)
server.close()
time.sleep(2)

test_complete.set()
server_thread.join(timeout=5)

assert success, f"Microcks test {test_id} did not succeed"