Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_event_timeline(self):
mock_response = create_mock_json('tests/resources/eventtimeline.json')
resource = resources.EventTimeline(**mock_response.json())
assert isinstance(resource, resources.EventTimeline)
assert resource.event_type_id == 1
def test_racecard(self):
rootdir = 'tests/resources/racecards'
racecards = []
for _, _, filenames in os.walk(rootdir):
for json_racecard in [fname for fname in filenames
if fname.startswith('racecards')]:
mock_response = create_mock_json(os.path.join(rootdir, json_racecard))
racecard = mock_response.json().get('result')
racecards.append(
resources.RaceCard(date_time_sent=self.DATE_TIME_SENT,
**racecard))
assert 0 < len(racecards)
assert all(isinstance(racecard, resources.RaceCard)
for racecard in racecards)
def test_list_race_details(self, mock_response):
mock = create_mock_json('tests/resources/list_race_details.json')
mock_response.return_value = (mock.json(), 1.5)
response = self.scores.list_race_details()
assert mock.json.call_count == 1
mock_response.assert_called_with('ScoresAPING/v1.0/listRaceDetails', {}, None)
assert isinstance(response[0], resources.RaceDetails)
assert len(response) == 475
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
def test_racedetails(self):
mock_response = create_mock_json('tests/resources/racedetails.json')
resource = resources.RaceDetails(**mock_response.json())
assert isinstance(resource, resources.RaceDetails)
def test_event_type_result(self):
mock_response = create_mock_json('tests/resources/list_event_types.json')
event_types = mock_response.json().get('result')
for event_type in event_types:
resource = resources.EventTypeResult(elapsed_time=self.ELAPSED_TIME,
**event_type)
assert resource.elapsed_time == self.ELAPSED_TIME
assert resource.market_count == event_type['marketCount']
assert resource.event_type.id == event_type['eventType']['id']
assert resource.event_type.name == event_type['eventType']['name']
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)
def list_incidents(self, update_keys, session=None, lightweight=None):
"""
Returns a list of incidents for the given events.
:param dict update_keys: The filter to select desired markets. All markets that match
the criteria in the filter are selected e.g. [{'eventId': '28205674', 'lastUpdateSequenceProcessed': 2}]
:param requests.session session: Requests session object
:param bool lightweight: If True will return dict not a resource
:rtype: list[resources.Incidents]
"""
params = clean_locals(locals())
method = '%s%s' % (self.URI, 'listIncidents')
(response, elapsed_time) = self.request(method, params, session)
return self.process_response(response, resources.Incidents, elapsed_time, lightweight)
def get_account_details(self, session=None, lightweight=None):
"""
Returns the details relating your account, including your discount
rate and Betfair point balance.
:param requests.session session: Requests session object
:param bool lightweight: If True will return dict not a resource
:rtype: resources.AccountDetails
"""
params = clean_locals(locals())
method = '%s%s' % (self.URI, 'getAccountDetails')
(response, elapsed_time) = self.request(method, params, session)
return self.process_response(response, resources.AccountDetails, elapsed_time, lightweight)
def list_event_types(self, filter=market_filter(), locale=None, session=None, lightweight=None):
"""
Returns a list of Event Types (i.e. Sports) associated with the markets
selected by the MarketFilter.
:param dict filter: The filter to select desired markets
:param str locale: The language used for the response
:param requests.session session: Requests session object
:param bool lightweight: If True will return dict not a resource
:rtype: list[resources.EventTypeResult]
"""
params = clean_locals(locals())
method = '%s%s' % (self.URI, 'listEventTypes')
(response, elapsed_time) = self.request(method, params, session)
return self.process_response(response, resources.EventTypeResult, elapsed_time, lightweight)