def test_california_los_angeles():
    util.run_scraper_and_assert(scraper_cls=CaliforniaLosAngeles,
                                assertions={
                                    'Date Published':
                                    datetime(2020, 7, 16).date(),
                                    'Total Cases':
                                    150000,
                                    'Total Deaths':
                                    4000,
                                    'Count Cases Black/AA':
                                    4000,
                                    'Count Deaths Black/AA':
                                    400,
                                    'Pct Includes Unknown Race':
                                    False,
                                    'Pct Includes Hispanic Black':
                                    False,
                                    'Pct Cases Black/AA':
                                    to_percentage(4000, 78500),
                                    'Pct Deaths Black/AA':
                                    to_percentage(400, 3650),
                                    'Count Cases Known Race':
                                    78500,
                                    'Count Deaths Known Race':
                                    3650
                                })
def test_delaware():
    util.run_scraper_and_assert(scraper_cls=Delaware,
                                assertions={
                                    'Date Published':
                                    datetime(2020, 7, 16).date(),
                                    'Total Cases':
                                    13000,
                                    'Total Deaths':
                                    500,
                                    'Count Cases Black/AA':
                                    3000,
                                    'Count Deaths Black/AA':
                                    100,
                                    'Pct Includes Unknown Race':
                                    False,
                                    'Pct Includes Hispanic Black':
                                    False,
                                    'Pct Cases Black/AA':
                                    to_percentage(3000, 12000),
                                    'Pct Deaths Black/AA':
                                    to_percentage(100, 480),
                                    'Count Cases Known Race':
                                    12000,
                                    'Count Deaths Known Race':
                                    480
                                })
Exemple #3
0
def test_california_sf():
    mocked_requests = {
        'date': util.MockSeleniumWireRequest(response_body=loader.get_blob('california_san_francisco_date.txt')),
        'cases_by_race': util.MockSeleniumWireRequest(
            response_body=loader.get_blob('california_san_francisco_cases.txt')),
        'deaths_by_race': util.MockSeleniumWireRequest(
            response_body=loader.get_blob('california_san_francisco_deaths.txt'))
    }

    mocked_webdriver = util.mocked_webdriver_runner(requests=mocked_requests)

    with mock.patch('covid19_scrapers.states.california_san_francisco.WebdriverRunner', mocked_webdriver):
        util.run_scraper_and_assert(
            scraper_cls=CaliforniaSanFrancisco,
            assertions={
                'Date Published': datetime(2020, 7, 17).date(),
                'Total Cases': 5100,
                'Total Deaths': 130,
                'Count Cases Black/AA': 300,
                'Count Deaths Black/AA': 5,
                'Pct Includes Unknown Race': False,
                'Pct Includes Hispanic Black': False,
                'Pct Cases Black/AA': to_percentage(300, 4400),
                'Pct Deaths Black/AA': to_percentage(5, 30),
                'Count Cases Known Race': 4400,
                'Count Deaths Known Race': 30
            })
Exemple #4
0
def test_alabama(patched_geoservice):
    # setup constants and mock data
    AA_IDX = 1
    UNKNOWN_IDX = 3

    cases = {
        'Racecat': ['Asian', 'Black', 'Other', 'Unknown', 'White'],
        'value': [200, 19000, 3000, 18000, 20000]
    }

    deaths = {
        'Racecat': ['Asian', 'Black', 'Other', 'Unknown', 'White'],
        'value': [10, 500, 25, 50, 600]
    }

    known_cases_by_race = sum(cases['value']) - cases['value'][UNKNOWN_IDX]
    known_deaths_by_race = sum(deaths['value']) - deaths['value'][UNKNOWN_IDX]

    # patch geoservice
    patched_geoservice.side_effect = [
        util.make_query_geoservice_data(data=cases),
        util.make_query_geoservice_data(data=deaths)
    ]

    # run and test
    util.run_scraper_and_assert(scraper_cls=Alabama,
                                assertions={
                                    'Date Published':
                                    date.today(),
                                    'Total Cases':
                                    sum(cases['value']),
                                    'Total Deaths':
                                    sum(deaths['value']),
                                    'Count Cases Black/AA':
                                    cases['value'][AA_IDX],
                                    'Count Deaths Black/AA':
                                    deaths['value'][AA_IDX],
                                    'Pct Includes Unknown Race':
                                    False,
                                    'Pct Includes Hispanic Black':
                                    False,
                                    'Pct Cases Black/AA':
                                    to_percentage(cases['value'][AA_IDX],
                                                  known_cases_by_race),
                                    'Pct Deaths Black/AA':
                                    to_percentage(deaths['value'][AA_IDX],
                                                  known_deaths_by_race),
                                    'Count Cases Known Race':
                                    known_cases_by_race,
                                    'Count Deaths Known Race':
                                    known_deaths_by_race
                                })
Exemple #5
0
def test_arkansas():
    util.run_scraper_and_assert(
        scraper_cls=Arkansas,
        assertions={
            'Date Published': date.today(),
            'Total Cases': 31000,
            'Total Deaths': 300,
            'Count Cases Black/AA': 6000,
            'Count Deaths Black/AA': 90,
            'Pct Includes Unknown Race': False,
            'Pct Includes Hispanic Black': True,
            'Pct Cases Black/AA': to_percentage(6000, 27000),
            'Pct Deaths Black/AA': to_percentage(90, 297),
            'Count Cases Known Race': 27000,
            'Count Deaths Known Race': 297
        })
Exemple #6
0
def test_alaska():
    util.run_scraper_and_assert(
        scraper_cls=Alaska,
        assertions={
            'Date Published': date.today(),
            'Total Cases': 1733,
            'Total Deaths': 17,
            'Count Cases Black/AA': 41,
            'Count Deaths Black/AA': 0,
            'Pct Includes Unknown Race': False,
            'Pct Includes Hispanic Black': True,
            'Pct Cases Black/AA': to_percentage(41, 1171),
            'Pct Deaths Black/AA': to_percentage(0, 17),
            'Count Cases Known Race': 1171,
            'Count Deaths Known Race': 17
        })
Exemple #7
0
def test_wisconsin():
    util.run_scraper_and_assert(
        scraper_cls=Wisconsin,
        assertions={
            'Date Published': date.today(),
            'Total Cases': 40000,
            'Total Deaths': 800,
            'Count Cases Black/AA': 6600,
            'Count Deaths Black/AA': 200,
            'Pct Includes Unknown Race': False,
            'Pct Includes Hispanic Black': True,
            'Pct Cases Black/AA': to_percentage(6600, 40000 - 3800),
            'Pct Deaths Black/AA': to_percentage(200, 800 - 10),
            'Count Cases Known Race': 40000 - 3800,
            'Count Deaths Known Race': 800 - 10
        })
Exemple #8
0
def test_wisconsin():
    _, df = util.make_query_geoservice_data(json_file='wisconsin.json')
    df['DATE'] = pd.Timestamp.today()
    with mock.patch('covid19_scrapers.states.wisconsin.query_geoservice', mock.MagicMock(return_value=(date, df))):
        util.run_scraper_and_assert(
            scraper_cls=Wisconsin,
            assertions={
                'Date Published': date.today(),
                'Total Cases': 40000,
                'Total Deaths': 800,
                'Count Cases Black/AA': 6600,
                'Count Deaths Black/AA': 200,
                'Pct Includes Unknown Race': False,
                'Pct Includes Hispanic Black': True,
                'Pct Cases Black/AA': to_percentage(6600, 40000 - 3800),
                'Pct Deaths Black/AA': to_percentage(200, 800 - 10),
                'Count Cases Known Race': 40000 - 3800,
                'Count Deaths Known Race': 800 - 10
            })
def test_illinois():
    util.run_scraper_and_assert(scraper_cls=Illinois,
                                assertions={
                                    'Date Published':
                                    datetime(2020, 7, 18).date(),
                                    'Total Cases':
                                    160000,
                                    'Total Deaths':
                                    7000,
                                    'Count Cases Black/AA':
                                    27000,
                                    'Count Deaths Black/AA':
                                    2000,
                                    'Pct Includes Unknown Race':
                                    True,
                                    'Pct Includes Hispanic Black':
                                    False,
                                    'Pct Cases Black/AA':
                                    to_percentage(27000, 160000),
                                    'Pct Deaths Black/AA':
                                    to_percentage(2000, 7000)
                                })
Exemple #10
0
def test_maryland():
    util.run_scraper_and_assert(scraper_cls=Maryland,
                                assertions={
                                    'Total Cases':
                                    75000,
                                    'Total Deaths':
                                    3000,
                                    'Count Cases Black/AA':
                                    20000,
                                    'Count Deaths Black/AA':
                                    1000,
                                    'Pct Includes Unknown Race':
                                    False,
                                    'Pct Includes Hispanic Black':
                                    False,
                                    'Pct Cases Black/AA':
                                    to_percentage(20000, 63000),
                                    'Pct Deaths Black/AA':
                                    to_percentage(1000, 2990),
                                    'Count Cases Known Race':
                                    63000,
                                    'Count Deaths Known Race':
                                    2990
                                })
Exemple #11
0
def test_california():
    mock_dfs = [
        util.mock_read_csv_dataframe('california_cases.csv',
                                     parse_dates=['date']),
        util.mock_read_csv_dataframe('california_demographics.csv',
                                     index_col=['date', 'race_ethnicity'],
                                     parse_dates=['date'])
    ]

    with mock.patch('covid19_scrapers.states.california.pd.read_csv',
                    side_effect=mock_dfs):
        util.run_scraper_and_assert(scraper_cls=California,
                                    assertions={
                                        'Date Published':
                                        datetime(2020, 7, 16).date(),
                                        'Total Cases':
                                        10000,
                                        'Total Deaths':
                                        1500,
                                        'Count Cases Black/AA':
                                        10000,
                                        'Count Deaths Black/AA':
                                        600,
                                        'Pct Includes Unknown Race':
                                        False,
                                        'Pct Includes Hispanic Black':
                                        False,
                                        'Pct Cases Black/AA':
                                        to_percentage(10000, 45000),
                                        'Pct Deaths Black/AA':
                                        to_percentage(600, 4100),
                                        'Count Cases Known Race':
                                        45000,
                                        'Count Deaths Known Race':
                                        4100
                                    })