-
-
Notifications
You must be signed in to change notification settings - Fork 382
test: add tests for RegisterReceiveOperation in python websocket component #1967
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
asyncapi-bot
merged 7 commits into
asyncapi:master
from
batchu5:test/add-tests-python-RegisterReceiveOperations-component
Feb 14, 2026
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b9c9a2d
test: add tests for RegisterReceiveOperation in python websocket comp…
batchu5 d358765
add explicit assertions for null-return cases
batchu5 33e9b9b
Merge branch 'master' into test/add-tests-python-RegisterReceiveOpera…
Adi-204 ff32ed7
remove unwanted tests
batchu5 c9c2b3a
Merge branch 'master' into test/add-tests-python-RegisterReceiveOpera…
batchu5 c79f983
Merge branch 'master' into test/add-tests-python-RegisterReceiveOpera…
batchu5 27ad187
Merge branch 'master' into test/add-tests-python-RegisterReceiveOpera…
Adi-204 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...ages/templates/clients/websocket/python/test/components/RegisterReceiveOperations.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import path from 'path'; | ||
| import { render } from '@asyncapi/generator-react-sdk'; | ||
| import { Parser, fromFile } from '@asyncapi/parser'; | ||
| import { RegisterReceiveOperations } from '../../components/RegisterReceiveOperations'; | ||
|
|
||
| const parser = new Parser(); | ||
| const asyncapiWebsocketQuery = path.resolve(__dirname, '../../../test/__fixtures__/asyncapi-websocket-components.yml'); | ||
|
|
||
| describe('Testing of RegisterReceiveOperations component', () => { | ||
| let parsedAsyncAPIDocument; | ||
|
|
||
| beforeAll(async () => { | ||
| const parseResult = await fromFile(parser, asyncapiWebsocketQuery).parse(); | ||
| parsedAsyncAPIDocument = parseResult.document; | ||
| expect(parsedAsyncAPIDocument).toBeDefined(); | ||
| }); | ||
|
|
||
| test('render RegisterReceiveOperations component with receive operations', () => { | ||
| const receiveOperations = parsedAsyncAPIDocument.operations().filterByReceive(); | ||
| const result = render(<RegisterReceiveOperations receiveOperations={receiveOperations} />); | ||
| const actual = result.trim(); | ||
| expect(actual).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders nothing when receive operations is empty', () => { | ||
| const result = render(<RegisterReceiveOperations receiveOperations={[]} />); | ||
| const actual = result.trim(); | ||
| expect(actual).toBe(''); | ||
| }); | ||
|
|
||
| test('renders nothing when receive operations is null', () => { | ||
| const result = render(<RegisterReceiveOperations receiveOperations={null} />); | ||
| const actual = result.trim(); | ||
| expect(actual).toBe(''); | ||
| }); | ||
|
|
||
| test('renders nothing without receive operations', () => { | ||
| const result = render(<RegisterReceiveOperations />); | ||
| const actual = result.trim(); | ||
| expect(actual).toBe(''); | ||
| }); | ||
|
|
||
| test('renders nothing when receiveOperations is undefined', () => { | ||
| const result = render(<RegisterReceiveOperations receiveOperations={undefined} />); | ||
| const actual = result.trim(); | ||
| expect(actual).toBe(''); | ||
| }); | ||
|
||
| }); | ||
83 changes: 83 additions & 0 deletions
83
...nts/websocket/python/test/components/__snapshots__/RegisterReceiveOperations.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Testing of RegisterReceiveOperations component render RegisterReceiveOperations component with receive operations 1`] = ` | ||
| "def register_receive_message_handler(self, handler, discriminator_key=None, discriminator_value=None): | ||
| \\"\\"\\" | ||
| Register a handler for receiveMessage operation. | ||
| Args: | ||
| handler (callable): Handler function that receives raw_message as argument | ||
| discriminator_key (str): Message field to use for routing (e.g., 'type', 'event_type') | ||
| discriminator_value (str): Expected value for routing (e.g., 'hello', 'user_joined') | ||
| \\"\\"\\" | ||
| if not callable(handler): | ||
| print(\\"Handler must be callable\\") | ||
| return | ||
| # Validate that either both discriminator_key and discriminator_value are provided or neither | ||
| if (discriminator_key is not None and discriminator_value is None) or (discriminator_key is None and discriminator_value is not None): | ||
| print(\\"Error: Both discriminator_key and discriminator_value must be provided together\\") | ||
| return | ||
| # Register handler | ||
| self.receive_operation_handlers[\\"receiveMessage\\"] = handler | ||
| # Add discriminator entry to the list if both key and value are provided | ||
| if discriminator_key is not None and discriminator_value is not None: | ||
| discriminator_entry = { | ||
| \\"key\\": discriminator_key, | ||
| \\"value\\": discriminator_value, | ||
| \\"operation_id\\": \\"receiveMessage\\" | ||
| } | ||
| # Check if this discriminator already exists | ||
| exists = any( | ||
| d.get(\\"key\\") == discriminator_key and | ||
| d.get(\\"value\\") == discriminator_value and | ||
| d.get(\\"operation_id\\") == \\"receiveMessage\\" | ||
| for d in self.receive_operation_discriminators | ||
| ) | ||
| if not exists: | ||
| self.receive_operation_discriminators.append(discriminator_entry) | ||
| def register_receive_notification_handler(self, handler, discriminator_key=None, discriminator_value=None): | ||
| \\"\\"\\" | ||
| Register a handler for receiveNotification operation. | ||
| Args: | ||
| handler (callable): Handler function that receives raw_message as argument | ||
| discriminator_key (str): Message field to use for routing (e.g., 'type', 'event_type') | ||
| discriminator_value (str): Expected value for routing (e.g., 'hello', 'user_joined') | ||
| \\"\\"\\" | ||
| if not callable(handler): | ||
| print(\\"Handler must be callable\\") | ||
| return | ||
| # Validate that either both discriminator_key and discriminator_value are provided or neither | ||
| if (discriminator_key is not None and discriminator_value is None) or (discriminator_key is None and discriminator_value is not None): | ||
| print(\\"Error: Both discriminator_key and discriminator_value must be provided together\\") | ||
| return | ||
| # Register handler | ||
| self.receive_operation_handlers[\\"receiveNotification\\"] = handler | ||
| # Add discriminator entry to the list if both key and value are provided | ||
| if discriminator_key is not None and discriminator_value is not None: | ||
| discriminator_entry = { | ||
| \\"key\\": discriminator_key, | ||
| \\"value\\": discriminator_value, | ||
| \\"operation_id\\": \\"receiveNotification\\" | ||
| } | ||
| # Check if this discriminator already exists | ||
| exists = any( | ||
| d.get(\\"key\\") == discriminator_key and | ||
| d.get(\\"value\\") == discriminator_value and | ||
| d.get(\\"operation_id\\") == \\"receiveNotification\\" | ||
| for d in self.receive_operation_discriminators | ||
| ) | ||
| if not exists: | ||
| self.receive_operation_discriminators.append(discriminator_entry)" | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed, you can remove it.