Beispiel #1
0
class OrderStreamTest(unittest.TestCase):
    def setUp(self):
        self.listener = mock.Mock()
        self.stream = OrderStream(self.listener)

    @mock.patch("betfairlightweight.streaming.stream.OrderStream._process")
    @mock.patch("betfairlightweight.streaming.stream.OrderStream._update_clk")
    def test_on_subscribe(self, mock_update_clk, mock_process):
        self.stream.on_subscribe({})
        mock_update_clk.assert_called_once_with({})

        self.stream.on_subscribe({"oc": {123}})
        mock_process.assert_called_once_with({123}, None)

    @mock.patch("betfairlightweight.streaming.stream.OrderBookCache")
    @mock.patch("betfairlightweight.streaming.stream.OrderStream.on_process")
    def test_process(self, mock_on_process, mock_cache):
        sub_image = create_mock_json(
            "tests/resources/streaming_ocm_FULL_IMAGE.json")
        data = sub_image.json()["oc"]
        self.stream._process(data, 123)

        self.assertEqual(len(self.stream), len(data))

    def test_str(self):
        assert str(self.stream) == "OrderStream"

    def test_repr(self):
        assert repr(self.stream) == "<OrderStream [0]>"
Beispiel #2
0
class OrderStreamTest(unittest.TestCase):
    def setUp(self):
        self.listener = mock.Mock()
        self.stream = OrderStream(self.listener, 123)

    def test_init(self):
        assert self.stream._lookup == "oc"
        assert self.stream._name == "OrderStream"

    @mock.patch("betfairlightweight.streaming.stream.OrderStream._process")
    @mock.patch("betfairlightweight.streaming.stream.OrderStream._update_clk")
    def test_on_subscribe(self, mock_update_clk, mock_process):
        self.stream.on_subscribe({})
        mock_update_clk.assert_called_once_with({})
        self.stream.on_subscribe({"oc": {123}})
        mock_process.assert_called_once_with({123}, None)

    @mock.patch("betfairlightweight.streaming.stream.OrderBookCache")
    @mock.patch("betfairlightweight.streaming.stream.OrderStream.on_process")
    def test_process(self, mock_on_process, mock_cache):
        sub_image = create_mock_json(
            "tests/resources/streaming_ocm_FULL_IMAGE.json")
        data = sub_image.json()["oc"]
        self.assertTrue(self.stream._process(data, 123))
        self.assertEqual(len(self.stream), len(data))
        self.assertFalse(self.stream._process(data, 123))
        mock_on_process.assert_called_with([mock_cache()])

    @mock.patch("betfairlightweight.streaming.stream.OrderBookCache")
    @mock.patch("betfairlightweight.streaming.stream.OrderStream.on_process")
    def test_process_new_image(self, mock_on_process, mock_cache):
        self.stream._caches = {"1.161613698": mock.Mock()}
        sub_image = create_mock_json(
            "tests/resources/streaming_ocm_NEW_FULL_IMAGE.json")
        data = sub_image.json()["oc"]
        self.assertTrue(self.stream._process(data, 123))
        self.assertEqual(len(self.stream), len(data))
        self.assertTrue(self.stream._process(data, 123))

    @mock.patch("betfairlightweight.streaming.stream.OrderBookCache")
    @mock.patch("betfairlightweight.streaming.stream.OrderStream.on_process")
    def test_process_empty_image(self, mock_on_process, mock_cache):
        self.stream._caches = {"1.161613698": mock.Mock()}
        sub_image = create_mock_json(
            "tests/resources/streaming_ocm_EMPTY_IMAGE.json")
        data = sub_image.json()["oc"]
        self.assertTrue(self.stream._process(data, 123))
        self.assertEqual(len(self.stream), len(data))
        self.assertTrue(self.stream._process(data, 123))

    def test_str(self):
        assert str(self.stream) == "OrderStream"

    def test_repr(self):
        assert repr(self.stream) == "<OrderStream [0]>"