def test_initialize_reference_metadata_objects(log, mocker, mock_api, site_objects_param): api = mocker.patch('solarforecastarbiter.io.reference_observations.' 'reference_data.get_apisession') mock_api.list_sites.return_value = {} api.return_value = mock_api reference_data.initialize_reference_metadata_objects('TOKEN', site_dicts()) api.assert_called_once() assert mock_api.create_site.call_count == 3 for site in site_objects_param[1:]: mock_api.create_site.assert_any_call(site)
(site_objects[0], 'site'), (site_objects[1], 'site2'), (site_objects[2], 'site3'), (site_objects[3], 'site4'), ]) def test_site_name_no_network(site, expected): assert common.site_name_no_network(site) == expected @pytest.mark.parametrize('name,expected', [('{n}_(a)_/m\\_.e@_[1]-', 'n a m e 1')]) def test_clean_name(name, expected): assert common.clean_name(name) == expected bad_network = site_dicts()[0] bad_network['extra_parameters']['network'] = 'BBQ DISCO' bad_network = expected_site(bad_network) @pytest.mark.parametrize('networks,site,expected', [ (['DOE ARM'], site_string_dicts[0], True), ('DOE ARM', site_string_dicts[0], True), (['DOE ARM', 'NREL MIDC'], site_string_dicts[1], False), (['NOAA SURFRAD', 'DOE ARM'], site_string_dicts[3], False), (['NOAA SURFRAD', 'DOE ARM'], bad_network, False), (['ARMS'], site_string_dicts[0], False), ]) def test_check_network(networks, site, expected): metadata = Site.from_dict(site) assert common.check_network(networks, metadata) == expected
import pandas as pd from solarforecastarbiter.io.reference_observations import reference_data from solarforecastarbiter.io.reference_observations.tests.conftest import ( site_dicts, site_objects) @pytest.fixture def log(mocker): logger = mocker.patch('solarforecastarbiter.io.reference_observations.' 'reference_data.logger') return logger site_object_pairs = list(zip(site_dicts(), site_objects))[:-1] def test_getapisession(mocker): mocked = mocker.patch( 'solarforecastarbiter.io.reference_observations.reference_data.APISession' ) # NOQA reference_data.get_apisession('TEST', 'url') assert mocked.called_with('TEST', 'url') @pytest.fixture() def mock_creates(mocker): initobs = mocker.patch( 'solarforecastarbiter.io.reference_observations.common.create_observation' ) # NOQA