Commits

Anonymous committed 14caa96 Draft

renamed default_marshalling --> json_marshalling

Comments (0)

Files changed (5)

araldo/marshalling/default_marshalling.py

-""" Default implemenation of marshalling/unmarshalling
-"""
-import json
-import jsonpickle
-from datetime import datetime
-from araldo.marshalling import MarshallingBase
-from araldo.message import Message
-
-JSONPICKLE_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
-
-
-class Marshalling(MarshallingBase):
-    """ Marhals/unmarshals to/from JSON
-    """
-    def __init__(self, **kwargs):
-        MarshallingBase.__init__(self)
-
-    @staticmethod
-    def plugin_id():
-        """ :return: ID of plugin
-        """
-        return "marshal-default"
-
-    def to_internal_format(self, message_str):
-        obj = json.loads(message_str)
-        # fix date
-        obj["creation_timestamp"] = datetime.strptime(
-            obj["creation_timestamp"], JSONPICKLE_TIMESTAMP_FORMAT)
-        return Message(**obj)
-
-    def to_external_format(self, message):
-        """ Serializes to JSON
-        """
-        return jsonpickle.encode(message, unpicklable=False)

araldo/marshalling/json_marshalling.py

+""" Default implemenation of marshalling/unmarshalling
+"""
+import json
+import jsonpickle
+from datetime import datetime
+from araldo.marshalling import MarshallingBase
+from araldo.message import Message
+
+JSONPICKLE_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
+
+
+class Marshalling(MarshallingBase):
+    """ Marhals/unmarshals to/from JSON
+    """
+    def __init__(self, **kwargs):
+        MarshallingBase.__init__(self)
+
+    @staticmethod
+    def plugin_id():
+        """ :return: ID of plugin
+        """
+        return "marshal-default"
+
+    def to_internal_format(self, message_str):
+        obj = json.loads(message_str)
+        # fix date
+        obj["creation_timestamp"] = datetime.strptime(
+            obj["creation_timestamp"], JSONPICKLE_TIMESTAMP_FORMAT)
+        return Message(**obj)
+
+    def to_external_format(self, message):
+        """ Serializes to JSON
+        """
+        return jsonpickle.encode(message, unpicklable=False)
     ],
     entry_points={
         "araldo.marshalling": [
-            "default-marshalling = araldo.marshalling.default_marshalling"
+            "default-marshalling = araldo.marshalling.json_marshalling"
         ]
     },
     classifiers=[

test/endpoint_websocket_test.py

 from geventwebsocket import WebSocketError
 from araldo.endpoints import websocket as sut
 from araldo.config import Config
-from araldo.marshalling import default_marshalling
+from araldo.marshalling import json_marshalling
 from araldo.message import Message
 
 
 @pytest.fixture
 def endpoint(config, queue, plugin_manager, valid_socket):
     with patch.object(sut.InOutBound, "_get_marshalling") as getm:
-        getm.return_value = default_marshalling.Marshalling()
+        getm.return_value = json_marshalling.Marshalling()
         result = sut.InOutBound(
             config=config,
             gevent_queue=queue,

test/marshalling_test.py

 import pytest
 import json
 from datetime import datetime
-from araldo.marshalling.default_marshalling import(
+from araldo.marshalling.json_marshalling import(
     Marshalling, JSONPICKLE_TIMESTAMP_FORMAT)
 from araldo.message import Message
 
 
 
 @pytest.fixture
-def default_marshalling():
+def json_marshalling():
     return Marshalling()
 
 
     )
 
 
-def test_instantiation(default_marshalling):
+def test_instantiation(json_marshalling):
     pass
 
 
-def test_to_internal_format(default_marshalling, message_str, timestamp):
-    message = default_marshalling.to_internal_format(message_str)
+def test_to_internal_format(json_marshalling, message_str, timestamp):
+    message = json_marshalling.to_internal_format(message_str)
     assert isinstance(message, Message)
     assert message.origin == "test_origin"
     assert message.destination == "test_destination"
     assert message.creation_timestamp == timestamp
 
 
-def test_to_external_format(default_marshalling, message, message_str):
-    message_str = default_marshalling.to_external_format(message)
+def test_to_external_format(json_marshalling, message, message_str):
+    message_str = json_marshalling.to_external_format(message)
     assert type(message_str) == str
     decoded = json.loads(message_str)
     assert decoded["origin"] == message.origin