Source

araldo / test / raw_marshalling_test.py

Full commit
import pytest
from datetime import datetime
from araldo.marshalling import raw as sut
from araldo.message import Message


@pytest.fixture
def marshalling():
    return sut.Marshalling()


@pytest.fixture
def timestamp():
    return datetime(2012, 10, 1)


@pytest.fixture
def timestamp_str(timestamp):
    return str(timestamp)


@pytest.fixture
def payload():
    return "test_payload"


@pytest.fixture
def message_obj(payload, timestamp_str):
    return  {
        u"origin": u"test_origin",
        u"destination": u"test_destination",
        u"payload": u"test_payload",
        u"msg_id": u"test_msg_id",
        u"creation_timestamp": timestamp_str}


@pytest.fixture
def message_str(payload):
    return payload


def test_to_internal_format(marshalling, message_str, payload):
    message = marshalling.to_internal_format(message_str)
    assert message.origin is None
    assert message.destination is None
    assert message.payload == payload
    assert message.creation_timestamp.__class__ == datetime
    assert message.creation_timestamp is not None


def test_to_externam_format(marshalling, message_obj, message_str, payload):
    message = Message(**message_obj)
    serialized_message_str = marshalling.to_external_format(message)
    assert serialized_message_str == payload