Beispiel #1
0
 def test_publish_event_converts_python_objects_to_json(self):
     offer = Offer("1", now(), 2, 3, "A")
     trade = Trade("2", now(), Offer("accepted", now(), 7, 8, "Z"), "B",
                   "C")
     new_offer = Offer("3", now(), 4, 5, "D")
     existing_offer = Offer("4", now(), 5, 6, "E")
     kwargs = {
         "offer": offer,
         "trade": trade,
         "new_offer": new_offer,
         "existing_offer": existing_offer
     }
     for dispatcher in [
             self.area.dispatcher.market_event_dispatcher,
             self.device1.dispatcher.market_event_dispatcher,
             self.device2.dispatcher.market_event_dispatcher
     ]:
         dispatcher.publish_event(dispatcher.area.uuid, MarketEvent.OFFER,
                                  **kwargs)
         assert dispatcher.redis.publish.call_count == 1
         payload = json.loads(
             dispatcher.redis.publish.call_args_list[0][0][1])
         assert isinstance(payload["kwargs"]["offer"], str)
         assert offer_from_JSON_string(payload["kwargs"]["offer"],
                                       offer.time) == offer
         assert isinstance(payload["kwargs"]["trade"], str)
         assert trade_from_JSON_string(payload["kwargs"]["trade"],
                                       trade.time) == trade
         assert isinstance(payload["kwargs"]["new_offer"], str)
         assert offer_from_JSON_string(payload["kwargs"]["new_offer"],
                                       new_offer.time) == new_offer
         assert isinstance(payload["kwargs"]["existing_offer"], str)
         assert offer_from_JSON_string(payload["kwargs"]["existing_offer"],
                                       existing_offer.time) == \
             existing_offer
Beispiel #2
0
    def sanitize_parameters(cls, data_dict):
        if "offer_or_id" in data_dict and data_dict["offer_or_id"] is not None:
            if isinstance(data_dict["offer_or_id"], str):
                data_dict["offer_or_id"] = offer_from_JSON_string(
                    data_dict["offer_or_id"])
        if "offer" in data_dict and data_dict["offer"] is not None:
            if isinstance(data_dict["offer"], str):
                data_dict["offer"] = offer_from_JSON_string(data_dict["offer"])

        return data_dict
Beispiel #3
0
 def _offer_response(self, payload):
     data = json.loads(payload["data"])
     # TODO: is this additional parsing needed?
     if isinstance(data, str):
         data = json.loads(data)
     if data["status"] == "ready":
         self.offer_buffer = offer_from_JSON_string(data["offer"])
         self.event_response_uuids.append(data["transaction_uuid"])
     else:
         raise D3ARedisException(
             f"Error when receiving response on channel {payload['channel']}:: "
             f"{data['exception']}:  {data['error_message']}")