Exemplo n.º 1
0
def trigger_parsing(request):
    if request.user.is_authenticated():
        site_manager = OFMSiteManager(request.user)
        site_manager.login()

        pm = ParserManager()
        pm.parse_all_ofm_data(site_manager)

        remote_version = pm.parse_ofm_version(site_manager)
        try:
            with open('version', 'r') as version_file:
                own_version = version_file.read().replace('\n', '')
            if own_version != "null" and own_version != remote_version:
                messages.info(
                    request, NEWER_OFM_VERSION_AVAILABLE %
                    (remote_version, own_version))
        except IOError:
            pass

        site_manager.kill_browser()

        return redirect('core:ofm:player_statistics')
    else:
        messages.error(request, NOT_LOGGED_IN)
        return redirect('core:account:login')
Exemplo n.º 2
0
def trigger_transfer_download(request):  # not for the chain
    get_matchday = request.GET.get("matchday_numbers")
    matchdays = []

    if get_matchday:
        matchday_numbers = get_matchday.split(',')

        for matchday_number in matchday_numbers:
            matchday, _ = Matchday.objects.get_or_create(
                number=matchday_number,
                season__number=Matchday.get_current().season.number)
            matchdays.append(matchday)

    site_manager = OFMSiteManager(request.user)

    pm = ParserManager()
    pm.parse_transfers(site_manager, matchdays)

    return redirect('core:ofm:transfers')
Exemplo n.º 3
0
def trigger_transfer_download(request):  # not for the chain
    get_matchday = request.GET.get("matchday_numbers")
    matchdays = []

    if get_matchday:
        matchday_numbers = get_matchday.split(',')

        for matchday_number in matchday_numbers:
            matchday, _ = Matchday.objects.get_or_create(
                            number=matchday_number,
                            season__number=Matchday.get_current().season.number
                          )
            matchdays.append(matchday)

    site_manager = OFMSiteManager(request.user)

    pm = ParserManager()
    pm.parse_transfers(site_manager, matchdays)

    return redirect('core:ofm:transfers')
Exemplo n.º 4
0
def trigger_parsing(request):
    if request.user.is_authenticated():
        site_manager = OFMSiteManager(request.user)
        site_manager.login()

        pm = ParserManager()
        pm.parse_all_ofm_data(site_manager)

        remote_version = pm.parse_ofm_version(site_manager)
        try:
            with open('version', 'r') as version_file:
                own_version = version_file.read().replace('\n', '')
            if own_version != "null" and own_version != remote_version:
                messages.info(request, NEWER_OFM_VERSION_AVAILABLE % (remote_version, own_version))
        except IOError:
            pass

        site_manager.kill_browser()

        return redirect('core:ofm:player_statistics')
    else:
        messages.error(request, NOT_LOGGED_IN)
        return redirect('core:account:login')
Exemplo n.º 5
0
 def setUp(self):
     self.parser_manager = ParserManager()
Exemplo n.º 6
0
class ParserManagerTest(TestCase):
    def setUp(self):
        self.parser_manager = ParserManager()

    @patch(
        'core.parsers.ofm_helper_version_parser.OfmHelperVersionParser.parse')
    def test_parse_ofm_version(self, parse_version_mock):
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_ofm_version(site_manager_mock)

        assert parse_version_mock.called

    @patch('core.parsers.matchday_parser.MatchdayParser.parse')
    def test_parse_matchday(self, parse_matchday_mock):
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_matchday(site_manager_mock)

        assert parse_matchday_mock.called

    @patch('core.managers.parser_manager.ParserManager.parse_matchday')
    @patch('core.parsers.players_parser.PlayersParser.parse')
    def test_parse_players_and_matchday(self, parse_players_mock,
                                        parse_matchday_mock):
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_players(site_manager_mock)

        assert parse_matchday_mock.called
        assert parse_players_mock.called

    @patch('core.managers.parser_manager.ParserManager.parse_matchday')
    @patch('core.parsers.player_statistics_parser.PlayerStatisticsParser.parse'
           )
    def test_parse_player_statistics(self, parse_player_statistics_mock,
                                     parse_matchday_mock):
        self.parser_manager.players_already_parsed = True
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_player_statistics(site_manager_mock)

        assert not parse_matchday_mock.called
        assert parse_player_statistics_mock.called

    @patch('core.managers.parser_manager.ParserManager.parse_players')
    @patch('core.parsers.player_statistics_parser.PlayerStatisticsParser.parse'
           )
    def test_parse_player_statistics_and_matchday(self,
                                                  parse_player_statistics_mock,
                                                  parse_players_mock):
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_player_statistics(site_manager_mock)

        assert parse_players_mock.called
        assert parse_player_statistics_mock.called

    @patch('core.managers.parser_manager.ParserManager.parse_matchday')
    @patch('core.parsers.awp_boundaries_parser.AwpBoundariesParser.parse')
    def test_parse_awp_and_matchday(self, parse_awp_mock, parse_matchday_mock):
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_awp_boundaries(site_manager_mock)

        assert parse_matchday_mock.called
        assert parse_awp_mock.called

    @patch('core.managers.parser_manager.ParserManager.parse_matchday')
    @patch('core.parsers.finances_parser.FinancesParser.parse')
    def test_parse_finances_and_matchday(self, parse_finances_mock,
                                         parse_matchday_mock):
        with patch('core.managers.site_manager.OFMSiteManager'
                   ) as site_manager_mock:
            site_manager_mock.browser.page_source.return_value = "<html></html>"
            self.parser_manager.parse_finances(site_manager_mock)

        assert parse_matchday_mock.called
        assert parse_finances_mock.called

    @skip('Works locally, but not on travis...')
    @patch('core.managers.parser_manager.ParserManager._convert_transfer_data')
    @patch('core.managers.site_manager.OFMTransferSiteManager.kill_browser')
    @patch(
        'core.managers.site_manager.OFMTransferSiteManager.download_transfer_excels'
    )
    @patch('core.managers.parser_manager.ParserManager.parse_matchday')
    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
Exemplo n.º 7
0
def trigger_match_parsing(request):
    pm = ParserManager()
    redirect_to = 'core:ofm:matches_overview'
    return trigger_single_parsing(request, pm.parse_all_matches, redirect_to)
Exemplo n.º 8
0
def trigger_finances_parsing(request):
    pm = ParserManager()
    redirect_to = 'core:ofm:finance_overview'
    return trigger_single_parsing(request, pm.parse_finances, redirect_to)
Exemplo n.º 9
0
def trigger_player_statistics_parsing(request):
    pm = ParserManager()
    redirect_to = 'core:ofm:player_statistics'
    return trigger_single_parsing(request, pm.parse_player_statistics,
                                  redirect_to)
Exemplo n.º 10
0
def trigger_matchday_parsing(request):
    pm = ParserManager()
    return trigger_single_parsing(request, pm.parse_matchday)