44
55from okdata .sdk .data .download import Download
66
7- data_downloader = Download ()
8-
97file_name = "kake.csv"
108s3_key = f"procecced/raw/green/{ file_name } "
119download_url = "https://www.dowload-stuff.com"
1816
1917
2018def test_download (mock_home_dir , mock_http_calls ):
19+ data_downloader = Download ()
20+ output_path = f"{ os .environ ['HOME' ]} /my/path"
21+ result = data_downloader .download (
22+ dataset_id , version , edition , output_path = output_path
23+ )
24+ exp_output_file_path = f"{ output_path } /{ file_name } "
25+ with open (exp_output_file_path , "r" ) as f :
26+ assert str (f .read ()) == test_file_content
27+ assert result == {"files" : [exp_output_file_path ]}
28+
29+
30+ def test_download_public (mock_home_dir , mock_http_calls_public ):
31+ data_downloader = Download ()
32+ data_downloader .auth .token_provider = None
2133 output_path = f"{ os .environ ['HOME' ]} /my/path"
2234 result = data_downloader .download (
2335 dataset_id , version , edition , output_path = output_path
@@ -38,7 +50,21 @@ def mock_http_calls(requests_mock):
3850
3951 requests_mock .register_uri (
4052 "GET" ,
41- f"{ data_downloader .data_exporter_url } /{ dataset_id } /{ version } /{ edition } " ,
53+ f"{ Download ().data_exporter_url } /{ dataset_id } /{ version } /{ edition } " ,
54+ text = json .dumps ([{"key" : s3_key , "url" : download_url }]),
55+ status_code = 200 ,
56+ )
57+
58+ requests_mock .register_uri (
59+ "GET" , download_url , text = test_file_content , status_code = 200
60+ )
61+
62+
63+ @pytest .fixture (scope = "function" )
64+ def mock_http_calls_public (requests_mock ):
65+ requests_mock .register_uri (
66+ "GET" ,
67+ f"{ Download ().data_exporter_url } /public/{ dataset_id } /{ version } /{ edition } " ,
4268 text = json .dumps ([{"key" : s3_key , "url" : download_url }]),
4369 status_code = 200 ,
4470 )
0 commit comments