def test_110(self): """deserialize, serialize, deserialize""" x1 = exceptions.deserialize(VALID_ERROR_DOC_NOTFOUND) sxml = x1.serialize() x2 = exceptions.deserialize(sxml) self.assertTrue(isinstance(x2, exceptions.NotFound)) self.assertEqual(x1.errorCode, x2.errorCode) self.assertEqual(x1.detailCode, x2.detailCode) self.assertEqual(x1.name, x2.name) self.assertEqual(x1.description, x2.description) self.assertEqual(x1.nodeId, x2.nodeId) self.assertEqual(x1.identifier, x2.identifier) self.assertEqual(x1.traceInformation, x2.traceInformation)
def test_1010(self): """deserialize, serialize, deserialize""" x1 = exceptions.deserialize(VALID_ERROR_DOC_NOTFOUND) sxml = x1.serialize() x2 = exceptions.deserialize(sxml) assert isinstance(x2, exceptions.NotFound) assert x1.errorCode == x2.errorCode assert x1.detailCode == x2.detailCode assert x1.name == x2.name assert x1.description == x2.description assert x1.nodeId == x2.nodeId assert x1.identifier == x2.identifier assert x1.traceInformation == x2.traceInformation
def test_1030(self): """deserialize, serialize, deserialize round trip 3""" x1 = exceptions.deserialize(VALID_ERROR_DOC_NOTFOUND_3) sxml = x1.serialize() x2 = exceptions.deserialize(sxml) assert isinstance(x2, exceptions.NotFound) assert x1.errorCode == x2.errorCode assert x1.detailCode == x2.detailCode assert x1.name == x2.name assert x1.description == x2.description assert x1.nodeId == x2.nodeId assert x1.identifier == x2.identifier self.sample.assert_equals(x1, 'valid_error_doc_notfound_3_round_trip_x1') self.sample.assert_equals(x2, 'valid_error_doc_notfound_3_round_trip_x2')
def test_1050(self): """deserialize, serialize, deserialize round trip 2.""" x1 = exceptions.deserialize(VALID_ERROR_DOC_NOTFOUND_2) s_xml = x1.serialize_to_display() x2 = exceptions.deserialize(s_xml) assert isinstance(x2, exceptions.NotFound) assert x1.errorCode == x2.errorCode assert x1.detailCode == x2.detailCode assert x1.name == x2.name assert x1.description == x2.description assert x1.nodeId == x2.nodeId assert x1.identifier == x2.identifier self.sample.assert_equals(x1, "valid_error_doc_notfound_2_round_trip_x1") self.sample.assert_equals(x2, "valid_error_doc_notfound_2_round_trip_x2")
def test_1000(self): """deserialize() valid error XML doc""" d1_exception = exceptions.deserialize(VALID_ERROR_DOC) assert isinstance(d1_exception, exceptions.IdentifierNotUnique) assert d1_exception.detailCode == '123.456.789' assert d1_exception.errorCode == 409 assert d1_exception.name == 'IdentifierNotUnique' assert d1_exception.identifier == 'SomeDataONEPID' assert d1_exception.nodeId == 'urn:node:SomeNode' assert d1_exception.description == 'description0' assert d1_exception.traceInformation == TRACE_SECTION.strip()
def test_100(self): """deserialize()""" d1_exception = exceptions.deserialize(VALID_ERROR_DOC) self.assertTrue( isinstance(d1_exception, exceptions.IdentifierNotUnique)) self.assertEqual(d1_exception.detailCode, '123.456.789') self.assertEqual(d1_exception.errorCode, 409) self.assertEqual(d1_exception.name, 'IdentifierNotUnique') self.assertEqual(d1_exception.identifier, 'SomeDataONEPID') self.assertEqual(d1_exception.nodeId, 'urn:node:SomeNode') self.assertEqual(d1_exception.description, 'description0') self.assertEqual(d1_exception.traceInformation, TRACE_SECTION.strip())
def test_400(self): """Test serialization and deserialization of DataONE Exceptions Test serialization and deserialization of DataONE Exceptions by performing a round trip: 1) Create a native DataONE Exception object. 2) Serialize the object to XML. 3) Deserialize XML to object. 4) Verify that the object contains the same information as in (1). """ # Create a native DataONE IdentifierNotUnique Exception object. exc = exceptions.IdentifierNotUnique(1010, 'description_test', 'test trace information', 'test_pid', 'node_id') # Serialize to XML. exc_ser_xml = exc.serialize() #print exc_ser_xml # Check XML. dom = xml.dom.minidom.parseString(exc_ser_xml) root = dom.firstChild self.assertEqual(root.tagName, u'error') self.assertEqual(root.attributes['detailCode'].value, u'1010') self.assertEqual(root.attributes['errorCode'].value, u'409') self.assertEqual(root.attributes['name'].value, u'IdentifierNotUnique') self.assertEqual(root.attributes['identifier'].value, u'test_pid') self.assertEqual( root.getElementsByTagName('description') [0].childNodes[0].nodeValue, u'description_test') # Disabled until we have decided how to encode traceInformation. #self.assertEqual(root.getElementsByTagName('traceInformation')[0]\ # .childNodes[0].nodeValue, u'test trace information') # Deserialize XML. exc_deser = exceptions.deserialize(exc_ser_xml) # Check deserialized native object. self.assertEqual(exc_deser.detailCode, '1010') self.assertEqual(exc_deser.errorCode, 409) self.assertEqual(exc_deser.name, 'IdentifierNotUnique') self.assertEqual(exc_deser.identifier, 'test_pid') self.assertEqual(exc_deser.description, 'description_test')
def test_1140(self): """Serialization and deserialization of DataONE Exceptions. Test serialization and deserialization of DataONE Exceptions by performing a round trip: 1) Create a native DataONE Exception object 2) Serialize the object to XML 3) Deserialize XML to object 4) Verify that the object contains the same information as in (1) """ # Create a native DataONE IdentifierNotUnique Exception object. exc = exceptions.IdentifierNotUnique(1010, "description_test", "test trace information", "test_pid", "node_id") # Serialize to XML. exc_ser_xml = exc.serialize_to_display() # Check XML. dom = xml.dom.minidom.parseString(exc_ser_xml) root = dom.firstChild assert root.tagName == "error" assert root.attributes["detailCode"].value == "1010" assert root.attributes["errorCode"].value == "409" assert root.attributes["name"].value == "IdentifierNotUnique" assert root.attributes["identifier"].value == "test_pid" assert (root.getElementsByTagName("description") [0].childNodes[0].nodeValue == "description_test") # Disabled until we have decided how to encode traceInformation. # self.assertEqual(root.getElementsByTagName('traceInformation')[0]\ # .childNodes[0].nodeValue, u'test trace information') # Deserialize XML. exc_deserialize = exceptions.deserialize(exc_ser_xml) # Check deserialized native object. assert exc_deserialize.detailCode == "1010" assert exc_deserialize.errorCode == 409 assert exc_deserialize.name == "IdentifierNotUnique" assert exc_deserialize.identifier == "test_pid" assert exc_deserialize.description == "description_test"
def test_1050(self): """String representation""" d1_exception = exceptions.deserialize(VALID_ERROR_DOC) assert 'name: IdentifierNotUnique' in str(d1_exception) assert 'errorCode: 409' in str(d1_exception) assert 'detailCode: 123.456.789' in str(d1_exception)
def test_1040(self): """deserialize() of bad document raises ServiceFailure""" with pytest.raises(exceptions.ServiceFailure): exceptions.deserialize(INVALID_ERROR_DOC[0])
def test_1080(self): """String representation.""" d1_exception = exceptions.deserialize(VALID_ERROR_DOC) assert "name: IdentifierNotUnique" in str(d1_exception) assert "errorCode: 409" in str(d1_exception) assert "detailCode: 123.456.789" in str(d1_exception)