77
88
99TEST_SHA256 = "38acb15d02d5ac0f2a2789602e9df950c380d2799b4bdb59394e4eeabdd3a662"
10+ TEST_XFC_ID = "test"
1011BAD_SHA256 = "asdf"
1112TEST_DATA = b"test data"
1213
@@ -19,6 +20,14 @@ def mock_file_download(httpserver_auth: HTTPServer):
1920 return httpserver_auth
2021
2122
23+ @pytest .fixture
24+ def mock_file_download_by_xfc (httpserver_auth : HTTPServer ):
25+ httpserver_auth .expect_request (
26+ f"/v1/files/get-file-by-xfc-content-id/{ TEST_XFC_ID } "
27+ ).respond_with_data (response_data = TEST_DATA , status = 200 )
28+ return httpserver_auth
29+
30+
2231@pytest .fixture
2332def mock_bad_sha256 (httpserver_auth : HTTPServer ):
2433 httpserver_auth .expect_request (
@@ -35,6 +44,14 @@ def mock_file_not_found(httpserver_auth: HTTPServer):
3544 return httpserver_auth
3645
3746
47+ @pytest .fixture
48+ def mock_file_not_found_by_xfc_id (httpserver_auth : HTTPServer ):
49+ httpserver_auth .expect_request (
50+ f"/v1/files/get-file-by-xfc-content-id/{ TEST_XFC_ID } "
51+ ).respond_with_data (response_data = "" , status = 404 )
52+ return httpserver_auth
53+
54+
3855def test_download_file_by_sha256_calls_with_correct_parameter (
3956 mock_file_download , tmp_path
4057):
@@ -70,6 +87,35 @@ def test_stream_file_by_sha256_streams_file(mock_file_download):
7087 assert content == TEST_DATA
7188
7289
90+ def test_download_file_by_xfc_id_calls_with_correct_parameter (
91+ mock_file_download_by_xfc , tmp_path
92+ ):
93+ c = Client ()
94+ p = tmp_path / "testfile.test"
95+ f = c .files .v1 .download_file_by_xfc_content_id (TEST_XFC_ID , p )
96+ with open (f , "rb" ) as file :
97+ content = file .read ()
98+ assert content == TEST_DATA
99+ mock_file_download_by_xfc .check ()
100+
101+
102+ def test_download_file_by_xfc_id_raises_error_when_file_not_found (
103+ mock_file_not_found_by_xfc_id ,
104+ ):
105+ c = Client ()
106+ with pytest .raises (HTTPError ) as error :
107+ c .files .v1 .download_file_by_xfc_content_id (TEST_XFC_ID , "testpath.text" )
108+ assert error .value .response .status_code == 404
109+ mock_file_not_found_by_xfc_id .check ()
110+
111+
112+ def test_stream_file_by_xfc_id_streams_file (mock_file_download_by_xfc ):
113+ c = Client ()
114+ response = c .files .v1 .stream_file_by_xfc_content_id (TEST_XFC_ID )
115+ content = b"" .join ([c for c in response .iter_content (chunk_size = 128 ) if c ])
116+ assert content == TEST_DATA
117+
118+
73119# ************************************************ CLI ************************************************
74120
75121
0 commit comments