def setUp(self): self.player = PlayerFactory.create() self.matchday = MatchdayFactory.create() self.second_matchday = MatchdayFactory.create(number=1) self.user1 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) Contract.objects.create( user=self.user1, player=self.player, bought_on_matchday=self.matchday, sold_on_matchday=None ) self.client.login(username='******', password='******') PlayerStatisticsFactory.create(player=self.player, matchday=self.matchday) PlayerStatisticsFactory.create( player=self.player, matchday=self.second_matchday, ep=3, tp=6, awp=4, freshness=5 )
def test_stadium_data_if_one_stand_not_used(self): MatchdayFactory.create(number=2) match = MatchFactory.create(user=self.user1) stadium_stat_2 = MatchStadiumStatisticsFactory.create(match=match) StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='W') response = self.client.get('/ofm/stadium/' + str(stadium_stat_2.id)) self.assertEqual(response.status_code, 200) self.assertTrue(response.context_data['north_stand'] is not None) self.assertTrue(response.context_data['south_stand'] is not None) self.assertTrue(response.context_data['west_stand'] is not None) self.assertTrue(response.context_data['east_stand'] is None)
def setUp(self): self.matchday = MatchdayFactory.create() self.second_matchday = MatchdayFactory.create(number=1) self.user1 = OFMUser.objects.create_user(username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******') self.user2 = OFMUser.objects.create_user(username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******') MatchFactory.create(user=self.user1) self.client.login(username='******', password='******')
def test_stadium_data_if_one_stand_not_used(self): MatchdayFactory.create(number=2) match = MatchFactory.create(user=self.user1) stadium_stat_2 = MatchStadiumStatisticsFactory.create(match=match) StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='W') response = self.client.get('/ofm/stadium/' + str(stadium_stat_2.id)) self.assertEqual(response.status_code, 200) self.assertTrue(response.context_data['north_stand'] is not None) self.assertTrue(response.context_data['south_stand'] is not None) self.assertTrue(response.context_data['west_stand'] is not None) self.assertTrue(response.context_data['east_stand'] is None)
def test_user_can_filter_for_stadium_configuration(self): matchday = MatchdayFactory.create(number=2) match2 = MatchFactory.create(user=self.user, matchday=matchday) light_level = StadiumLevelItemFactory(current_level=1) level = StadiumLevelFactory.create(light=light_level) stadium_stat_2 = MatchStadiumStatisticsFactory.create(match=match2, level=level) StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='W') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='O') options = { 'harmonic_strength': 50, 'tolerance': 2, 'configuration_filter': self.stadium_stat.get_configuration() } response = self.client.get( reverse('core:ofm:stadium_statistics_overview_json'), options) returned_json_data = json.loads(response.content.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(returned_json_data), 1)
def test_user_can_see_his_player_statistics_diff_when_given_only_newer_matchday( self): third_matchday = MatchdayFactory.create(number=self.matchday.number + 2) PlayerStatisticsFactory.create(player=self.player, matchday=third_matchday, ep=12, tp=15, awp=13, freshness=14) response = self.client.get( reverse('core:ofm:player_statistics_json'), { 'newer_matchday_season': third_matchday.season.number, 'newer_matchday': third_matchday.number }) returned_json_data = json.loads(response.content.decode('utf-8')) self.assertEqual(returned_json_data[0]['position'], 'TW') self.assertEqual(returned_json_data[0]['name'], '<a href="/ofm/players/1">Martin Adomeit</a>') self.assertEqual(returned_json_data[0]['ep'], 12) self.assertEqual(returned_json_data[0]['tp'], 15) self.assertEqual(returned_json_data[0]['awp'], 13) self.assertEqual(returned_json_data[0]['strength'], 1) self.assertEqual(returned_json_data[0]['freshness'], 14)
def test_player_chart_shows_reached_but_not_promoted_awp_boundary(self): PlayerStatisticsFactory.create(player=self.player, matchday=self.matchday, strength=2, awp=2800) PlayerStatisticsFactory.create( player=self.player, matchday=MatchdayFactory.create(number=1), strength=2, awp=3500 ) awp_boundaries = AwpBoundaries.get_or_create_from_matchday(self.matchday) awp_boundaries[2] = 2000 awp_boundaries[3] = 3000 awp_boundaries[4] = 4000 response = self.client.get(reverse('core:ofm:players_chart_json'), {'player_id': self.player.id}) self.assertEqual(response.status_code, 200) returned_json_data = json.loads(response.content.decode('utf-8')) self.assertTrue('series' in returned_json_data) self.assertEqual('AWP', returned_json_data['series'][0]['name']) self.assertTrue('data' in returned_json_data['series'][0]) self.assertEqual('AWP-Grenze: 3', returned_json_data['series'][1]['name']) self.assertTrue('data' in returned_json_data['series'][1]) self.assertEqual([3000] * 2, returned_json_data['series'][1]['data']) self.assertEqual('AWP-Grenze: 4', returned_json_data['series'][2]['name']) self.assertTrue('data' in returned_json_data['series'][2]) self.assertEqual([4000] * 2, returned_json_data['series'][2]['data'])
def setUp(self): testdata = open(os.path.join(TESTDATA_PATH, 'stadium_environment.html'), encoding='utf8') self.user = OFMUserFactory.create(username='******') matchday2 = MatchdayFactory.create(number=2) self.match2 = MatchFactory.create(user=self.user, matchday=matchday2) self.parser = StadiumStatisticsParser(testdata, self.user, self.match2)
def setUp(self): testdata = open(os.path.join(TESTDATA_PATH, 'player_statistics.html'), encoding='utf8') self.matchday = MatchdayFactory.create() user = OFMUserFactory.create() season = SeasonFactory.create() country_choices = Country.get_choices() country_iso_greece = list(country_choices.keys())[list( country_choices.values()).index('Griechenland')] nationality_greece, _ = Country.objects.get_or_create( country=country_iso_greece) self.player = Player.objects.create(id='159883060', position='TW', name='Chrístos Tsigas', birth_season=season, nationality=nationality_greece) self.player = Player.objects.create(id='160195494', position='LV', name='Irwin O\'Canny', birth_season=season, nationality=nationality_greece) self.player = Player.objects.create(id='159341445', position='LMD', name='Jan Stemmler', birth_season=season, nationality=nationality_greece) self.parser = PlayerStatisticsParser(testdata, user, self.matchday) self.player_stat_list = self.parser.parse() self.first_player_stat = self.player_stat_list[0] self.assertEqual(Matchday.objects.all().count(), 1)
def setUp(self): testdata = open(os.path.join(TESTDATA_PATH, 'stadium_environment.html'), encoding='utf8') self.user = OFMUserFactory.create(username='******') matchday2 = MatchdayFactory.create(number=2) self.match2 = MatchFactory.create(user=self.user, matchday=matchday2) self.parser = StadiumStatisticsParser(testdata, self.user, self.match2)
def setUp(self): self.matchday = MatchdayFactory.create() self.second_matchday = MatchdayFactory.create(number=1) self.user1 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) self.user2 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) MatchFactory.create(user=self.user1) self.client.login(username='******', password='******')
def test_stadium_environment_parser_takes_old_screen_data_while_in_construction_if_older_stat_exists(self): matchday1 = MatchdayFactory.create(number=1) last_level = StadiumLevelFactory.create() match1 = MatchFactory.create(user=self.user, matchday=matchday1) MatchStadiumStatisticsFactory.create(match=match1, level=last_level) stadium_stat = self.parser.parse() self.assertEqual(stadium_stat.level.screen.current_level, 0) self.assertEqual(stadium_stat.level.screen.value, 0) self.assertEqual(stadium_stat.level.screen.daily_costs, 0)
def test_stadium_environment_parser_takes_old_screen_data_while_in_construction_if_older_stat_exists( self): matchday1 = MatchdayFactory.create(number=1) last_level = StadiumLevelFactory.create() match1 = MatchFactory.create(user=self.user, matchday=matchday1) MatchStadiumStatisticsFactory.create(match=match1, level=last_level) stadium_stat = self.parser.parse() self.assertEqual(stadium_stat.level.screen.current_level, 0) self.assertEqual(stadium_stat.level.screen.value, 0) self.assertEqual(stadium_stat.level.screen.daily_costs, 0)
def setUp(self): self.player = PlayerFactory.create() self.matchday = MatchdayFactory.create() self.second_matchday = MatchdayFactory.create(number=1) self.user1 = OFMUser.objects.create_user(username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******') Contract.objects.create(user=self.user1, player=self.player, bought_on_matchday=self.matchday, sold_on_matchday=None) self.client.login(username='******', password='******') PlayerStatisticsFactory.create(player=self.player, matchday=self.matchday) PlayerStatisticsFactory.create(player=self.player, matchday=self.second_matchday, ep=3, tp=6, awp=4, freshness=5)
def setUp(self): self.matchday = MatchdayFactory.create() self.user = OFMUser.objects.create_user(username='******', password='******') self.client.login(username='******', password='******') self.match = MatchFactory.create(user=self.user) self.stadium_stat = MatchStadiumStatisticsFactory.create(match=self.match) StadiumStandStatisticsFactory.create(stadium_statistics=self.stadium_stat, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=self.stadium_stat, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=self.stadium_stat, sector='W') StadiumStandStatisticsFactory.create(stadium_statistics=self.stadium_stat, sector='O')
def test_get_current_matchday_from_player_statistics(self): MatchdayFactory.create(number=1) m2 = MatchdayFactory.create(number=5) m3 = MatchdayFactory.create(number=7) MatchdayFactory.create(number=15) FinanceFactory.create(matchday=m2) PlayerStatisticsFactory.create(matchday=m3) self.assertEqual(Matchday.get_current(), m3)
def setUp(self): MatchdayFactory.create() user1 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) match = MatchFactory.create(user=user1) stadium_stat = MatchStadiumStatisticsFactory.create(match=match) StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='W') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='O') self.client.login(username='******', password='******')
def test_default_values_from_last_match_for_strength_slider(self): matchday = MatchdayFactory.create(number=2) match2 = MatchFactory.create(user=self.user, home_team_statistics__strength=30, guest_team_statistics__strength=150, matchday=matchday) MatchStadiumStatisticsFactory.create(match=match2) response = self.client.get( reverse('core:ofm:stadium_statistics_overview')) self.assertEqual(response.status_code, 200) self.assertEqual(response.context_data['slider_min'], 30) self.assertEqual(response.context_data['slider_max'], 150) self.assertEqual(response.context_data['tolerance'], 5)
def test_parse_transfer_data(self, parse_matchday_mock, download_transfers_mock, kill_browser_mock, convert_mock): with patch('core.managers.site_manager.OFMTransferSiteManager' ) as site_manager_mock: site_manager_mock.download_transfer_excels = download_transfers_mock site_manager_mock._convert_transfer_data = convert_mock # pylint: disable=protected-access site_manager_mock.kill_browser = kill_browser_mock self.parser_manager.parsed_matchday = MatchdayFactory.create() self.parser_manager.parse_transfers(site_manager_mock) assert download_transfers_mock.called assert kill_browser_mock.called
def setUp(self): MatchdayFactory.create() user1 = OFMUser.objects.create_user(username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******') OFMUser.objects.create_user(username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******') match = MatchFactory.create(user=user1) stadium_stat = MatchStadiumStatisticsFactory.create(match=match) StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='W') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat, sector='O') self.client.login(username='******', password='******')
def test_default_values_from_last_match_for_strength_slider(self): matchday = MatchdayFactory.create(number=2) match2 = MatchFactory.create( user=self.user, home_team_statistics__strength=30, guest_team_statistics__strength=150, matchday=matchday ) MatchStadiumStatisticsFactory.create(match=match2) response = self.client.get(reverse('core:ofm:stadium_statistics_overview')) self.assertEqual(response.status_code, 200) self.assertEqual(response.context_data['slider_min'], 30) self.assertEqual(response.context_data['slider_max'], 150) self.assertEqual(response.context_data['tolerance'], 5)
def test_user_can_see_his_player_statistics_diff_when_given_only_newer_matchday(self): third_matchday = MatchdayFactory.create(number=self.matchday.number + 2) PlayerStatisticsFactory.create(player=self.player, matchday=third_matchday, ep=12, tp=15, awp=13, freshness=14) response = self.client.get(reverse('core:ofm:player_statistics_json'), {'newer_matchday_season': third_matchday.season.number, 'newer_matchday': third_matchday.number }) returned_json_data = json.loads(response.content.decode('utf-8')) self.assertEqual(returned_json_data[0]['position'], 'TW') self.assertEqual(returned_json_data[0]['name'], '<a href="/ofm/players/1">Martin Adomeit</a>') self.assertEqual(returned_json_data[0]['ep'], 12) self.assertEqual(returned_json_data[0]['tp'], 15) self.assertEqual(returned_json_data[0]['awp'], 13) self.assertEqual(returned_json_data[0]['strength'], 1) self.assertEqual(returned_json_data[0]['freshness'], 14)
def test_get_current_matchday_from_matches(self): user2 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username="******", ofm_password="******" ) MatchdayFactory.create(number=1) m2 = MatchdayFactory.create(number=5) m3 = MatchdayFactory.create(number=7) m4 = MatchdayFactory.create(number=9) MatchdayFactory.create(number=15) FinanceFactory.create(matchday=m2, user=user2) PlayerStatisticsFactory.create(matchday=m3) MatchFactory.create(matchday=m4, user=user2) self.assertEqual(Matchday.get_current(), m4)
def setUp(self): self.matchday = MatchdayFactory.create() self.user = OFMUser.objects.create_user(username='******', password='******') self.client.login(username='******', password='******') self.match = MatchFactory.create(user=self.user) self.stadium_stat = MatchStadiumStatisticsFactory.create( match=self.match) StadiumStandStatisticsFactory.create( stadium_statistics=self.stadium_stat, sector='N') StadiumStandStatisticsFactory.create( stadium_statistics=self.stadium_stat, sector='S') StadiumStandStatisticsFactory.create( stadium_statistics=self.stadium_stat, sector='W') StadiumStandStatisticsFactory.create( stadium_statistics=self.stadium_stat, sector='O')
def test_user_can_filter_for_stadium_configuration(self): matchday = MatchdayFactory.create(number=2) match2 = MatchFactory.create(user=self.user, matchday=matchday) light_level = StadiumLevelItemFactory(current_level=1) level = StadiumLevelFactory.create(light=light_level) stadium_stat_2 = MatchStadiumStatisticsFactory.create(match=match2, level=level) StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='N') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='S') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='W') StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='O') options = { 'harmonic_strength': 50, 'tolerance': 2, 'configuration_filter': self.stadium_stat.get_configuration() } response = self.client.get(reverse('core:ofm:stadium_statistics_overview_json'), options) returned_json_data = json.loads(response.content.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(returned_json_data), 1)
def test_player_chart_shows_different_awp_boundaries(self): matchday_9 = MatchdayFactory.create(number=9) PlayerStatisticsFactory.create(player=self.player, matchday=self.matchday) PlayerStatisticsFactory.create(player=self.player, matchday=matchday_9) awp_boundaries = AwpBoundaries.get_or_create_from_matchday(self.matchday) awp_boundaries[2] = 2000 awp_boundaries_9 = AwpBoundaries.get_or_create_from_matchday(matchday_9) awp_boundaries_9[2] = 3000 response = self.client.get(reverse('core:ofm:players_chart_json'), {'player_id': self.player.id}) self.assertEqual(response.status_code, 200) returned_json_data = json.loads(response.content.decode('utf-8')) self.assertTrue('series' in returned_json_data) self.assertEqual('AWP', returned_json_data['series'][0]['name']) self.assertTrue('data' in returned_json_data['series'][0]) self.assertEqual('AWP-Grenze: 2', returned_json_data['series'][1]['name']) self.assertTrue('data' in returned_json_data['series'][1]) self.assertEqual([2000, 3000], returned_json_data['series'][1]['data'])
def setUp(self): self.player = PlayerFactory.create() self.matchday = MatchdayFactory.create() self.user1 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) self.user2 = OFMUser.objects.create_user( username='******', email='*****@*****.**', password='******', ofm_username='******', ofm_password='******' ) Contract.objects.create( user=self.user1, player=self.player, bought_on_matchday=self.matchday, sold_on_matchday=None ) self.client.login(username='******', password='******')
def setUp(self): testdata = open(os.path.join(TESTDATA_PATH, 'player_statistics.html'), encoding='utf8') self.matchday = MatchdayFactory.create() user = OFMUserFactory.create() season = SeasonFactory.create() country_choices = Country.get_choices() country_iso_greece = list(country_choices.keys())[list(country_choices.values()).index('Griechenland')] nationality_greece, _ = Country.objects.get_or_create(country=country_iso_greece) self.player = Player.objects.create( id='159883060', position='TW', name='Chrístos Tsigas', birth_season=season, nationality=nationality_greece ) self.player = Player.objects.create( id='160195494', position='LV', name='Irwin O\'Canny', birth_season=season, nationality=nationality_greece ) self.player = Player.objects.create( id='159341445', position='LMD', name='Jan Stemmler', birth_season=season, nationality=nationality_greece ) self.parser = PlayerStatisticsParser(testdata, user, self.matchday) self.player_stat_list = self.parser.parse() self.first_player_stat = self.player_stat_list[0] self.assertEqual(Matchday.objects.all().count(), 1)
def test_get_current_matchday_from_finances(self): MatchdayFactory.create(number=1) m2 = MatchdayFactory.create(number=5) MatchdayFactory.create(number=15) FinanceFactory.create(matchday=m2) self.assertEqual(Matchday.get_current(), m2)
def test_create_matchday(self): m = MatchdayFactory.create() self.assertIsNotNone(m) self.assertEqual(m.season.number, 1) self.assertEqual(m.number, 0)
def test_matchday_order_desc_by_number(self): MatchdayFactory.create(number=1) MatchdayFactory.create(number=2) self.assertEqual(Matchday.objects.all()[0].number, 2)
def test_get_current_matchday_default(self): MatchdayFactory.create(number=1) m2 = MatchdayFactory.create(number=5) self.assertEqual(Matchday.get_current(), m2)
def test_matchday_order_desc_by_season(self): s = SeasonFactory.create(number=2) MatchdayFactory.create() MatchdayFactory.create(season=s) self.assertEqual(Matchday.objects.all()[0].season.number, 2)