예제 #1
0
    def test_Response_DicomXML(self):
        response = odil.webservices.QIDORSResponse()
        response.set_representation(odil.webservices.Utils.Representation.DICOM_XML)
        response.set_data_sets(self.data_sets)
        self.assertEqual(response.get_media_type(), "application/dicom+xml")
        self.assertEqual(response.get_representation(), odil.webservices.Utils.Representation.DICOM_XML)
        http = response.get_http_response()

        message_bytes = [
            name.encode()+b": "+value.encode()
            for (name, value) in http.get_headers().items()]
        message_bytes.append(http.get_body())
        message_bytes = b"\r\n".join(message_bytes)
        if sys.version_info[0] >= 3:
            msg = email.message_from_bytes(message_bytes)
        else:
            msg = email.message_from_string(message_bytes)
        self.assertTrue(msg.is_multipart())

        i = 0
        for part in msg.walk():
            if part.get_content_type() == "application/dicom+xml":
                self.assertEqual(odil.as_xml(self.data_sets[i], False), part.get_payload())
                i = i+1
        self.assertEqual(i, len(self.data_sets))
예제 #2
0
    def test_difference(self):
        http_response = odil.webservices.HTTPResponse()
        http_response.set_header("Content-Type", "application/dicom+xml")
        http_response.set_status(200)
        http_response.set_reason("OK")
        http_response.set_body(odil.as_xml(self.data_set, False))
        response = odil.webservices.STOWRSResponse(http_response)

        http_response_2 = odil.webservices.HTTPResponse()
        http_response_2.set_header("Content-Type", "application/dicom+xml")
        http_response_2.set_status(400)
        http_response_2.set_reason("Bad Request")
        http_response_2.set_body(odil.as_xml(self.data_set, False))
        response_2 = odil.webservices.STOWRSResponse(http_response_2)

        self.assertTrue(response != response_2)
예제 #3
0
    def test_difference(self):
        http_response = odil.webservices.HTTPResponse()
        http_response.set_header("Content-Type", "application/dicom+xml")
        http_response.set_status(200)
        http_response.set_reason("OK")
        http_response.set_body(odil.as_xml(self.data_set, False))
        response = odil.webservices.STOWRSResponse(http_response)

        http_response_2 = odil.webservices.HTTPResponse()
        http_response_2.set_header("Content-Type", "application/dicom+xml")
        http_response_2.set_status(400)
        http_response_2.set_reason("Bad Request")
        http_response_2.set_body(odil.as_xml(self.data_set, False))
        response_2 = odil.webservices.STOWRSResponse(http_response_2)

        self.assertTrue(response != response_2)
예제 #4
0
    def test_Response_DicomXML(self):
        response = odil.webservices.QIDORSResponse()
        response.set_representation(
            odil.webservices.Utils.Representation.DICOM_XML)
        response.set_data_sets(self.data_sets)
        self.assertEqual(response.get_media_type(), "application/dicom+xml")
        self.assertEqual(response.get_representation(),
                         odil.webservices.Utils.Representation.DICOM_XML)
        http = response.get_http_response()

        # Convert http response into string
        http_str = ""
        h = []
        for header in http.get_headers():
            h.append(header.key())
        for header in h:
            http_str += header + ": " + http.get_header(header)
        http_str += "\r\n" + http.get_body()

        msg = email.message_from_string(http_str)
        self.assertTrue(msg.is_multipart())

        i = 0
        for part in msg.walk():
            if part.get_content_type() == "application/dicom+xml":
                self.assertEqual(odil.as_xml(self.data_sets[i], False),
                                 part.get_payload())
                i = i + 1
        self.assertEqual(i, len(self.data_sets))
예제 #5
0
    def test_respondDICOM_XML(self):
        response = odil.webservices.STOWRSResponse()
        response.set_representation(odil.webservices.Utils.Representation.DICOM_XML)
        response.set_store_instance_responses(self.data_set)
        self.assertEqual(response.get_media_type(), "application/dicom+xml")
        self.assertEqual(response.get_representation(), odil.webservices.Utils.Representation.DICOM_XML)
        http = response.get_http_response()

        msg = self._http_message_to_email_message(http)

        for part in msg.walk():
            if part.get_content_type() == "application/dicom+xml":
                self.assertEqual(odil.as_xml(self.data_set, False), part.get_payload())
예제 #6
0
    def test_equality(self):
        http_response = odil.webservices.HTTPResponse()
        http_response.set_header("Content-Type", "application/dicom+xml")
        http_response.set_status(200)
        http_response.set_reason("OK")
        http_response.set_body(odil.as_xml(self.data_set, False))

        response = odil.webservices.STOWRSResponse(http_response)
        response_2 = odil.webservices.STOWRSResponse()
        response_2.set_representation(odil.webservices.Utils.Representation.DICOM_XML)
        response_2.set_store_instance_responses(self.data_set)
        response_2.set_warning(False)
        response_2.set_reason("OK")
        self.assertEqual(response, response_2)
예제 #7
0
    def test_equality(self):
        http_response = odil.webservices.HTTPResponse()
        http_response.set_header("Content-Type", "application/dicom+xml")
        http_response.set_status(200)
        http_response.set_reason("OK")
        http_response.set_body(odil.as_xml(self.data_set, False))

        response = odil.webservices.STOWRSResponse(http_response)
        response_2 = odil.webservices.STOWRSResponse()
        response_2.set_representation(odil.webservices.Utils.Representation.DICOM_XML)
        response_2.set_store_instance_responses(self.data_set)
        response_2.set_warning(False)
        response_2.set_reason("OK")
        self.assertEqual(response, response_2)
예제 #8
0
    def test_respondDICOM_XML(self):
        response = odil.webservices.STOWRSResponse()
        response.set_representation(
            odil.webservices.Utils.Representation.DICOM_XML)
        response.set_store_instance_responses(self.data_set)
        self.assertEqual(response.get_media_type(), "application/dicom+xml")
        self.assertEqual(response.get_representation(),
                         odil.webservices.Utils.Representation.DICOM_XML)
        http = response.get_http_response()

        msg = self._http_message_to_email_message(http)

        for part in msg.walk():
            if part.get_content_type() == "application/dicom+xml":
                self.assertEqual(odil.as_xml(self.data_set, False),
                                 part.get_payload())
예제 #9
0
    def test_respondDICOMXML(self):
        wado = odil.webservices.WADORSResponse()
        wado.set_data_sets(self.data_sets)
        wado.respond_dicom(odil.webservices.Utils.Representation.DICOM_XML)
        self.assertEqual(wado.get_type(), odil.webservices.Utils.Type.DICOM)
        self.assertEqual(wado.get_representation(),
                         odil.webservices.Utils.Representation.DICOM_XML)
        http = wado.get_http_response()

        msg = self._http_message_to_email_message(http)
        self.assertTrue(msg.is_multipart())

        i = 0
        for part in msg.walk():
            if part.get_content_type() == "application/dicom+xml":
                self.assertEqual(odil.as_xml(self.data_sets[i], False),
                                 part.get_payload())
                i = i + 1
        self.assertEqual(i, len(self.data_sets))
예제 #10
0
    def test_respondDICOM_XML(self):
        response = odil.webservices.STOWRSResponse()
        response.set_representation(odil.webservices.Utils.Representation.DICOM_XML)
        response.set_store_instance_responses(self.data_set)
        self.assertEqual(response.get_media_type(), "application/dicom+xml")
        self.assertEqual(response.get_representation(), odil.webservices.Utils.Representation.DICOM_XML)
        http = response.get_http_response()

        # Convert http response into string

        http_str = ""
        h = []
        for header in http.get_headers():
            h.append(header.key())
        for header in h:
            http_str += header + ": " + http.get_header(header)
        http_str += "\r\n" + http.get_body()


        msg = email.message_from_string(http_str)

        for part in msg.walk():
            if part.get_content_type() == "application/dicom+xml":
                self.assertEqual(odil.as_xml(self.data_set, False), part.get_payload())
예제 #11
0
def as_xml(input, output, pretty_print):
    with odil.open(input) as stream:
        _, data_set = odil.Reader.read_file(stream)
    with open(output, "w") as fd:
        xml = odil.as_xml(data_set, pretty_print)
        fd.write(xml)
예제 #12
0
파일: transcode.py 프로젝트: lamyj/odil
def as_xml(input, output, pretty_print):
    with odil.open(input) as stream:
        _, data_set = odil.Reader.read_file(stream)
    with open(output, "w") as fd:
        xml = odil.as_xml(data_set, pretty_print)
        fd.write(xml)
예제 #13
0
 def test_pretty_print(self):
     serialized = odil.as_xml(self.data_set, True)
     serialized = re.sub(r"\n\s+", "\n", serialized, re.M)
     serialized = re.sub(r"\n", "", serialized)
     self.assertEqual(serialized, self.xml)
예제 #14
0
 def test_ugly_print(self):
     serialized = odil.as_xml(self.data_set, False)
     self.assertEqual(re.sub(r"\n+", "", serialized), self.xml)
예제 #15
0
파일: transcode.py 프로젝트: cguebert/odil
def as_xml(input, output, pretty_print):
    _, data_set = odil.read(input)
    with open(output, "w") as fd:
        xml = odil.as_xml(data_set, pretty_print)
        fd.write(xml)
예제 #16
0
def as_xml(input, output, pretty_print):
    _, data_set = odil.read(input)
    with open(output, "w") as fd:
        xml = odil.as_xml(data_set, pretty_print)
        fd.write(xml)