def test_downloader_populate_https(): # "images.key" with https action = DownloaderAction("key", "/path/to/save", params={"url": "https://url.org/resource.img"}) action.level = 1 action.populate( {"images": { "key": { "url": "https://url.org/resource.img" } }}) assert len(action.pipeline.actions) == 1 assert isinstance(action.pipeline.actions[0], HttpDownloadAction) assert action.pipeline.actions[0].url == urlparse( "https://url.org/resource.img") # "key" with https action = DownloaderAction("key", "/path/to/save", params={"url": "https://url.org/resource.img"}) action.level = 1 action.populate({"key": {"url": "https://url.org/resource.img"}}) assert len(action.pipeline.actions) == 1 assert isinstance(action.pipeline.actions[0], HttpDownloadAction) assert action.pipeline.actions[0].url == urlparse( "https://url.org/resource.img")
def test_downloader_no_url(): # 1. no url avaialbe action = DownloaderAction("key", "/path/to/save", params={}) action.level = 1 with pytest.raises(JobError) as exc: action.populate({"key": {}}) assert exc.match("Invalid deploy action: 'url' is missing for 'key'")
def test_downloader_populate_scp(): # "images.key" with scp action = DownloaderAction("key", "/path/to/save", params={"url": "scp://user@host:/resource.img"}) action.level = 1 action.populate( {"images": { "key": { "url": "scp://user@host:/resource.img" } }}) assert len(action.pipeline.actions) == 1 assert isinstance(action.pipeline.actions[0], ScpDownloadAction) assert action.pipeline.actions[0].url == urlparse( "scp://user@host:/resource.img") # "key" with scp action = DownloaderAction("key", "/path/to/save", params={"url": "scp://user@host:/resource.img"}) action.level = 1 action.populate({"key": {"url": "scp://user@host:/resource.img"}}) assert len(action.pipeline.actions) == 1 assert isinstance(action.pipeline.actions[0], ScpDownloadAction) assert action.pipeline.actions[0].url == urlparse( "scp://user@host:/resource.img")
def test_downloader_unsupported_scheme(): # Test raise # 1. unsuported scheme action = DownloaderAction("key", "/path/to/save", params={"url": "ftp://user@host:/resource.img"}) action.level = 1 with pytest.raises(JobError) as exc: action.populate({"key": {"url": "ftp://user@host:/resource.img"}}) assert exc.match("Unsupported url protocol scheme: ftp")
def test_downloader_populate_file(): # "images.key" with lxc action = DownloaderAction("key", "/path/to/save", params={"url": "lxc:///resource.img"}) action.level = 1 action.populate({"images": {"key": {"url": "lxc:///resource.img"}}}) assert len(action.pipeline.actions) == 1 assert isinstance(action.pipeline.actions[0], LxcDownloadAction) assert action.pipeline.actions[0].url == urlparse("lxc:///resource.img") # "key" with lxc action = DownloaderAction("key", "/path/to/save", params={"url": "lxc:///resource.img"}) action.level = 1 action.populate({"key": {"url": "lxc:///resource.img"}}) assert len(action.pipeline.actions) == 1 assert isinstance(action.pipeline.actions[0], LxcDownloadAction) assert action.pipeline.actions[0].url == urlparse("lxc:///resource.img")