How to use get_fixture_by_id method in Slash

Best Python code snippet using slash

goals_aggregator_test.py

Source:goals_aggregator_test.py Github

copy

Full Screen

1import pytest2import pandas as pd3from datetime import datetime4from mock import MagicMock, Mock5from compiler.preprocessing.goals_aggregator import GoalsAggregator6from compiler.grpc.proto.fixture_pb2 import Fixture7from compiler.grpc.proto import result_pb28from compiler.grpc.fixture_client import FixtureClient9from compiler.grpc.ratings_client import RatingsClient10from compiler.grpc.result_client import ResultClient11from compiler.grpc.team_stats_client import TeamStatsClient12from compiler.grpc.proto import ratings_pb2, team_stats_pb213from google.protobuf.timestamp_pb2 import Timestamp14def test_for_season_data_frame_columns(match_goals):15 value = match_goals.result_client.get_results_for_season.return_value16 value.__iter__.return_value = iter([])17 df = match_goals.for_season(5, datetime.fromisoformat('2019-04-23T18:15:38+00:00'))18 match_goals.result_client.get_results_for_season.assert_called_with(19 season_id=5,20 date_before='2019-04-23T18:15:38+00:00'21 )22 columns = [23 'fixture_id',24 'season_id',25 'round',26 'date',27 'home_team',28 'home_goals',29 'home_xg',30 'home_shots_on_goal',31 'home_attack_points',32 'home_defence_points',33 'away_team',34 'away_goals',35 'away_xg',36 'away_shots_on_goal',37 'away_attack_points',38 'away_defence_points',39 ]40 assert (df.columns == columns).all()41def test_for_season_converts_result_object_into_data_frame_row(match_goals, rating_response, result, team_stats_response):42 value = match_goals.result_client.get_results_for_season.return_value43 value.__iter__.return_value = iter([result])44 match_goals.ratings_client.get_fixture_ratings.return_value = rating_response45 match_goals.team_stats_client.get_team_stats_for_fixture.return_value = team_stats_response46 df = match_goals.for_season(5, datetime.fromisoformat('2019-04-23T18:15:38+00:00'))47 match_goals.result_client.get_results_for_season.assert_called_with(48 season_id=5,49 date_before='2019-04-23T18:15:38+00:00'50 )51 match_goals.ratings_client.get_fixture_ratings.assert_called_with(fixture_id=66)52 expected = [53 66,54 39910,55 '4',56 pd.to_datetime(datetime.utcfromtimestamp(1556043338), format='%Y-%m-%dT%H:%M:%S'),57 'West Ham United',58 2,59 1.25,60 12,61 6.20,62 1.11,63 'Tottenham Hotspur',64 2,65 1,66 15,67 10,68 1.1169 ]70 assert df.iloc[0, :].values.tolist() == expected71def test_for_season_populates_multiple_rows_of_data_for_multiple_results(72 match_goals,73 rating_response,74 result,75 team_stats_response76):77 value = match_goals.result_client.get_results_for_season.return_value78 value.__iter__.return_value = iter([result, result, result])79 match_goals.ratings_client.get_fixture_ratings.return_value = rating_response80 match_goals.team_stats_client.get_team_stats_for_fixture.return_value = team_stats_response81 df = match_goals.for_season(5, datetime.fromisoformat('2019-04-23T18:15:38+00:00'))82 match_goals.result_client.get_results_for_season.assert_called_with(83 season_id=5,84 date_before='2019-04-23T18:15:38+00:00'85 )86 match_goals.ratings_client.get_fixture_ratings.assert_called_with(fixture_id=66)87 assert df.shape == (3, 16)88def test_for_season_raises_an_exception_if_an_issue_with_parsing_team_ratings(match_goals, result, team_stats_response):89 with pytest.raises(Exception):90 value = match_goals.result_client.get_results_for_season.return_value91 value.__iter__.return_value = iter([result])92 match_goals.ratings_client.get_fixture_ratings.return_value = rating_response93 match_goals.team_stats_client.get_team_stats_for_fixture.return_value = ratings_pb2.RatingResponse(94 ratings=[95 ratings_pb2.TeamRating(96 team_id=7901,97 fixture_id=5,98 season_id=18378,99 attack=ratings_pb2.Points(100 points=13.87,101 difference=6.20,102 ),103 defence=ratings_pb2.Points(104 points=2.08,105 difference=1.11,106 ),107 fixture_date=Timestamp(seconds=1660228999),108 timestamp=Timestamp(seconds=1660228999),109 ),110 ]111 )112 match_goals.for_season(5, datetime.fromisoformat('2019-04-23T18:15:38+00:00'))113def test_for_fixture_data_frame_columns(match_goals, fixture):114 match_goals.fixture_client.get_fixture_by_id.return_value = fixture115 fixture, df = match_goals.for_fixture(fixture_id=66)116 match_goals.fixture_client.get_fixture_by_id.assert_called_with(fixture_id=66)117 columns = [118 'fixture_id',119 'season_id',120 'round',121 'date',122 'home_team',123 'home_goals',124 'home_xg',125 'home_shots_on_goal',126 'home_attack_points',127 'home_defence_points',128 'away_team',129 'away_goals',130 'away_xg',131 'away_shots_on_goal',132 'away_attack_points',133 'away_defence_points',134 ]135 assert (columns == df.columns).all()136 assert df.shape == (1, 16)137def test_for_fixture_returns_data_frame_of_collated_fixture_data(match_goals, fixture):138 match_goals.fixture_client.get_fixture_by_id.return_value = fixture139 fixture, df = match_goals.for_fixture(fixture_id=66)140 match_goals.fixture_client.get_fixture_by_id.assert_called_with(fixture_id=66)141 row = df.iloc[0, :]142 assert row['fixture_id'] == 66143 assert row['season_id'] == 39910144 assert row['round'] == '4'145 assert row['date'] == pd.to_datetime(datetime.utcfromtimestamp(1556043338), format='%Y-%m-%dT%H:%M:%S')146 assert row['home_team'] == 'West Ham United'147 assert row['away_team'] == 'Tottenham Hotspur'148def test_for_fixture_raises_exception_if_unable_to_retrieve_fixture(match_goals):149 match_goals.fixture_client.get_fixture_by_id.side_effect = Exception()150 with pytest.raises(Exception):151 match_goals.for_fixture(fixture_id=66)152def test_for_fixture_returns_fixture_and_data_frame(match_goals, fixture):153 match_goals.fixture_client.get_fixture_by_id.return_value = fixture154 fixture, df = match_goals.for_fixture(fixture_id=66)155 match_goals.fixture_client.get_fixture_by_id.assert_called_with(fixture_id=66)156 assert fixture.id == 66157 assert fixture.season.name == '2018/19'158 assert fixture.round.name == '4'159 assert fixture.season.id == 39910160 assert fixture.season.is_current.value == True161 assert fixture.date_time.utc == 1556043338162 assert fixture.home_team.name == 'West Ham United'163 assert fixture.away_team.name == 'Tottenham Hotspur'164@pytest.fixture()165def match_goals():166 fixture_client = MagicMock(spec=FixtureClient)167 ratings_client = MagicMock(spec=RatingsClient)168 result_client = MagicMock(spec=ResultClient)169 team_stats_client = Mock(spec=TeamStatsClient)170 aggregator = GoalsAggregator(171 fixture_client=fixture_client,172 ratings_client=ratings_client,173 result_client=result_client,174 team_stats_client=team_stats_client175 )176 return aggregator177@pytest.fixture()178def result():179 result = result_pb2.Result()180 result.id = 66181 result.season.name = '2018/19'182 result.round.name = '4'183 result.season.id = 39910184 result.season.is_current.value = True185 result.date_time.utc = 1556043338186 result.home_team.id = 7901187 result.home_team.name = 'West Ham United'188 result.away_team.id = 496189 result.away_team.name = 'Tottenham Hotspur'190 result.stats.home_formation.value = '4-4-2'191 result.stats.away_formation.value = '5-3-1-1'192 result.stats.home_score.value = 2193 result.stats.away_score.value = 2194 return result195@pytest.fixture()196def home_past_result():197 result = result_pb2.Result()198 result.date_time.utc = 1555761600199 result.home_team.id = 7901200 result.home_team.name = 'West Ham United'201 result.away_team.id = 496202 result.away_team.name = 'Tottenham Hotspur'203 result.stats.home_score.value = 5204 result.stats.away_score.value = 2205 return result206@pytest.fixture()207def away_past_result():208 result = result_pb2.Result()209 result.date_time.utc = 1555549200210 result.home_team.id = 496211 result.home_team.name = 'Manchester City'212 result.way_team.id = 7901213 result.away_team.name = 'Liverpool'214 result.stats.home_score.value = 1215 result.stats.away_score.value = 3216 return result217@pytest.fixture218def team_stats_response():219 response = team_stats_pb2.TeamStatsResponse()220 response.home_team.shots_total.value = 34221 response.home_team.shots_on_goal.value = 12222 response.away_team.shots_total.value = 26223 response.away_team.shots_on_goal.value = 15224 response.team_xg.home.value = 1.25225 response.team_xg.away.value = 1226 return response227@pytest.fixture()228def fixture():229 fixture = Fixture()230 fixture.id = 66231 fixture.season.name = '2018/19'232 fixture.round.name = '4'233 fixture.season.id = 39910234 fixture.season.is_current.value = True235 fixture.date_time.utc = 1556043338236 fixture.home_team.id = 7901237 fixture.home_team.name = 'West Ham United'238 fixture.away_team.id = 496239 fixture.away_team.name = 'Tottenham Hotspur'240 return fixture241@pytest.fixture()242def rating_response():243 return ratings_pb2.RatingResponse(244 ratings=[245 ratings_pb2.TeamRating(246 team_id=7901,247 fixture_id=5,248 season_id=18378,249 attack=ratings_pb2.Points(250 points=13.87,251 difference=6.20,252 ),253 defence=ratings_pb2.Points(254 points=2.08,255 difference=1.11,256 ),257 fixture_date=Timestamp(seconds=1660228999),258 timestamp=Timestamp(seconds=1660228999),259 ),260 ratings_pb2.TeamRating(261 team_id=496,262 fixture_id=5,263 season_id=18378,264 attack=ratings_pb2.Points(265 points=32.18,266 difference=10,267 ),268 defence=ratings_pb2.Points(269 points=2.08,270 difference=1.11,271 ),272 fixture_date=Timestamp(seconds=1660228999),273 timestamp=Timestamp(seconds=1660228999),274 )275 ]...

Full Screen

Full Screen

test_ota_fixtures.py

Source:test_ota_fixtures.py Github

copy

Full Screen

...80 def test_basic_fixture_generation(self):81 fixture_xml = generator.get_fixtures(self.restore_user)82 self._check_fixture(fixture_xml, item_lists=[SA_PROVINCES, FR_PROVINCES])83 def test_fixtures_by_id(self):84 fixture_xml = generator.get_fixture_by_id('user-groups', self.restore_user)85 self._check_fixture([fixture_xml])86 fixture_xml = generator.get_fixture_by_id('item-list:sa_provinces', self.restore_user)87 self._check_fixture([fixture_xml], has_groups=False, item_lists=[SA_PROVINCES])88 fixture_xml = generator.get_fixture_by_id('item-list:fr_provinces', self.restore_user)89 self._check_fixture([fixture_xml], has_groups=False, item_lists=[FR_PROVINCES])90 fixture_xml = generator.get_fixture_by_id('user-locations', self.restore_user)91 self.assertIsNone(fixture_xml)92 fixture_xml = generator.get_fixture_by_id('bad ID', self.restore_user)93 self.assertIsNone(fixture_xml)94@use_sql_backend95class OtaFixtureTestSQL(OtaFixtureTest):96 pass97def _get_group_fixture(user_id, groups):98 groups = sorted(groups, key=lambda g: g.get_id)99 group_blocks = ["""100 <group id="{id}">101 <name>{name}</name>102 </group>103 """.format(id=group.get_id, name=group.name) for group in groups]104 groups_xml = """105 <groups>106 {}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful