Beispiel #1
0
    def test_parse_for_non_empty_contents(self):
        url = \
         "http://www.bcra.gov.ar/Publicaciones\
            Estadisticas/Evolucion_moneda.asp"

        coins = {"bolivar_venezolano": "Bolívar Venezolano"}
        scraper = BCRAExchangeRateScraper(url,
                                          coins,
                                          intermediate_panel_path=None,
                                          use_intermediate_panel=False)
        start_date = datetime(2019, 4, 8)
        end_date = datetime(2019, 4, 8)
        contents = {}

        table_content = '''
        <table class="table table-BCRA table-bordered table-hover
        table-responsive" colspan="3">
            <thead>
            <tr>
            <td colspan="3">
                <b>MERCADO DE CAMBIOS - COTIZACIONES CIERRE VENDEDOR<br>
                Bolívar Venezolano</b>
            </td>
            </tr>
            <tr>
                <td width="10%"><b>
                    FECHA</b>
                </td>
                <td width="40%"><b>
            TIPO DE PASE - EN DOLARES - (por unidad)</b></td>
                <td width="50%"><b>
            TIPO DE CAMBIO - MONEDA DE CURSO LEGAL - (por unidad)</b></td>
                </tr>
            </thead>
            <tbody><tr>
                <td width="10%">
                08/04/2019</td>
                <td width="40%">
                0,0003030</td>
                <td width="50%">
                0,0132500</td>
            </tr>
            </tbody>
        </table>
        '''

        contents['bolivar_venezolano'] = table_content

        parsed = scraper.parse_contents(contents, start_date, end_date)

        assert parsed['tc_local'] == [{
            'bolivar_venezolano': '0,0132500',
            'indice_tiempo': '08/04/2019'
        }]

        assert parsed['tp_usd'] == [{
            'bolivar_venezolano': '0,0003030',
            'indice_tiempo': '08/04/2019'
        }]
    def test_parse_contents(self):
        url = ''

        start_date = datetime(2019, 4, 24)
        end_date = datetime(2019, 4, 24)

        coins = {
            "bolivar_venezolano": "Bolívar Venezolano"
        }

        content = {'bolivar_venezolano': 'foo'}

        parsed = [
            {
                'moneda': 'bolivar_venezolano',
                'indice_tiempo': '24/04/2019',
                'tp_usd': '0,0001930',
                'tc_local': '0,0084610'
            }
        ]

        with patch.object(
            BCRAExchangeRateScraper,
            'parse_coin',
            return_value=parsed
        ):
            scraper = BCRAExchangeRateScraper(url, coins, False)
            result = scraper.parse_contents(content, start_date, end_date)

            assert result == {
                'tc_local':
                [
                    {
                        'indice_tiempo': '24/04/2019',
                        'bolivar_venezolano': '0,0084610'
                    }
                ],
                'tp_usd':
                [
                    {
                        'indice_tiempo': '24/04/2019',
                        'bolivar_venezolano': '0,0001930'
                    }
                ]
            }
    def test_parse_for_empty_contents(self):
        url = \
         "http://www.bcra.gov.ar/Publicaciones\
            Estadisticas/Evolucion_moneda.asp"
        coins = {
            "bolivar_venezolano": "Bolívar Venezolano",
            "chelin_austriaco": "Chelín Austríaco",
            "cordoba_nicaraguense": "Cordoba Nicaraguense",
            "corona_checa": "Corona Checa",
            "corona_danesa": "Corona Danesa",
        }
        scraper = BCRAExchangeRateScraper(url, coins, False)
        start_date = date.today()
        end_date = date.today()
        contents = {}
        parsed = scraper.parse_contents(contents, start_date, end_date)

        assert parsed['tc_local'] == []
        assert parsed['tp_usd'] == []