async def test_subscribe_warning(sm: SubscriptionManager):
    sm._logger.warning = Mock()

    send_mock = CoroutineMock()
    send_mock.return_value = 'some return value'
    sm._ds.send_message = send_mock

    sm._sub_payload = Mock()
    sub_payload_value = 'some value'
    sm._sub_payload.return_value = sub_payload_value

    sub = Subscription(category=Category.MARKET,
                       events=[MarketEvents.CANCELS, MarketEvents.ORDERS],
                       topics=['ETH_AURA', 'ETH_ZRX'])

    sm.subscriptions[sub.category] = {}

    result = await sm.subscribe(sub)

    sm._logger.warning.assert_called_once()

    sm._sub_payload.assert_called_once_with(Action.SUBSCRIBE,
                                            topics=sub.topics,
                                            events=sub.events)
    send_mock.assert_awaited_once_with(sub.category.value, sub_payload_value,
                                       None)
    assert result == 'some return value'
async def test_unsubscribe_rid(sm: SubscriptionManager):
    sm._ds.send_message = CoroutineMock(return_value='some return value')
    sm._sub_payload = Mock(return_value='some value')

    category = Category.MARKET

    result = await sm.unsubscribe(category, ['ETH_AURA'], 'some_rid')

    sm._sub_payload.assert_called_once_with(Action.UNSUBSCRIBE, ['ETH_AURA'])
    sm._ds.send_message.assert_awaited_once_with(category.value, 'some value',
                                                 'some_rid')

    assert result == 'some return value'
async def test_clear_rid(sm: SubscriptionManager):
    sm._ds.send_message = CoroutineMock(return_value='some return value')
    sm._sub_payload = Mock(return_value='some value')

    category = Category.MARKET

    result = await sm.clear(category, 'some_rid')

    sm._sub_payload.assert_called_once_with(Action.CLEAR)
    sm._ds.send_message.assert_awaited_once_with(category.value, 'some value',
                                                 'some_rid')

    assert result == 'some return value'
async def test_get(sm: SubscriptionManager):
    sm._ds.send_message = CoroutineMock(return_value='some return value')
    sm._sub_payload = Mock(return_value='some value')

    category = Category.MARKET

    result = await sm.get(category)

    sm._sub_payload.assert_called_once_with(Action.GET)
    sm._ds.send_message.assert_awaited_once_with(category.value, 'some value',
                                                 None)

    assert result == 'some return value'
def test_sub_payload(sm: SubscriptionManager):
    sm._filter_none = Mock(return_value='value')
    params = dict(action=Action.SUBSCRIBE,
                  topics=['ETH_AURA'],
                  events=MarketEvents.ORDERS)

    result = sm._sub_payload(**params)

    sm._filter_none.assert_called_once_with(
        dict(action=Action.SUBSCRIBE.value,
             topics=['ETH_AURA'],
             events=MarketEvents.ORDERS))

    assert result == 'value'