Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions betfairlightweight/endpoints/inplayservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ def get_scores(
response_json, resources.Scores, elapsed_time, lightweight
)

def get_scores_and_broadcast(
self,
event_ids: list,
session: requests.Session = None,
lightweight: bool = None,
) -> Union[list, List[resources.ScoresAndBroadcast]]:
"""
Returns a list of scores and broadcast data based on
event id's supplied.

:param list event_ids: List of event id's to return
:param requests.session session: Requests session object
:param bool lightweight: If True will return dict not a resource

:rtype: list[resources.ScoresAndBroadcast]
"""
url = "%s%s" % (self.url, "scoresAndBroadcast")
params = {
"eventIds": ",".join(str(x) for x in event_ids),
"alt": "json",
"regionCode": "UK",
"locale": "en_GB",
}
(response, response_json, elapsed_time) = self.request(
params=params, session=session, url=url
)
return self.process_response(
response_json, resources.ScoresAndBroadcast, elapsed_time, lightweight
)

def request(
self,
method: str = None,
Expand Down
2 changes: 1 addition & 1 deletion betfairlightweight/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from .racecardresources import RaceCard

from .inplayserviceresources import EventTimeline, Scores
from .inplayserviceresources import EventTimeline, Scores, ScoresAndBroadcast

from .streamingresources import (
CricketMatch,
Expand Down
81 changes: 81 additions & 0 deletions tests/resources/scores_and_broadcast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"eventTypeId": 1,
"eventId": 28210051,
"score": {
"home": {
"name": "Boluspor",
"score": "0",
"halfTimeScore": "0",
"fullTimeScore": "",
"penaltiesScore": "",
"penaltiesSequence": [],
"games": "",
"sets": "",
"numberOfYellowCards": 1,
"numberOfRedCards": 0,
"numberOfCards": 1,
"numberOfCorners": 1,
"numberOfCornersFirstHalf": 0,
"numberOfCornersSecondHalf": 1,
"bookingPoints": 10
},
"away": {
"name": "Sanliurfaspor",
"score": "2",
"halfTimeScore": "1",
"fullTimeScore": "",
"penaltiesScore": "",
"penaltiesSequence": [],
"games": "",
"sets": "",
"numberOfYellowCards": 0,
"numberOfRedCards": 0,
"numberOfCards": 0,
"numberOfCorners": 2,
"numberOfCornersFirstHalf": 2,
"numberOfCornersSecondHalf": 0,
"bookingPoints": 0
},
"numberOfYellowCards": 1,
"numberOfRedCards": 0,
"numberOfCards": 1,
"numberOfCorners": 3,
"numberOfCornersFirstHalf": 2,
"numberOfCornersSecondHalf": 1,
"bookingPoints": 10
},
"timeElapsed": 78,
"elapsedRegularTime": 77,
"timeElapsedSeconds": 56,
"fullTimeElapsed": {
"hour": 0,
"min": 0,
"sec": 0
},
"status": "SecondHalfKickOff",
"matchStatus": "SecondHalfKickOff",
"broadcasts": [
{
"eventId": 28210051,
"hasLiveStreaming": true,
"hasLiveStreamingInfo": true,
"imgUrl": "https://example.com/img.png",
"overviewUrl": "https://example.com/overview",
"provider": "PROVIDER",
"providerName": "Provider Name",
"providerDisplayName": "Provider Display Name",
"channels": ["channel1", "channel2"]
}
],
"matchInfo": {
"eventId": 28210051,
"matchId": "12345",
"homeTeam": "Boluspor",
"awayTeam": "Sanliurfaspor",
"competition": "Turkish League",
"eventTypeId": 1,
"startTime": "2017-05-07T15:30:00.000Z",
"venue": "Stadium",
"inPlay": true
}
}
25 changes: 25 additions & 0 deletions tests/test_inplayservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ def test_get_scores(self, mock_request, mock_process_response):
assert mock_request.call_count == 1
assert mock_process_response.call_count == 1

@mock.patch(
"betfairlightweight.endpoints.inplayservice.InPlayService.process_response"
)
@mock.patch(
"betfairlightweight.endpoints.inplayservice.InPlayService.request",
return_value=(mock.Mock(), mock.Mock(), 1.3),
)
def test_get_scores_and_broadcast(self, mock_request, mock_process_response):
event_ids = [12345]
params = {
"eventIds": ",".join(str(x) for x in event_ids),
"alt": "json",
"regionCode": "UK",
"locale": "en_GB",
}
self.in_play_service.get_scores_and_broadcast(event_ids)

mock_request.assert_called_with(
url="https://ips.betfair.com/inplayservice/v1.1/scoresAndBroadcast",
session=None,
params=params,
)
assert mock_request.call_count == 1
assert mock_process_response.call_count == 1

@mock.patch("betfairlightweight.endpoints.inplayservice.check_status_code")
@mock.patch("betfairlightweight.endpoints.inplayservice.InPlayService.headers")
@mock.patch("betfairlightweight.baseclient.requests.get")
Expand Down
50 changes: 50 additions & 0 deletions tests/test_inplayserviceresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,53 @@ def test_event_timeline(self):

assert isinstance(resource, resources.EventTimeline)
assert resource.event_type_id == 1

def test_scores_and_broadcast(self):
mock_response = create_mock_json("tests/resources/scores_and_broadcast.json")
resource = resources.ScoresAndBroadcast(**mock_response.json())

assert isinstance(resource, resources.ScoresAndBroadcast)
assert resource.event_type_id == 1
assert resource.event_id == 28210051
assert resource.score is not None
assert resource.score.home.name == "Boluspor"
assert resource.score.away.name == "Sanliurfaspor"
assert resource.full_time_elapsed is not None
assert resource.status == "SecondHalfKickOff"
assert resource.match_status == "SecondHalfKickOff"
assert len(resource.broadcasts) == 1
assert resource.broadcasts[0].event_id == 28210051
assert resource.broadcasts[0].has_live_streaming is True
assert resource.broadcasts[0].has_live_streaming_info is True
assert resource.broadcasts[0].img_url == "https://example.com/img.png"
assert resource.broadcasts[0].overview_url == "https://example.com/overview"
assert resource.broadcasts[0].provider == "PROVIDER"
assert resource.broadcasts[0].provider_name == "Provider Name"
assert resource.broadcasts[0].provider_display_name == "Provider Display Name"
assert resource.broadcasts[0].channels == ["channel1", "channel2"]
assert resource.match_info is not None
assert resource.match_info.event_id == 28210051
assert resource.match_info.match_id == "12345"
assert resource.match_info.home_team == "Boluspor"
assert resource.match_info.away_team == "Sanliurfaspor"
assert resource.match_info.competition == "Turkish League"
assert resource.match_info.event_type_id == 1
assert resource.match_info.start_time is not None
assert resource.match_info.venue == "Stadium"
assert resource.match_info.in_play is True

def test_scores_and_broadcast_minimal(self):
"""Test ScoresAndBroadcast with minimal data (no broadcasts/matchInfo)."""
resource = resources.ScoresAndBroadcast(
eventId=123,
eventTypeId=1,
status="InProgress",
)

assert isinstance(resource, resources.ScoresAndBroadcast)
assert resource.event_id == 123
assert resource.event_type_id == 1
assert resource.score is None
assert resource.full_time_elapsed is None
assert resource.broadcasts == []
assert resource.match_info is None
Loading