def test_get_ina_data_error(): ina_id = id_tuple(id="36885889", type="observations") mock_session = mock.MagicMock() mock_session.get.side_effect = requests.exceptions.HTTPError with mock.patch("inrbot.session", mock_session): response = inrbot.get_ina_data(ina_id) assert response is None
def test_get_ina_data_wrong_number(): ina_id = id_tuple(id="36885889", type="observations") mock_session = mock.MagicMock() mock_session.get.return_value.json.return_value = {"total_results": 2} with mock.patch("inrbot.session", mock_session): response = inrbot.get_ina_data(ina_id) assert response is None
def test_find_photo_in_obs_notmatching(): page = mock.MagicMock() page.latest_file_info.sha1 = "foo" obs_id = id_tuple(id="36885821", type="observations") ina_data = inrbot.get_ina_data(obs_id) photo, found = inrbot.find_photo_in_obs(page, obs_id, ina_data) assert photo is None assert found == "notmatching"
def test_find_photo_in_obs(): page = mock.MagicMock() page.latest_file_info.sha1 = "a80ef8a886c3deeeded624856fb83d269dda1683" obs_id = id_tuple(id="36885821", type="observations") ina_data = inrbot.get_ina_data(obs_id) photo, found = inrbot.find_photo_in_obs(page, obs_id, ina_data) assert found == "sha1" assert photo._replace(url="") == id_tuple(id="58381754", type="photos")
def test_find_photo_in_obs_photo(): page = mock.MagicMock() mock_compare = mock.Mock(return_value=False) mock_config = {"use_ssim": False} obs_id = id_tuple(id="36885889", type="observations") photo_id = id_tuple(id="58596679", type="photos") ina_data = inrbot.get_ina_data(obs_id) with mock.patch.dict("inrbot.config", mock_config): with mock.patch("inrbot.compare_photo_hashes", mock_compare): photo, found = inrbot.find_photo_in_obs(page, obs_id, ina_data, raw_photo_id=photo_id) assert mock_compare.call_count == 1
def test_find_photo_in_obs_ssim_pass(): page = pywikibot.FilePage(inrbot.site, "File:Acomys subspinosus 15087534.jpg") obs_id = id_tuple(id="10783720", type="observations") ina_data = inrbot.get_ina_data(obs_id) mock_config = {"use_ssim": True} from ssim import compute_ssim inrbot.compute_ssim = compute_ssim with mock.patch("inrbot.compare_photo_hashes", return_value=False): with mock.patch.dict("inrbot.config", mock_config): photo, found = inrbot.find_photo_in_obs(page, obs_id, ina_data) assert found.startswith("ssim") assert photo._replace(url="") == id_tuple(id="15087534", type="photos")
def test_find_photo_in_obs_ssim_fail(): page = pywikibot.FilePage(inrbot.site, "File:Acomys subspinosus 15087534.jpg") obs_id = id_tuple(id="10783720", type="observations") ina_data = inrbot.get_ina_data(obs_id) thumb_url = page.get_file_url(url_width=340) mock_url = mock.Mock(return_value=thumb_url) page.get_file_url = mock_url mock_config = {"use_ssim": True} from ssim import compute_ssim inrbot.compute_ssim = compute_ssim with mock.patch("inrbot.compare_photo_hashes", return_value=False): with mock.patch.dict("inrbot.config", mock_config): photo, found = inrbot.find_photo_in_obs(page, obs_id, ina_data) assert found == "notmatching" assert photo is None
def test_get_ina_data_wrong_endpoint(): ina_id = id_tuple(id="anticompositenumber", type="people") response = inrbot.get_ina_data(ina_id) assert response is None
def test_get_ina_data_observation(): ina_id = id_tuple(id="36885889", type="observations") response = inrbot.get_ina_data(ina_id) assert response assert type(response) is dict