diff --git a/src/contact/check.rs b/src/contact/check.rs index 234b2c0..5d09a6a 100644 --- a/src/contact/check.rs +++ b/src/contact/check.rs @@ -55,10 +55,8 @@ pub struct ContactCheck<'a> { #[cfg(test)] mod tests { use super::ContactCheck; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -70,10 +68,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/contact/check.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/contact/check.xml"); let results = object.res_data().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/contact/create.rs b/src/contact/create.rs index 275f932..a2fe594 100644 --- a/src/contact/create.rs +++ b/src/contact/create.rs @@ -102,11 +102,9 @@ mod tests { use chrono::{TimeZone, Utc}; use super::{ContactCreate, Phone, PostalInfo}; - use crate::common::NoExtension; use crate::contact::Address; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -132,11 +130,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/contact/create.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); - + let object = response_from_file::("response/contact/create.xml"); let results = object.res_data().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/contact/delete.rs b/src/contact/delete.rs index fa308a7..21717e8 100644 --- a/src/contact/delete.rs +++ b/src/contact/delete.rs @@ -45,10 +45,8 @@ impl<'a> ContactDelete<'a> { #[cfg(test)] mod tests { use super::ContactDelete; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -58,11 +56,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/contact/delete.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); - + let object = response_from_file::("response/contact/delete.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); diff --git a/src/contact/info.rs b/src/contact/info.rs index 7fe5662..6af38a8 100644 --- a/src/contact/info.rs +++ b/src/contact/info.rs @@ -107,10 +107,8 @@ mod tests { use chrono::{TimeZone, Utc}; use super::ContactInfo; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -120,9 +118,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/contact/info.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/contact/info.xml"); let result = object.res_data().unwrap(); let fax = result.info_data.fax.as_ref().unwrap(); diff --git a/src/contact/update.rs b/src/contact/update.rs index aab3c87..8ba32ed 100644 --- a/src/contact/update.rs +++ b/src/contact/update.rs @@ -108,11 +108,10 @@ pub struct ContactUpdate<'a> { #[cfg(test)] mod tests { use super::{ContactUpdate, Phone, PostalInfo}; - use crate::common::{NoExtension, ObjectStatus}; + use crate::common::ObjectStatus; use crate::contact::Address; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -138,11 +137,7 @@ mod tests { #[test] fn contact_update() { - let xml = get_xml("response/contact/update.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); - + let object = response_from_file::("response/contact/update.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); diff --git a/src/domain/check.rs b/src/domain/check.rs index 93952a6..695913d 100644 --- a/src/domain/check.rs +++ b/src/domain/check.rs @@ -53,10 +53,8 @@ pub struct DomainCheck<'a> { #[cfg(test)] mod tests { use super::DomainCheck; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -68,10 +66,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/domain/check.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/domain/check.xml"); let result = object.res_data().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/domain/create.rs b/src/domain/create.rs index f0a1d27..1ea9fe8 100644 --- a/src/domain/create.rs +++ b/src/domain/create.rs @@ -109,11 +109,9 @@ mod tests { use chrono::{TimeZone, Utc}; use super::{DomainContact, DomainCreate, HostList, Period}; - use crate::common::NoExtension; use crate::domain::{HostAttr, HostAttrList, HostObjList}; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -219,9 +217,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/domain/create.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/domain/create.xml"); let result = object.res_data().unwrap(); diff --git a/src/domain/delete.rs b/src/domain/delete.rs index dde56d9..5eb71e7 100644 --- a/src/domain/delete.rs +++ b/src/domain/delete.rs @@ -45,10 +45,8 @@ pub struct DomainDelete<'a> { #[cfg(test)] mod tests { use super::DomainDelete; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -58,9 +56,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/domain/delete.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/domain/delete.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/src/domain/info.rs b/src/domain/info.rs index f1961b3..e91ac48 100644 --- a/src/domain/info.rs +++ b/src/domain/info.rs @@ -133,10 +133,8 @@ pub struct DomainInfoResponse { #[cfg(test)] mod tests { use super::DomainInfo; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; use chrono::{TimeZone, Utc}; #[test] @@ -147,9 +145,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/domain/info.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/domain/info.xml"); let result = object.res_data().unwrap(); let auth_info = result.info_data.auth_info.as_ref().unwrap(); @@ -205,7 +201,6 @@ mod tests { #[test] fn response_alt() { - let xml = get_xml("response/domain/info_alt.xml").unwrap(); - >::deserialize_response(xml.as_str()).unwrap(); + response_from_file::("response/domain/info_alt.xml"); } } diff --git a/src/domain/renew.rs b/src/domain/renew.rs index f8457ec..653e8b4 100644 --- a/src/domain/renew.rs +++ b/src/domain/renew.rs @@ -78,10 +78,8 @@ pub struct DomainRenewResponse { #[cfg(test)] mod tests { use super::{DomainRenew, Period}; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; use chrono::{NaiveDate, TimeZone, Utc}; @@ -94,9 +92,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/domain/renew.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/domain/renew.xml"); let result = object.res_data().unwrap(); diff --git a/src/domain/transfer.rs b/src/domain/transfer.rs index 0afc210..865119e 100644 --- a/src/domain/transfer.rs +++ b/src/domain/transfer.rs @@ -136,10 +136,8 @@ mod tests { use chrono::{TimeZone, Utc}; use super::{DomainTransfer, Period}; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn request_command() { @@ -174,10 +172,7 @@ mod tests { #[test] fn request_response() { - let xml = get_xml("response/domain/transfer_request.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); + let object = response_from_file::("response/domain/transfer_request.xml"); let result = object.res_data().unwrap(); @@ -211,10 +206,7 @@ mod tests { #[test] fn approve_response() { - let xml = get_xml("response/domain/transfer_approve.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); + let object = response_from_file::("response/domain/transfer_approve.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); @@ -224,10 +216,7 @@ mod tests { #[test] fn reject_response() { - let xml = get_xml("response/domain/transfer_reject.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); + let object = response_from_file::("response/domain/transfer_reject.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); @@ -237,10 +226,7 @@ mod tests { #[test] fn cancel_response() { - let xml = get_xml("response/domain/transfer_cancel.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); + let object = response_from_file::("response/domain/transfer_cancel.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); @@ -250,10 +236,7 @@ mod tests { #[test] fn query_response() { - let xml = get_xml("response/domain/transfer_query.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()) - .unwrap(); + let object = response_from_file::("response/domain/transfer_query.xml"); let result = object.res_data().unwrap(); diff --git a/src/domain/update.rs b/src/domain/update.rs index a349adb..8b263b9 100644 --- a/src/domain/update.rs +++ b/src/domain/update.rs @@ -102,10 +102,9 @@ pub struct DomainUpdate<'a> { #[cfg(test)] mod tests { use super::{DomainAddRemove, DomainAuthInfo, DomainChangeInfo, DomainContact, DomainUpdate}; - use crate::common::{NoExtension, ObjectStatus}; - use crate::request::Transaction; + use crate::common::ObjectStatus; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -145,9 +144,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/domain/update.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/domain/update.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/src/extensions/namestore.rs b/src/extensions/namestore.rs index 5aa0181..cca9cd8 100644 --- a/src/extensions/namestore.rs +++ b/src/extensions/namestore.rs @@ -97,8 +97,7 @@ pub struct NameStoreData<'a> { mod tests { use super::NameStore; use crate::domain::check::DomainCheck; - use crate::request::Transaction; - use crate::tests::{assert_serialized, get_xml}; + use crate::tests::{assert_serialized, response_from_file_with_ext}; #[test] fn command() { @@ -116,13 +115,10 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/extensions/namestore.xml").unwrap(); - - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file_with_ext::( + "response/extensions/namestore.xml", + ); let ext = object.extension.unwrap(); - assert_eq!(ext.data.subproduct, "com".into()); } } diff --git a/src/extensions/rgp/request.rs b/src/extensions/rgp/request.rs index fd11390..22457b7 100644 --- a/src/extensions/rgp/request.rs +++ b/src/extensions/rgp/request.rs @@ -70,9 +70,8 @@ mod tests { use super::{RgpRestoreRequest, Update}; use crate::domain::info::DomainInfo; use crate::domain::update::{DomainChangeInfo, DomainUpdate}; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file_with_ext, SUCCESS_MSG, SVTRID}; #[test] fn request_command() { @@ -97,13 +96,9 @@ mod tests { #[test] fn request_response() { - let xml = get_xml("response/extensions/rgp_restore.xml").unwrap(); - let object = - >>::deserialize_response( - xml.as_str(), - ) - .unwrap(); - + let object = response_from_file_with_ext::>( + "response/extensions/rgp_restore.xml", + ); let ext = object.extension.unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); @@ -114,12 +109,9 @@ mod tests { #[test] fn domain_info_request_response() { - let xml = get_xml("response/extensions/domain_info_rgp.xml").unwrap(); - let object = >>::deserialize_response( - xml.as_str(), - ) - .unwrap(); - + let object = response_from_file_with_ext::>( + "response/extensions/domain_info_rgp.xml", + ); let ext = object.extension.unwrap(); assert_eq!(ext.data.rgp_status[0].status, "addPeriod"); diff --git a/src/host/check.rs b/src/host/check.rs index bb0cd97..c0be38e 100644 --- a/src/host/check.rs +++ b/src/host/check.rs @@ -57,10 +57,8 @@ pub struct HostCheck<'a> { #[cfg(test)] mod tests { use super::HostCheck; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -72,10 +70,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/host/check.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/host/check.xml"); let result = object.res_data().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/host/create.rs b/src/host/create.rs index 400be0b..7776000 100644 --- a/src/host/create.rs +++ b/src/host/create.rs @@ -77,10 +77,8 @@ mod tests { use chrono::{TimeZone, Utc}; use super::{HostCreate, IpAddr}; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -95,10 +93,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/host/create.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/host/create.xml"); let result = object.res_data().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/host/delete.rs b/src/host/delete.rs index 95d828a..f7fbeec 100644 --- a/src/host/delete.rs +++ b/src/host/delete.rs @@ -45,10 +45,8 @@ pub struct HostDelete<'a> { #[cfg(test)] mod tests { use super::HostDelete; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -58,10 +56,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/host/delete.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/host/delete.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); diff --git a/src/host/info.rs b/src/host/info.rs index f76f18c..67de15a 100644 --- a/src/host/info.rs +++ b/src/host/info.rs @@ -109,10 +109,8 @@ mod tests { use chrono::{TimeZone, Utc}; use super::{HostInfo, IpAddr}; - use crate::common::NoExtension; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -122,10 +120,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/host/info.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/host/info.xml"); let result = object.res_data().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/host/update.rs b/src/host/update.rs index bec23e8..843acc3 100644 --- a/src/host/update.rs +++ b/src/host/update.rs @@ -94,10 +94,9 @@ pub struct HostUpdate<'a> { mod tests { use super::IpAddr; use super::{HostAddRemove, HostChangeInfo, HostUpdate}; - use crate::common::{NoExtension, ObjectStatus}; - use crate::request::Transaction; + use crate::common::ObjectStatus; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -132,9 +131,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/host/update.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/host/update.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/src/login.rs b/src/login.rs index 96d6713..f57a6e4 100644 --- a/src/login.rs +++ b/src/login.rs @@ -67,9 +67,8 @@ impl<'a> Command for Login<'a> { #[cfg(test)] mod tests { use super::Login; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -80,9 +79,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/login.xml").unwrap(); - let object = Login::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/login.xml"); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); diff --git a/src/logout.rs b/src/logout.rs index 30f1571..56dd63c 100644 --- a/src/logout.rs +++ b/src/logout.rs @@ -21,9 +21,8 @@ pub struct Logout; #[cfg(test)] mod tests { use super::Logout; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SVTRID}; #[test] fn command() { @@ -33,8 +32,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/logout.xml").unwrap(); - let object = Logout::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/logout.xml"); assert_eq!( object.result.code, diff --git a/src/message/ack.rs b/src/message/ack.rs index 5ee6a3f..96f2d64 100644 --- a/src/message/ack.rs +++ b/src/message/ack.rs @@ -34,9 +34,8 @@ impl<'a> MessageAck<'a> { #[cfg(test)] mod tests { use super::MessageAck; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, SUCCESS_MSG, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, SUCCESS_MSG, SVTRID}; #[test] fn command() { @@ -46,9 +45,7 @@ mod tests { #[test] fn response() { - let xml = get_xml("response/message/ack.xml").unwrap(); - let object = MessageAck::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/message/ack.xml"); let msg = object.message_queue().unwrap(); assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); diff --git a/src/message/poll.rs b/src/message/poll.rs index b7a2d6b..b30c870 100644 --- a/src/message/poll.rs +++ b/src/message/poll.rs @@ -52,9 +52,8 @@ pub struct MessagePollResponse { mod tests { use super::MessagePoll; use crate::message::poll::MessageData; - use crate::request::Transaction; use crate::response::ResultCode; - use crate::tests::{assert_serialized, get_xml, CLTRID, SVTRID}; + use crate::tests::{assert_serialized, response_from_file, CLTRID, SVTRID}; use chrono::{TimeZone, Utc}; use std::net::IpAddr; @@ -67,9 +66,7 @@ mod tests { #[test] fn domain_transfer_response() { - let xml = get_xml("response/message/poll_domain_transfer.xml").unwrap(); - let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/message/poll_domain_transfer.xml"); let result = object.res_data().unwrap(); let msg = object.message_queue().unwrap(); @@ -110,9 +107,7 @@ mod tests { #[test] fn host_info_response() { - let xml = get_xml("response/message/poll_host_info.xml").unwrap(); - let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/message/poll_host_info.xml"); let result = object.res_data().unwrap(); let msg = object.message_queue().unwrap(); @@ -159,9 +154,7 @@ mod tests { #[test] fn message_only_response() { - let xml = get_xml("response/message/poll_message_only.xml").unwrap(); - let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); - + let object = response_from_file::("response/message/poll_message_only.xml"); let msg = object.message_queue().unwrap(); assert_eq!( @@ -187,8 +180,7 @@ mod tests { #[test] fn empty_queue_response() { - let xml = get_xml("response/message/poll_empty_queue.xml").unwrap(); - let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); + let object = response_from_file::("response/message/poll_empty_queue.xml"); assert_eq!( object.result.code, diff --git a/src/tests/mod.rs b/src/tests/mod.rs index fa9a283..c260c6f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -6,7 +6,9 @@ use regex::Regex; use crate::{ client::RequestData, + common::NoExtension, request::{Command, CommandDocument, Extension, Transaction}, + response::{Response, ResponseDocument}, xml::EppXml, }; @@ -48,3 +50,26 @@ pub(crate) fn assert_serialized<'c, 'e, Cmd, Ext>( let actual = EppXml::serialize(&document).unwrap(); assert_eq!(expected, actual); } + +pub(crate) fn response_from_file<'c, Cmd>( + path: &str, +) -> Response::Response> +where + Cmd: Transaction + Command + 'c, +{ + response_from_file_with_ext::(path) +} + +pub(crate) fn response_from_file_with_ext( + path: &str, +) -> Response +where + Cmd: Transaction + Command, + Ext: Extension, +{ + let xml = get_xml(path).unwrap(); + let rsp = + as EppXml>::deserialize(&xml).unwrap(); + assert!(rsp.data.result.code.is_success()); + rsp.data +}