Example #1
0
class BettingTest(unittest.TestCase):
    def setUp(self):
        client = APIClient('username', 'password', 'app_key', 'UK')
        self.betting = Betting(client)

    # def test_set_next_hour(self):
    #     self.betting.set_next_hour()
    #     now = datetime.datetime.now()
    #     assert self.betting._next_hour == (now + datetime.timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
    #
    # def test_get_transaction_count(self):
    #     params = {'instructions': [1, 2, 3]}
    #     length = self.betting.get_transaction_count(params)
    #     assert length == 3
    #
    #     params = {}
    #     length = self.betting.get_transaction_count(params)
    #     assert length == 0
    #
    # def test_check_transaction_count(self):
    #     params = {'instructions': [1, 2, 3]}
    #     self.betting.check_transaction_count(params)
    #     assert self.betting.transaction_count == 3
    #
    #     now = datetime.datetime.now()
    #     self.betting._next_hour = (now + datetime.timedelta(hours=-1)).replace(minute=0, second=0, microsecond=0)
    #     params = {'instructions': [1, 2, 3]}
    #     self.betting.check_transaction_count(params)
    #     assert self.betting.transaction_count == 3
    #
    #     self.betting.transaction_limit = 2
    #     with self.assertRaises(TransactionCountError):
    #         self.betting.check_transaction_count(params)
    #     assert self.betting.transaction_count == 6

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_event_types(self, mock_response):
        mock = create_mock_json('tests/resources/list_event_types.json')
        mock_response.return_value = mock

        response = self.betting.list_event_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listEventTypes',
                                         None, None)
        assert isinstance(response[0], resources.EventTypeResult)
        assert len(response) == 2

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_competitions(self, mock_response):
        mock = create_mock_json('tests/resources/list_competitions.json')
        mock_response.return_value = mock

        response = self.betting.list_competitions()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCompetitions',
                                         None, None)
        assert isinstance(response[0], resources.CompetitionResult)
        assert len(response) == 22

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_time_ranges(self, mock_response):
        mock = create_mock_json('tests/resources/list_time_ranges.json')
        mock_response.return_value = mock

        response = self.betting.list_time_ranges()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listTimeRanges',
                                         None, None)
        assert isinstance(response[0], resources.TimeRangeResult)
        assert len(response) == 30

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_events(self, mock_response):
        mock = create_mock_json('tests/resources/list_events.json')
        mock_response.return_value = mock

        response = self.betting.list_events()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listEvents', None,
                                         None)
        assert isinstance(response[0], resources.EventResult)
        assert len(response) == 7

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_types(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_types.json')
        mock_response.return_value = mock

        response = self.betting.list_market_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketTypes',
                                         None, None)
        assert isinstance(response[0], resources.MarketTypeResult)
        assert len(response) == 25

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_countries(self, mock_response):
        mock = create_mock_json('tests/resources/list_countries.json')
        mock_response.return_value = mock

        response = self.betting.list_countries()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCountries',
                                         None, None)
        assert isinstance(response[0], resources.CountryResult)
        assert len(response) == 4

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_venues(self, mock_response):
        mock = create_mock_json('tests/resources/list_venues.json')
        mock_response.return_value = mock

        response = self.betting.list_venues()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listVenues', None,
                                         None)
        assert isinstance(response[0], resources.VenueResult)
        assert len(response) == 30

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_catalogue(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_catalogue.json')
        mock_response.return_value = mock

        response = self.betting.list_market_catalogue()
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            'SportsAPING/v1.0/listMarketCatalogue', None, None)
        assert isinstance(response[0], resources.MarketCatalogue)
        assert len(response) == 1

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_book(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_book.json')
        mock_response.return_value = mock

        response = self.betting.list_market_book()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketBook',
                                         None, None)
        assert isinstance(response[0], resources.MarketBook)
        assert len(response) == 1

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_current_orders(self, mock_response):
        mock = create_mock_json('tests/resources/list_current_orders.json')
        mock_response.return_value = mock

        response = self.betting.list_current_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCurrentOrders',
                                         None, None)
        assert isinstance(response, resources.CurrentOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_cleared_orders(self, mock_response):
        mock = create_mock_json('tests/resources/list_cleared_orders.json')
        mock_response.return_value = mock

        response = self.betting.list_cleared_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listClearedOrders',
                                         None, None)
        assert isinstance(response, resources.ClearedOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_place_orders(self, mock_response):
        mock = create_mock_json('tests/resources/place_orders.json')
        mock_response.return_value = mock

        response = self.betting.place_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/placeOrders', None,
                                         None)
        assert isinstance(response, resources.PlaceOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_cancel_orders(self, mock_response):
        mock = create_mock_json('tests/resources/cancel_orders.json')
        mock_response.return_value = mock

        response = self.betting.cancel_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/cancelOrders', None,
                                         None)
        assert isinstance(response, resources.CancelOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_update_orders(self, mock_response):
        mock = create_mock_json('tests/resources/update_orders.json')
        mock_response.return_value = mock

        response = self.betting.update_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/updateOrders', None,
                                         None)
        assert isinstance(response, resources.UpdateOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_replace_orders(self, mock_response):
        mock = create_mock_json('tests/resources/replace_orders.json')
        mock_response.return_value = mock

        response = self.betting.replace_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/replaceOrders',
                                         None, None)
        assert isinstance(response, resources.ReplaceOrders)
Example #2
0
class BettingTest(unittest.TestCase):

    def setUp(self):
        client = APIClient('username', 'password', 'app_key', 'UK')
        self.betting = Betting(client)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_event_types(self, mock_response):
        mock = create_mock_json('tests/resources/list_event_types.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_event_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listEventTypes', {'filter': {}}, None)
        assert isinstance(response[0], resources.EventTypeResult)
        assert len(response) == 2

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_competitions(self, mock_response):
        mock = create_mock_json('tests/resources/list_competitions.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_competitions()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCompetitions', {'filter': {}}, None)
        assert isinstance(response[0], resources.CompetitionResult)
        assert len(response) == 22

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_time_ranges(self, mock_response):
        mock = create_mock_json('tests/resources/list_time_ranges.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_time_ranges()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listTimeRanges', {'granularity': 'DAYS', 'filter': {}}, None)
        assert isinstance(response[0], resources.TimeRangeResult)
        assert len(response) == 30

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_events(self, mock_response):
        mock = create_mock_json('tests/resources/list_events.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_events()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listEvents', {'filter': {}}, None)
        assert isinstance(response[0], resources.EventResult)
        assert len(response) == 7

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_types(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_types.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_market_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketTypes', {'filter': {}}, None)
        assert isinstance(response[0], resources.MarketTypeResult)
        assert len(response) == 25

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_countries(self, mock_response):
        mock = create_mock_json('tests/resources/list_countries.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_countries()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCountries', {'filter': {}}, None)
        assert isinstance(response[0], resources.CountryResult)
        assert len(response) == 4

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_venues(self, mock_response):
        mock = create_mock_json('tests/resources/list_venues.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_venues()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listVenues', {'filter': {}}, None)
        assert isinstance(response[0], resources.VenueResult)
        assert len(response) == 30

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_catalogue(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_catalogue.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_market_catalogue()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketCatalogue', {'maxResults': 1, 'filter': {}}, None)
        assert isinstance(response[0], resources.MarketCatalogue)
        assert len(response) == 1

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_book(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_book.json')
        mock_response.return_value = (mock.json(), 1.3)
        marketIds = mock.Mock()

        response = self.betting.list_market_book(marketIds)
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketBook', {'marketIds': marketIds}, None)
        assert isinstance(response[0], resources.MarketBook)
        assert len(response) == 1

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_current_orders(self, mock_response):
        mock = create_mock_json('tests/resources/list_current_orders.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_current_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCurrentOrders', {'dateRange': {'from': None, 'to': None}}, None)
        assert isinstance(response, resources.CurrentOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_cleared_orders(self, mock_response):
        mock = create_mock_json('tests/resources/list_cleared_orders.json')
        mock_response.return_value = (mock.json(), 1.3)

        response = self.betting.list_cleared_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listClearedOrders', {'settledDateRange': {'to': None, 'from': None}, 'betStatus': 'SETTLED'}, None)
        assert isinstance(response, resources.ClearedOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_place_orders(self, mock_response):
        mock = create_mock_json('tests/resources/place_orders.json')
        mock_response.return_value = (mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.place_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/placeOrders',
                                         {'marketId': marketId, 'instructions': instructions}, None)
        assert isinstance(response, resources.PlaceOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_cancel_orders(self, mock_response):
        mock = create_mock_json('tests/resources/cancel_orders.json')
        mock_response.return_value = (mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.cancel_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/cancelOrders',
                                         {'marketId': marketId, 'instructions': instructions}, None)
        assert isinstance(response, resources.CancelOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_update_orders(self, mock_response):
        mock = create_mock_json('tests/resources/update_orders.json')
        mock_response.return_value = (mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.update_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/updateOrders',
                                         {'marketId': marketId, 'instructions': instructions}, None)
        assert isinstance(response, resources.UpdateOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_replace_orders(self, mock_response):
        mock = create_mock_json('tests/resources/replace_orders.json')
        mock_response.return_value = (mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.replace_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/replaceOrders',
                                         {'marketId': marketId, 'instructions': instructions}, None)
        assert isinstance(response, resources.ReplaceOrders)
class BettingTest(unittest.TestCase):

    def setUp(self):
        client = APIClient('username', 'password', 'app_key', 'UK')
        self.betting = Betting(client)

    # def test_set_next_hour(self):
    #     self.betting.set_next_hour()
    #     now = datetime.datetime.now()
    #     assert self.betting._next_hour == (now + datetime.timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
    #
    # def test_get_transaction_count(self):
    #     params = {'instructions': [1, 2, 3]}
    #     length = self.betting.get_transaction_count(params)
    #     assert length == 3
    #
    #     params = {}
    #     length = self.betting.get_transaction_count(params)
    #     assert length == 0
    #
    # def test_check_transaction_count(self):
    #     params = {'instructions': [1, 2, 3]}
    #     self.betting.check_transaction_count(params)
    #     assert self.betting.transaction_count == 3
    #
    #     now = datetime.datetime.now()
    #     self.betting._next_hour = (now + datetime.timedelta(hours=-1)).replace(minute=0, second=0, microsecond=0)
    #     params = {'instructions': [1, 2, 3]}
    #     self.betting.check_transaction_count(params)
    #     assert self.betting.transaction_count == 3
    #
    #     self.betting.transaction_limit = 2
    #     with self.assertRaises(TransactionCountError):
    #         self.betting.check_transaction_count(params)
    #     assert self.betting.transaction_count == 6

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_event_types(self, mock_response):
        mock = create_mock_json('tests/resources/list_event_types.json')
        mock_response.return_value = mock

        response = self.betting.list_event_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listEventTypes', None, None)
        assert isinstance(response[0], resources.EventTypeResult)
        assert len(response) == 2

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_competitions(self, mock_response):
        mock = create_mock_json('tests/resources/list_competitions.json')
        mock_response.return_value = mock

        response = self.betting.list_competitions()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCompetitions', None, None)
        assert isinstance(response[0], resources.CompetitionResult)
        assert len(response) == 22

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_time_ranges(self, mock_response):
        mock = create_mock_json('tests/resources/list_time_ranges.json')
        mock_response.return_value = mock

        response = self.betting.list_time_ranges()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listTimeRanges', None, None)
        assert isinstance(response[0], resources.TimeRangeResult)
        assert len(response) == 30

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_events(self, mock_response):
        mock = create_mock_json('tests/resources/list_events.json')
        mock_response.return_value = mock

        response = self.betting.list_events()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listEvents', None, None)
        assert isinstance(response[0], resources.EventResult)
        assert len(response) == 7

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_types(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_types.json')
        mock_response.return_value = mock

        response = self.betting.list_market_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketTypes', None, None)
        assert isinstance(response[0], resources.MarketTypeResult)
        assert len(response) == 25

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_countries(self, mock_response):
        mock = create_mock_json('tests/resources/list_countries.json')
        mock_response.return_value = mock

        response = self.betting.list_countries()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCountries', None, None)
        assert isinstance(response[0], resources.CountryResult)
        assert len(response) == 4

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_venues(self, mock_response):
        mock = create_mock_json('tests/resources/list_venues.json')
        mock_response.return_value = mock

        response = self.betting.list_venues()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listVenues', None, None)
        assert isinstance(response[0], resources.VenueResult)
        assert len(response) == 30

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_catalogue(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_catalogue.json')
        mock_response.return_value = mock

        response = self.betting.list_market_catalogue()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketCatalogue', None, None)
        assert isinstance(response[0], resources.MarketCatalogue)
        assert len(response) == 1

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_market_book(self, mock_response):
        mock = create_mock_json('tests/resources/list_market_book.json')
        mock_response.return_value = mock

        response = self.betting.list_market_book()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listMarketBook', None, None)
        assert isinstance(response[0], resources.MarketBook)
        assert len(response) == 1

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_current_orders(self, mock_response):
        mock = create_mock_json('tests/resources/list_current_orders.json')
        mock_response.return_value = mock

        response = self.betting.list_current_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listCurrentOrders', None, None)
        assert isinstance(response, resources.CurrentOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_list_cleared_orders(self, mock_response):
        mock = create_mock_json('tests/resources/list_cleared_orders.json')
        mock_response.return_value = mock

        response = self.betting.list_cleared_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/listClearedOrders', None, None)
        assert isinstance(response, resources.ClearedOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_place_orders(self, mock_response):
        mock = create_mock_json('tests/resources/place_orders.json')
        mock_response.return_value = mock

        response = self.betting.place_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/placeOrders', None, None)
        assert isinstance(response, resources.PlaceOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_cancel_orders(self, mock_response):
        mock = create_mock_json('tests/resources/cancel_orders.json')
        mock_response.return_value = mock

        response = self.betting.cancel_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/cancelOrders', None, None)
        assert isinstance(response, resources.CancelOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_update_orders(self, mock_response):
        mock = create_mock_json('tests/resources/update_orders.json')
        mock_response.return_value = mock

        response = self.betting.update_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/updateOrders', None, None)
        assert isinstance(response, resources.UpdateOrders)

    @mock.patch('betfairlightweight.endpoints.betting.Betting.request')
    def test_replace_orders(self, mock_response):
        mock = create_mock_json('tests/resources/replace_orders.json')
        mock_response.return_value = mock

        response = self.betting.replace_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with('SportsAPING/v1.0/replaceOrders', None, None)
        assert isinstance(response, resources.ReplaceOrders)
Example #4
0
class BettingTest(unittest.TestCase):
    def setUp(self):
        client = APIClient("username", "password", "app_key", "UK")
        self.betting = Betting(client)

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_event_types(self, mock_response):
        mock = create_mock_json("tests/resources/list_event_types.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_event_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listEventTypes",
                                         {"filter": {}}, None)
        assert isinstance(response[0], resources.EventTypeResult)
        assert len(response) == 2

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_competitions(self, mock_response):
        mock = create_mock_json("tests/resources/list_competitions.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_competitions()
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listCompetitions",
                                         {"filter": {}}, None)
        assert isinstance(response[0], resources.CompetitionResult)
        assert len(response) == 22

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_time_ranges(self, mock_response):
        mock = create_mock_json("tests/resources/list_time_ranges.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_time_ranges()
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/listTimeRanges",
            {
                "granularity": "DAYS",
                "filter": {}
            },
            None,
        )
        assert isinstance(response[0], resources.TimeRangeResult)
        assert len(response) == 30

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_events(self, mock_response):
        mock = create_mock_json("tests/resources/list_events.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_events()
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listEvents",
                                         {"filter": {}}, None)
        assert isinstance(response[0], resources.EventResult)
        assert len(response) == 7

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_market_types(self, mock_response):
        mock = create_mock_json("tests/resources/list_market_types.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_market_types()
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listMarketTypes",
                                         {"filter": {}}, None)
        assert isinstance(response[0], resources.MarketTypeResult)
        assert len(response) == 25

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_countries(self, mock_response):
        mock = create_mock_json("tests/resources/list_countries.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_countries()
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listCountries",
                                         {"filter": {}}, None)
        assert isinstance(response[0], resources.CountryResult)
        assert len(response) == 4

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_venues(self, mock_response):
        mock = create_mock_json("tests/resources/list_venues.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_venues()
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listVenues",
                                         {"filter": {}}, None)
        assert isinstance(response[0], resources.VenueResult)
        assert len(response) == 30

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_market_catalogue(self, mock_response):
        mock = create_mock_json("tests/resources/list_market_catalogue.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_market_catalogue()
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/listMarketCatalogue",
            {
                "maxResults": 1,
                "filter": {}
            },
            None,
        )
        assert isinstance(response[0], resources.MarketCatalogue)
        assert len(response) == 1

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_market_book(self, mock_response):
        mock = create_mock_json("tests/resources/list_market_book.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)
        marketIds = mock.Mock()

        response = self.betting.list_market_book(marketIds)
        assert mock.json.call_count == 1
        mock_response.assert_called_with("SportsAPING/v1.0/listMarketBook",
                                         {"marketIds": marketIds}, None)
        assert isinstance(response[0], resources.MarketBook)
        assert len(response) == 1

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_runner_book(self, mock_response):
        mock = create_mock_json("tests/resources/list_runner_book.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)
        marketId = mock.Mock()
        selectionId = mock.Mock()

        response = self.betting.list_runner_book(marketId, selectionId)
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/listRunnerBook",
            {
                "marketId": marketId,
                "selectionId": selectionId
            },
            None,
        )
        assert isinstance(response[0], resources.MarketBook)
        assert len(response) == 1

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_current_orders(self, mock_response):
        mock = create_mock_json("tests/resources/list_current_orders.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_current_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/listCurrentOrders",
            {"dateRange": {
                "from": None,
                "to": None
            }},
            None,
        )
        assert isinstance(response, resources.CurrentOrders)

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_list_cleared_orders(self, mock_response):
        mock = create_mock_json("tests/resources/list_cleared_orders.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)

        response = self.betting.list_cleared_orders()
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/listClearedOrders",
            {
                "settledDateRange": {
                    "to": None,
                    "from": None
                },
                "betStatus": "SETTLED"
            },
            None,
        )
        assert isinstance(response, resources.ClearedOrders)

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_place_orders(self, mock_response):
        mock = create_mock_json("tests/resources/place_orders.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.place_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/placeOrders",
            {
                "marketId": marketId,
                "instructions": instructions
            },
            None,
        )
        assert isinstance(response, resources.PlaceOrders)

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_cancel_orders(self, mock_response):
        mock = create_mock_json("tests/resources/cancel_orders.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.cancel_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/cancelOrders",
            {
                "marketId": marketId,
                "instructions": instructions
            },
            None,
        )
        assert isinstance(response, resources.CancelOrders)

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_update_orders(self, mock_response):
        mock = create_mock_json("tests/resources/update_orders.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.update_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/updateOrders",
            {
                "marketId": marketId,
                "instructions": instructions
            },
            None,
        )
        assert isinstance(response, resources.UpdateOrders)

    @mock.patch("betfairlightweight.endpoints.betting.Betting.request")
    def test_replace_orders(self, mock_response):
        mock = create_mock_json("tests/resources/replace_orders.json")
        mock_response.return_value = (mock.Mock(), mock.json(), 1.3)
        marketId = mock.Mock()
        instructions = mock.Mock()

        response = self.betting.replace_orders(marketId, instructions)
        assert mock.json.call_count == 1
        mock_response.assert_called_with(
            "SportsAPING/v1.0/replaceOrders",
            {
                "marketId": marketId,
                "instructions": instructions
            },
            None,
        )
        assert isinstance(response, resources.ReplaceOrders)