def test_ids_from_path(): """should get correct ids""" check.equal(resources.ids_from_path( "study/1/series/2/instances/3"), {'study_id': '1', 'series_id': '2', 'instance_id': '3', }) check.equal(resources.ids_from_path( "study/1/series/2/instances/3/frames/4"), {'study_id': '1', 'series_id': '2', 'instance_id': '3', 'frame_id': '4'})
def test_get_path_level(): """should get correct level""" check.equal(resources.get_path_level( resources.ids_from_path("")), "root") check.equal(resources.get_path_level( resources.ids_from_path("study/1/series/1/instances/3")), "instances") check.equal(resources.get_path_level( resources.ids_from_path("study/1/series/1/instances/3/frames/2")), "frames")
def test_download_path(): """should download correct file by path""" httpretty.register_uri( httpretty.GET, URL + "/studies/1/series/2/instances/3", body="3.dcm", adding_headers={ 'Content-Type': 'application/dicom'} ) requests = requests_util.Requests(URL, None) requests.download_dicom_by_ids(resources.ids_from_path( "studies/1/series/2/instances/3"), "./testData", None) assert os.path.isfile("./testData/1/2/3.dcm") file = open("./testData/1/2/3.dcm", 'r') data = file.read() assert data == "3.dcm"
def test_download_multipart(): """should download correct file by json based dict""" mock_data = [b'1C\r\n--123 Content-Type:image/png\r\n4\r\ndata\r\n1C\r\n\ --123 Content-Type:image/png\r\n5\r\ndata2\r\n5\r\n--123\r\n0\r\n\r\n'] httpretty.register_uri( httpretty.GET, URL + "/studies/6/series/7/instances/8", body=(l for l in mock_data), adding_headers={ 'Content-Type': 'multipart/related; type="image/png"; boundary=123;', 'transfer-encoding': 'chunked'}, streaming=True ) requests = requests_util.Requests(URL, None) requests.download_dicom_by_ids(resources.ids_from_path( "studies/6/series/7/instances/8"), "./testData", "image/png") assert os.path.isfile("./testData/6/7/8_frame_1.png") assert os.path.isfile("./testData/6/7/8_frame_2.png") file = open("./testData/6/7/8_frame_2.png", 'r') data = file.read() assert data == 'data2'
def test_path_from_ids(): """should get correct path from ids""" path = "/studies/1/series/2/instances/3" assert resources.path_from_ids(resources.ids_from_path(path)) == path