def test_offer_calls_market_method_and_publishes_response(self):

        payload = {
            "data":
            json.dumps({
                "seller": "mykonos",
                "energy": 12,
                "price": 32,
                "transaction_uuid": "trans_id"
            })
        }
        offer = Offer("o_id", now(), 32, 12, "o_seller")
        self.market.offer = MagicMock(return_value=offer)
        self.subscriber._offer(payload)
        sleep(0.01)
        self.subscriber.market.offer.assert_called_once_with(seller="mykonos",
                                                             energy=12,
                                                             price=32)
        self.subscriber.redis_db.publish.assert_called_once_with(
            "id/OFFER/RESPONSE",
            json.dumps({
                "status": "ready",
                "offer": offer.to_JSON_string(),
                "transaction_uuid": "trans_id"
            }))
 def test_accept_offer_calls_market_method_and_publishes_response(self):
     offer = Offer("o_id", now(), 12, 13, "o_seller")
     payload = {
         "data":
         json.dumps({
             "buyer": "mykonos",
             "energy": 12,
             "offer_or_id": offer.to_JSON_string(),
             "transaction_uuid": "trans_id"
         })
     }
     trade = Trade(id="trade_id",
                   time=now(),
                   offer=offer,
                   seller="trade_seller",
                   buyer="trade_buyer")
     self.market.accept_offer = MagicMock(return_value=trade)
     self.subscriber._accept_offer(payload)
     sleep(0.01)
     self.subscriber.market.accept_offer.assert_called_once_with(
         offer_or_id=offer, buyer="mykonos", energy=12)
     self.subscriber.redis_db.publish.assert_called_once_with(
         "id/ACCEPT_OFFER/RESPONSE",
         json.dumps({
             "status": "ready",
             "trade": trade.to_JSON_string(),
             "transaction_uuid": "trans_id"
         }))
    def test_delete_offer_calls_market_method_and_publishes_response(self):
        offer = Offer("o_id", now(), 32, 12, "o_seller")
        payload = {
            "data":
            json.dumps({
                "offer_or_id": offer.to_JSON_string(),
                "transaction_uuid": "trans_id"
            })
        }

        self.market.delete_offer = MagicMock(return_value=offer)
        self.subscriber._delete_offer(payload)
        self.subscriber.market.delete_offer.assert_called_once_with(
            offer_or_id=offer)
        self.subscriber.redis_db.publish.assert_called_once_with(
            "id/DELETE_OFFER/RESPONSE",
            json.dumps({
                "status": "ready",
                "transaction_uuid": "trans_id"
            }))