Skip to content

Commit

Permalink
test if fallback URLs are used if main URL does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Sep 15, 2023
1 parent 0b2f96f commit 66ddc0a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

import pytest
import requests

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -141,7 +142,29 @@ def test_maybe_download_is_not_final(
requests_mock.register_uri("GET", url, content=csv_data)
csv_df = pd.read_csv(BytesIO(csv_data))

res = downloader.maybe_download(endpoint, callback=pd.read_csv, is_final=False)
res = downloader.maybe_download(endpoint, callback=pd.read_csv)

assert requests_mock.called_once
np.testing.assert_array_equal(res.index, csv_df.index)
np.testing.assert_array_equal(res.columns, csv_df.columns)
np.testing.assert_array_equal(res.values, csv_df.values)

def test_fallback_urls(self, requests_mock, csv_data: bytes):
query = "annotations?resources=PROGENy"
opt = Options(url="https://wrong.omnipathdb.org/")
requests_mock.register_uri(
"GET",
urljoin(opt.url, query),
exc=requests.exceptions.ConnectionError,
)
requests_mock.register_uri(
"GET",
urljoin(opt.fallback_urls[0], query),
content=csv_data,
)
csv_df = pd.read_csv(BytesIO(csv_data))
downloader = Downloader(opt)
res = downloader.maybe_download(query, callback=pd.read_csv)

assert requests_mock.called_once
np.testing.assert_array_equal(res.index, csv_df.index)
Expand Down

0 comments on commit 66ddc0a

Please sign in to comment.