Beispiel #1
0
def test_message_from_dict():
    mocked_message_from_dict = message_from_dict({"some": "payload"},
                                                 {"some": "attributes"})

    assert mocked_message_from_dict.data == {"some": "payload"}
    assert mocked_message_from_dict.attributes == {"some": "attributes"}
    assert mocked_message_from_dict.publish_time
Beispiel #2
0
    def publish(
        self, topic: str, data: str, connection_id: str = "", **attrs: Any
    ) -> MessageFuture:

        if topic in self.subscriptions:
            self.subscriptions[topic](self.session, message_from_dict(json.loads(data)))
        self.topics_called[topic].call_count += 1
        self.topics_called[topic].call_list.append(data)
        self.topics_called[topic].calls.append(
            [data, {**attrs, "connection_id": connection_id}]
        )

        return MessageFuture()
def test_delete_by_connection_id_when_table_valid(mock_session):
    base_mock = Mock()
    metadata_mock = Mock()
    tables_mock = Mock()

    table_mock = Table("foo", MetaData(),
                       Column("connection_id", String(), primary_key=True))

    base_mock.metadata = metadata_mock
    metadata_mock.tables = tables_mock
    tables_mock.values.return_value = [table_mock]

    consumer = DeleteConnectionConsumer(base_mock)
    delete_message = message_from_dict({"connection_id": "test:123"})

    consumer.delete_by_connection_id(mock_session, delete_message, False)

    assert mock_session.execute.called
    assert mock_session.commit.called
def test_delete_by_connection_id_when_table_invalid(mock_session):
    base_mock = Mock()
    metadata_mock = Mock()
    tables_mock = Mock()

    table_mock = Mock()
    columns = Mock()

    table_mock.c = columns
    columns.get.side_effect = lambda c: None

    base_mock.metadata = metadata_mock
    metadata_mock.tables = tables_mock
    tables_mock.values.return_value = [table_mock]

    consumer = DeleteConnectionConsumer(base_mock)
    delete_message = message_from_dict({"connection_id": "test:123"})

    consumer.delete_by_connection_id(mock_session, delete_message, False)

    assert not mock_session.execute.called
    assert mock_session.commit.called