Skip to content

Commit

Permalink
Merge pull request #118 from muzzammilshahid/fix-UnSubscribe-UnRegister
Browse files Browse the repository at this point in the history
Correct names of 'Unregister' and 'Unsubscribe' messages
  • Loading branch information
muzzammilshahid authored Jul 6, 2024
2 parents 4c3213a + ca83c87 commit 8cee568
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 94 deletions.
6 changes: 3 additions & 3 deletions tests/broker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def test_unsubscribing_from_topic():
subscribe = messages.Subscribe(messages.SubscribeFields(1, topic_name))
broker.receive_message(details.session_id, subscribe)

unsubscribe = messages.UnSubscribe(messages.UnSubscribeFields(1, 1))
unsubscribe = messages.Unsubscribe(messages.UnsubscribeFields(1, 1))
message_with_recipient = broker.receive_message(details.session_id, unsubscribe)

assert message_with_recipient.recipient == 1
assert isinstance(message_with_recipient.message, messages.UnSubscribed)
assert isinstance(message_with_recipient.message, messages.Unsubscribed)

# Check subscription by topic
has_subscription = broker.has_subscription(topic_name)
Expand All @@ -74,7 +74,7 @@ def test_unsubscribing_from_topic():
assert str(exc.value) == "cannot unsubscribe, session 2 doesn't exist"

# Unsubscribe with invalid subscriptionID
invalid_unsubscribe = messages.UnSubscribe(messages.UnSubscribeFields(1, 2))
invalid_unsubscribe = messages.Unsubscribe(messages.UnsubscribeFields(1, 2))
with pytest.raises(ValueError) as exc:
broker.receive_message(1, invalid_unsubscribe)

Expand Down
8 changes: 4 additions & 4 deletions tests/dealer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_unregister_procedure_not_registered():
details = SessionDetails(1, "realm1", "authid", "authrole")
dealer.add_session(details)

unregister = messages.UnRegister(messages.UnRegisterFields(details.session_id, 1))
unregister = messages.Unregister(messages.UnregisterFields(details.session_id, 1))
with pytest.raises(ValueError) as exc:
dealer.receive_message(details.session_id, unregister)

Expand All @@ -126,10 +126,10 @@ def test_unregister_procedure():
register = messages.Register(messages.RegisterFields(1, procedure_name))
dealer.receive_message(details.session_id, register)

unregister = messages.UnRegister(messages.UnRegisterFields(2, 1))
unregister = messages.Unregister(messages.UnregisterFields(2, 1))
messages_with_recipient = dealer.receive_message(details.session_id, unregister)
assert messages_with_recipient.recipient == details.session_id
assert isinstance(messages_with_recipient.message, messages.UnRegistered)
assert isinstance(messages_with_recipient.message, messages.Unregistered)

# Check registration by procedure
has_registration = dealer.has_registration(procedure_name)
Expand All @@ -142,7 +142,7 @@ def test_unregister_procedure():
assert str(exc.value) == "cannot unregister, session 2 doesn't exist"

# Unregister with invalid registrationID
invalid_unregister = messages.UnRegister(messages.UnRegisterFields(3, 3))
invalid_unregister = messages.Unregister(messages.UnregisterFields(3, 3))
with pytest.raises(ValueError) as exc:
dealer.receive_message(details.session_id, invalid_unregister)

Expand Down
8 changes: 4 additions & 4 deletions tests/interoptests/messages/unregister_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from wampproto.serializers import JSONSerializer, CBORSerializer, MsgPackSerializer


def is_equal(msg1: messages.UnRegister, msg2: messages.UnRegister) -> bool:
def is_equal(msg1: messages.Unregister, msg2: messages.Unregister) -> bool:
return msg1.request_id == msg2.request_id and msg1.registration_id == msg2.registration_id


@pytest.mark.asyncio
async def test_json_serializer():
msg = messages.UnRegister(messages.UnRegisterFields(1, 1))
msg = messages.Unregister(messages.UnregisterFields(1, 1))
command = f"wampproto message unregister {msg.request_id} {msg.registration_id} --serializer json"

output = await run_command(command)
Expand All @@ -24,7 +24,7 @@ async def test_json_serializer():

@pytest.mark.asyncio
async def test_cbor_serializer():
msg = messages.UnRegister(messages.UnRegisterFields(1, 1))
msg = messages.Unregister(messages.UnregisterFields(1, 1))
command = f"wampproto message unregister {msg.request_id} {msg.registration_id} --serializer cbor --output hex"

output = await run_command(command)
Expand All @@ -38,7 +38,7 @@ async def test_cbor_serializer():

@pytest.mark.asyncio
async def test_msgpack_serializer():
msg = messages.UnRegister(messages.UnRegisterFields(1, 1))
msg = messages.Unregister(messages.UnregisterFields(1, 1))
command = f"wampproto message unregister {msg.request_id} {msg.registration_id} --serializer msgpack --output hex"

output = await run_command(command)
Expand Down
8 changes: 4 additions & 4 deletions tests/interoptests/messages/unregistered_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from wampproto.serializers import JSONSerializer, CBORSerializer, MsgPackSerializer


def is_equal(msg1: messages.UnRegistered, msg2: messages.UnRegistered) -> bool:
def is_equal(msg1: messages.Unregistered, msg2: messages.Unregistered) -> bool:
return msg1.request_id == msg2.request_id


@pytest.mark.asyncio
async def test_json_serializer():
msg = messages.UnRegistered(messages.UnRegisteredFields(1))
msg = messages.Unregistered(messages.UnregisteredFields(1))
command = f"wampproto message unregistered {msg.request_id} --serializer json"

output = await run_command(command)
Expand All @@ -24,7 +24,7 @@ async def test_json_serializer():

@pytest.mark.asyncio
async def test_cbor_serializer():
msg = messages.UnRegistered(messages.UnRegisteredFields(1))
msg = messages.Unregistered(messages.UnregisteredFields(1))
command = f"wampproto message unregistered {msg.request_id} --serializer cbor --output hex"

output = await run_command(command)
Expand All @@ -38,7 +38,7 @@ async def test_cbor_serializer():

@pytest.mark.asyncio
async def test_msgpack_serializer():
msg = messages.UnRegistered(messages.UnRegisteredFields(1))
msg = messages.Unregistered(messages.UnregisteredFields(1))
command = f"wampproto message unregistered {msg.request_id} --serializer msgpack --output hex"

output = await run_command(command)
Expand Down
8 changes: 4 additions & 4 deletions tests/interoptests/messages/unsubscribe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from wampproto.serializers import JSONSerializer, CBORSerializer, MsgPackSerializer


def is_equal(msg1: messages.UnSubscribe, msg2: messages.UnSubscribe) -> bool:
def is_equal(msg1: messages.Unsubscribe, msg2: messages.Unsubscribe) -> bool:
return msg1.request_id == msg2.request_id and msg1.subscription_id == msg2.subscription_id


@pytest.mark.asyncio
async def test_json_serializer():
msg = messages.UnSubscribe(messages.UnSubscribeFields(1, 1))
msg = messages.Unsubscribe(messages.UnsubscribeFields(1, 1))
command = f"wampproto message unsubscribe {msg.request_id} {msg.subscription_id} --serializer json"

output = await run_command(command)
Expand All @@ -24,7 +24,7 @@ async def test_json_serializer():

@pytest.mark.asyncio
async def test_cbor_serializer():
msg = messages.UnSubscribe(messages.UnSubscribeFields(1, 1))
msg = messages.Unsubscribe(messages.UnsubscribeFields(1, 1))
command = f"wampproto message unsubscribe {msg.request_id} {msg.subscription_id} --serializer cbor --output hex"

output = await run_command(command)
Expand All @@ -38,7 +38,7 @@ async def test_cbor_serializer():

@pytest.mark.asyncio
async def test_msgpack_serializer():
msg = messages.UnSubscribe(messages.UnSubscribeFields(1, 1))
msg = messages.Unsubscribe(messages.UnsubscribeFields(1, 1))
command = f"wampproto message unsubscribe {msg.request_id} {msg.subscription_id} --serializer msgpack --output hex"

output = await run_command(command)
Expand Down
8 changes: 4 additions & 4 deletions tests/interoptests/messages/unsubscribed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from wampproto.serializers import JSONSerializer, CBORSerializer, MsgPackSerializer


def is_equal(msg1: messages.UnSubscribed, msg2: messages.UnSubscribed) -> bool:
def is_equal(msg1: messages.Unsubscribed, msg2: messages.Unsubscribed) -> bool:
return msg1.request_id == msg2.request_id


@pytest.mark.asyncio
async def test_json_serializer():
msg = messages.UnSubscribed(messages.UnSubscribedFields(1))
msg = messages.Unsubscribed(messages.UnsubscribedFields(1))
command = f"wampproto message unsubscribed {msg.request_id} --serializer json"

output = await run_command(command)
Expand All @@ -24,7 +24,7 @@ async def test_json_serializer():

@pytest.mark.asyncio
async def test_cbor_serializer():
msg = messages.UnSubscribed(messages.UnSubscribedFields(1))
msg = messages.Unsubscribed(messages.UnsubscribedFields(1))
command = f"wampproto message unsubscribed {msg.request_id} --serializer cbor --output hex"

output = await run_command(command)
Expand All @@ -38,7 +38,7 @@ async def test_cbor_serializer():

@pytest.mark.asyncio
async def test_msgpack_serializer():
msg = messages.UnSubscribed(messages.UnSubscribedFields(1))
msg = messages.Unsubscribed(messages.UnsubscribedFields(1))
command = f"wampproto message unsubscribed {msg.request_id} --serializer msgpack --output hex"

output = await run_command(command)
Expand Down
34 changes: 17 additions & 17 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ def test_call_error(session: WAMPSession):


def test_unregister(session: WAMPSession, register_procedure):
# Send UnRegister message and receive UnRegistered message
unregister = messages.UnRegister(messages.UnRegisterFields(1, 1))
# Send Unregister message and receive Unregistered message
unregister = messages.Unregister(messages.UnregisterFields(1, 1))
to_send = session.send_message(unregister)
assert to_send == f"[{messages.UnRegister.TYPE}, {unregister.request_id}, {unregister.registration_id}]"
assert to_send == f"[{messages.Unregister.TYPE}, {unregister.request_id}, {unregister.registration_id}]"

unregistered = messages.UnRegistered(messages.UnRegisteredFields(1))
unregistered = messages.Unregistered(messages.UnregisteredFields(1))
received = session.receive_message(unregistered)
assert received == unregistered


def test_unregister_error(session: WAMPSession):
# Send UnRegister message and receive Error for that UnRegister
unregister = messages.UnRegister(messages.UnRegisterFields(3, 3))
# Send Unregister message and receive Error for that Unregister
unregister = messages.Unregister(messages.UnregisterFields(3, 3))
session.send_message(unregister)

unregister_err = messages.Error(
messages.ErrorFields(messages.UnRegister.TYPE, unregister.request_id, uris.INVALID_ARGUMENT)
messages.ErrorFields(messages.Unregister.TYPE, unregister.request_id, uris.INVALID_ARGUMENT)
)
received = session.receive_message(unregister_err)
assert received == unregister_err
Expand Down Expand Up @@ -126,22 +126,22 @@ def test_unsubscribe(session: WAMPSession):
# confirm subscribed
session.receive_message(messages.Subscribed(messages.SubscribedFields(7, 8)))

unsubscribe = messages.UnSubscribe(messages.UnSubscribeFields(8, 8))
unsubscribe = messages.Unsubscribe(messages.UnsubscribeFields(8, 8))
to_send = session.send_message(unsubscribe)
assert to_send == f"[{messages.UnSubscribe.TYPE}, {unsubscribe.request_id}, {unsubscribe.subscription_id}]"
assert to_send == f"[{messages.Unsubscribe.TYPE}, {unsubscribe.request_id}, {unsubscribe.subscription_id}]"

unsubscribed = messages.UnSubscribed(messages.UnSubscribedFields(8))
unsubscribed = messages.Unsubscribed(messages.UnsubscribedFields(8))
received = session.receive_message(unsubscribed)
assert received == unsubscribed


def test_unsubscribe_error(session: WAMPSession):
# Send UnSubscribe message and receive Error for that UnSubscribe
unsubscribe = messages.UnSubscribe(messages.UnSubscribeFields(8, 8))
# Send Unsubscribe message and receive Error for that Unsubscribe
unsubscribe = messages.Unsubscribe(messages.UnsubscribeFields(8, 8))
session.send_message(unsubscribe)

unsubscribe_error = messages.Error(
messages.ErrorFields(messages.UnSubscribe.TYPE, unsubscribe.request_id, uris.INVALID_URI)
messages.ErrorFields(messages.Unsubscribe.TYPE, unsubscribe.request_id, uris.INVALID_URI)
)
received = session.receive_message(unsubscribe_error)
assert received == unsubscribe_error
Expand Down Expand Up @@ -230,10 +230,10 @@ def test_exceptions():

assert str(exc.value) == f"received {messages.Error.TEXT} for invalid register request"

# Receive error invalid UnRegister id
# Receive error invalid Unregister id
with pytest.raises(ValueError) as exc:
session.receive_message(
messages.Error(messages.ErrorFields(messages.UnRegister.TYPE, 100, uris.INVALID_ARGUMENT))
messages.Error(messages.ErrorFields(messages.Unregister.TYPE, 100, uris.INVALID_ARGUMENT))
)

assert str(exc.value) == f"received {messages.Error.TEXT} for invalid unregister request"
Expand All @@ -246,10 +246,10 @@ def test_exceptions():

assert str(exc.value) == f"received {messages.Error.TEXT} for invalid subscribe request"

# Receive error invalid UnSubscribe id
# Receive error invalid Unsubscribe id
with pytest.raises(ValueError) as exc:
session.receive_message(
messages.Error(messages.ErrorFields(messages.UnSubscribe.TYPE, 100, uris.INVALID_ARGUMENT))
messages.Error(messages.ErrorFields(messages.Unsubscribe.TYPE, 100, uris.INVALID_ARGUMENT))
)

assert str(exc.value) == f"received {messages.Error.TEXT} for invalid unsubscribe request"
Expand Down
4 changes: 2 additions & 2 deletions wampproto/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def receive_message(self, session_id: int, message: messages.Message) -> types.M

subscribed = messages.Subscribed(messages.SubscribedFields(message.request_id, subscription.id))
return types.MessageWithRecipient(subscribed, session_id)
elif isinstance(message, messages.UnSubscribe):
elif isinstance(message, messages.Unsubscribe):
if session_id not in self.subscriptions_by_session:
raise ValueError(f"cannot unsubscribe, session {session_id} doesn't exist")

Expand All @@ -74,7 +74,7 @@ def receive_message(self, session_id: int, message: messages.Message) -> types.M

del self.subscriptions_by_session[session_id][message.subscription_id]

unsubscribed = messages.UnSubscribed(messages.UnSubscribedFields(message.request_id))
unsubscribed = messages.Unsubscribed(messages.UnsubscribedFields(message.request_id))
return types.MessageWithRecipient(unsubscribed, session_id)
else:
raise ValueError("message type not supported")
Expand Down
4 changes: 2 additions & 2 deletions wampproto/dealer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def receive_message(self, session_id: int, message: messages.Message) -> types.M

registered = messages.Registered(messages.RegisteredFields(message.request_id, registration.id))
return types.MessageWithRecipient(registered, session_id)
elif isinstance(message, messages.UnRegister):
elif isinstance(message, messages.Unregister):
registrations = self.registrations_by_session.get(session_id)
if registrations is None:
raise ValueError(f"cannot unregister, session {session_id} doesn't exist")
Expand All @@ -174,7 +174,7 @@ def receive_message(self, session_id: int, message: messages.Message) -> types.M

self.registrations_by_session[session_id] = registrations

unregistered = messages.UnRegistered(messages.UnRegisteredFields(message.request_id))
unregistered = messages.Unregistered(messages.UnregisteredFields(message.request_id))
return types.MessageWithRecipient(unregistered, session_id)
else:
raise ValueError("message type not supported")
24 changes: 12 additions & 12 deletions wampproto/messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from wampproto.messages.call import Call, CallFields
from wampproto.messages.register import Register, RegisterFields
from wampproto.messages.registered import Registered, RegisteredFields
from wampproto.messages.unregister import UnRegister, UnRegisterFields
from wampproto.messages.unregistered import UnRegistered, UnRegisteredFields
from wampproto.messages.unregister import Unregister, UnregisterFields
from wampproto.messages.unregistered import Unregistered, UnregisteredFields
from wampproto.messages.hello import Hello, HelloFields
from wampproto.messages.abort import Abort, AbortFields
from wampproto.messages.yield_ import Yield, YieldFields
Expand All @@ -18,8 +18,8 @@
from wampproto.messages.event import Event, EventFields
from wampproto.messages.subscribe import Subscribe, SubscribeFields
from wampproto.messages.subscribed import Subscribed, SubscribedFields
from wampproto.messages.unsubscribe import UnSubscribe, UnSubscribeFields
from wampproto.messages.unsubscribed import UnSubscribed, UnSubscribedFields
from wampproto.messages.unsubscribe import Unsubscribe, UnsubscribeFields
from wampproto.messages.unsubscribed import Unsubscribed, UnsubscribedFields
from wampproto.messages.error import Error, ErrorFields
from wampproto.messages.cancel import Cancel, CancelFields
from wampproto.messages.interrupt import Interrupt, InterruptFields
Expand Down Expand Up @@ -50,10 +50,10 @@
"RegisterFields",
"Registered",
"RegisteredFields",
"UnRegister",
"UnRegisterFields",
"UnRegistered",
"UnRegisteredFields",
"Unregister",
"UnregisterFields",
"Unregistered",
"UnregisteredFields",
"Publish",
"PublishFields",
"Published",
Expand All @@ -64,10 +64,10 @@
"SubscribeFields",
"Subscribed",
"SubscribedFields",
"UnSubscribe",
"UnSubscribeFields",
"UnSubscribed",
"UnSubscribedFields",
"Unsubscribe",
"UnsubscribeFields",
"Unsubscribed",
"UnsubscribedFields",
"Error",
"ErrorFields",
"Cancel",
Expand Down
Loading

0 comments on commit 8cee568

Please sign in to comment.