class MarketsTest(unittest.TestCase): def setUp(self) -> None: self.markets = Markets() def test_init(self): self.assertEqual(self.markets._markets, {}) def test_add_market(self): mock_market = mock.Mock() self.markets.add_market("1.1", mock_market) self.assertEqual(self.markets._markets, {"1.1": mock_market}) def test_add_market_reopen(self): mock_market = mock.Mock() self.markets._markets = {"1.1": mock_market} self.markets.add_market("1.1", mock_market) self.assertEqual(self.markets._markets, {"1.1": mock_market}) mock_market.open_market.assert_called_with() def test_close_market(self): mock_market = mock.Mock() self.markets._markets = {"1.1": mock_market} self.markets.close_market("1.1") mock_market.close_market.assert_called_with() def test_remove_market(self): mock_market = mock.Mock() self.markets._markets = {"1.1": mock_market} self.markets.remove_market("1.1") self.assertEqual(self.markets._markets, {}) def test_get_order(self): mock_market = mock.Mock() mock_market.closed = False mock_market.blotter = {"test": 12} self.markets._markets = {"1.1": mock_market} self.assertEqual(self.markets.get_order("1.1", "test"), 12) self.assertIsNone(self.markets.get_order("1.2", "test")) def test_get_order_from_bet_id(self): mock_order = mock.Mock() mock_order.bet_id = "321" mock_market = mock.Mock() mock_market.closed = False mock_market.blotter.__iter__ = mock.Mock( return_value=iter([mock_order])) self.markets._markets = {"1.1": mock_market} self.assertEqual(self.markets.get_order_from_bet_id("1.1", "321"), mock_order) self.assertIsNone(self.markets.get_order("1.2", "test")) def test_markets(self): self.assertEqual(self.markets.markets, {}) mock_market = mock.Mock() mock_market_two = mock.Mock() self.markets._markets = {"1.1": mock_market, "2.1": mock_market_two} self.assertEqual(self.markets.markets, { "1.1": mock_market, "2.1": mock_market_two }) def test_open_market_ids(self): self.assertEqual(self.markets.open_market_ids, []) mock_market = mock.Mock() mock_market.closed = False mock_market_two = mock.Mock() mock_market_two.closed = True self.markets._markets = {"1.1": mock_market, "2.1": mock_market_two} self.assertEqual(self.markets.open_market_ids, [mock_market.market_id]) def test_live_orders(self): self.assertFalse(self.markets.live_orders) mock_market = mock.Mock() mock_market.closed = False mock_market.blotter.has_live_orders = True self.markets._markets = {"1.234": mock_market} self.assertTrue(self.markets.live_orders) mock_market.blotter.has_live_orders = False self.assertFalse(self.markets.live_orders) def test_iter(self): self.assertEqual(len([i for i in self.markets]), 0) def test_len(self): self.assertEqual(len(self.markets), 0)
class MarketsTest(unittest.TestCase): def setUp(self) -> None: self.markets = Markets() def test_init(self): self.assertEqual(self.markets._markets, {}) self.assertEqual(self.markets.events, {}) def test_add_market(self): mock_market = mock.Mock(event_id="1234") self.markets.add_market("1.1", mock_market) self.assertEqual(self.markets._markets, {"1.1": mock_market}) self.assertEqual(self.markets.events, {"1234": [mock_market]}) def test_add_market_no_event_id(self): mock_market = mock.Mock(event_id=None) self.markets.add_market("1.1", mock_market) self.assertEqual(self.markets._markets, {"1.1": mock_market}) self.assertEqual(self.markets.events, {}) def test_add_market_reopen(self): mock_market = mock.Mock() self.markets._markets = {"1.1": mock_market} self.markets.add_market("1.1", mock_market) self.assertEqual(self.markets._markets, {"1.1": mock_market}) mock_market.open_market.assert_called_with() def test_close_market(self): mock_market = mock.Mock() self.markets._markets = {"1.1": mock_market} self.markets.close_market("1.1") mock_market.close_market.assert_called_with() def test_remove_market(self): mock_market = mock.Mock(event_id=1234) self.markets._markets = {"1.1": mock_market} self.markets.events = {1234: [mock_market]} self.markets.remove_market("1.1") self.assertEqual(self.markets._markets, {}) self.assertEqual(self.markets.events, {1234: []}) def test_remove_market_no_event(self): mock_market = mock.Mock(event_id=1234) self.markets._markets = {"1.1": mock_market} self.markets.remove_market("1.1") self.assertEqual(self.markets._markets, {}) self.assertEqual(self.markets.events, {}) def test_get_order(self): mock_market = mock.Mock() mock_market.closed = False mock_market.blotter = {"test": 12} self.markets._markets = {"1.1": mock_market} self.assertEqual(self.markets.get_order("1.1", "test"), 12) self.assertIsNone(self.markets.get_order("1.2", "test")) def test_get_order_from_bet_id(self): mock_blotter = mock.Mock() mock_market = mock.Mock(closed=False, blotter=mock_blotter) self.markets._markets = {"1.1": mock_market} self.markets.get_order_from_bet_id("1.1", "321") mock_blotter.get_order_bet_id.assert_called_with("321") def test_markets(self): self.assertEqual(self.markets.markets, {}) mock_market = mock.Mock() mock_market_two = mock.Mock() self.markets._markets = {"1.1": mock_market, "2.1": mock_market_two} self.assertEqual( self.markets.markets, {"1.1": mock_market, "2.1": mock_market_two} ) def test_open_market_ids(self): self.assertEqual(self.markets.open_market_ids, []) mock_market = mock.Mock(status="OPEN") mock_market_two = mock.Mock(status="CLOSED") self.markets._markets = {"1.1": mock_market, "2.1": mock_market_two} self.assertEqual(self.markets.open_market_ids, [mock_market.market_id]) def test_live_orders(self): self.assertFalse(self.markets.live_orders) mock_market = mock.Mock() mock_market.closed = False mock_market.blotter.has_live_orders = True self.markets._markets = {"1.234": mock_market} self.assertTrue(self.markets.live_orders) mock_market.blotter.has_live_orders = False self.assertFalse(self.markets.live_orders) def test_iter(self): self.assertEqual(len([i for i in self.markets]), 0) def test_len(self): self.assertEqual(len(self.markets), 0)