示例#1
0
 def test_fail_validation(self):
     """validation should fail"""
     httpretty.register_uri(httpretty.GET,
                            "https://dicom.com/studies?limit=1",
                            match_querystring=True,
                            status=404)
     with self.assertRaises(SystemExit):
         dcmweb.Dcmweb("https://dicom.com/", False, None)
def test_delete():
    """delete request should be performed in old and new api"""
    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/v1/dicomWeb/studies?limit=1",
                           match_querystring=True)
    dcmweb_cli = dcmweb.Dcmweb("https://dicom.com/v1/dicomWeb/", False, None)
    empty_response = DeleteResponse('{}')

    httpretty.register_uri(httpretty.DELETE,
                           "https://dicom.com/v1/dicomWeb/studies/1",
                           status=200,
                           match_querystring=True,
                           body=empty_response.request_callback)
    dcmweb_cli.delete("studies/1")

    assert empty_response.requested

    operation_response = DeleteResponse('{"name":"/operation/1"}')
    operation_progress = OperationProgress()

    httpretty.register_uri(httpretty.DELETE,
                           "https://dicom.com/v1/dicomWeb/studies/2",
                           status=200,
                           match_querystring=True,
                           body=operation_response.request_callback)

    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/v1/operation/1",
                           status=200,
                           match_querystring=True,
                           body=operation_progress.request_callback)

    dcmweb_cli.delete("studies/2")

    assert operation_progress.requests < 1
    assert operation_response.requested

    operation_response = DeleteResponse('{"name":"/operation/2"}')
    httpretty.register_uri(httpretty.DELETE,
                           "https://dicom.com/v1/dicomWeb/studies/3",
                           status=200,
                           match_querystring=True,
                           body=operation_response.request_callback)

    httpretty.register_uri(
        httpretty.GET,
        "https://dicom.com/v1/operation/2",
        status=404,
        match_querystring=True,
    )

    assert dcmweb_cli.delete("studies/3") == "/operation/2"
示例#3
0
 def test_retrieve(self):  # pylint: disable=no-self-use; method in class for cleaner look by setup method
     """should get all avalible files and single one"""
     output = "./testData/"
     for multithreading in (True, False):
         dcmweb_cli = dcmweb.Dcmweb(
             URL, multithreading, None)
         for path, files in RETRIEVE_CASES.items():
             dcmweb_cli.retrieve(path, output)
             for file in files:
                 file_path = output + file
                 file_exists = os.path.isfile(file_path)
                 check.is_true(file_exists, "can't find file {} in {} mode after retrieving {}"\
                     .format(file_path, "parallel" if multithreading else "sequential", path))
                 if file_exists:
                     os.remove(file_path)
             shutil.rmtree(output)
示例#4
0
def test_store():
    """files should be uploaded correctly"""
    requests_counter = RequestsCounter()
    httpretty.register_uri(httpretty.POST,
                           "https://dicom.com/studies",
                           body=requests_counter.request_callback)
    httpretty.register_uri(httpretty.GET, "https://dicom.com/studies?limit=1")

    for multithreading in (True, False):
        dcmweb_cli = dcmweb.Dcmweb("https://dicom.com/", multithreading, None)
        for mask, amount in FILE_PATH_CASES.items():
            dcmweb_cli.store(mask)
            check.equal(requests_counter.requests, amount,\
            "incorrect amount of uploaded files for {} mask in {} mode, should be {}"\
            .format(mask, "parallel" if multithreading else "sequential", amount))
            requests_counter.reset()
def test_search():
    """request shuld use limit from search"""
    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/studies?limit=1",
                           match_querystring=True)
    dcmweb_cli = dcmweb.Dcmweb("https://dicom.com/", False, None)
    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/study/123?limit=1",
                           body='[{"single": "response1"}]\n',
                           match_querystring=True)
    response1 = [{"single": "response1"}]
    assert dcmweb_cli.search("study/123",
                             "limit=1") == json.dumps(response1,
                                                      indent=INDENT,
                                                      sort_keys=SORT_KEYS)
    assert dcmweb_cli.search("study/123",
                             "?limit=1") == json.dumps(response1,
                                                       indent=INDENT,
                                                       sort_keys=SORT_KEYS)
    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/study/123?limit=5000",
                           body='[{"single": "response2"}]\n',
                           match_querystring=True)
    response2 = [{"single": "response2"}]
    assert dcmweb_cli.search("study/123",
                             "") == json.dumps(response2,
                                               indent=INDENT,
                                               sort_keys=SORT_KEYS)
    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/studies?limit=5000",
                           body='[{"single": "response3"}]\n',
                           match_querystring=True)
    response3 = [{"single": "response3"}]
    assert dcmweb_cli.search() == json.dumps(response3,
                                             indent=INDENT,
                                             sort_keys=SORT_KEYS)

    httpretty.register_uri(httpretty.GET,
                           "https://dicom.com/study/1234?limit=1",
                           status=204,
                           match_querystring=True)
    assert dcmweb_cli.search("study/1234",
                             "limit=1") == json.dumps([],
                                                      indent=INDENT,
                                                      sort_keys=SORT_KEYS)
示例#6
0
def test_empty_store(caplog):
    """error message should be printed"""
    httpretty.register_uri(httpretty.GET, "https://dicom.com/studies?limit=1")
    dcmweb_cli = dcmweb.Dcmweb("https://dicom.com/", True, None)
    dcmweb_cli.store("/wrong/path")
    assert caplog.records[-1].message == "No files found matching /wrong/path"