Simplify response tests with a helper

This commit is contained in:
Dirkjan Ochtman 2022-03-12 18:02:51 +01:00 committed by masalachai
parent 5dce8501d5
commit dd5fbc60ce
24 changed files with 89 additions and 183 deletions

View File

@ -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 =
<ContactCheck as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<ContactCheck>("response/contact/check.xml");
let results = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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 =
<ContactCreate as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<ContactCreate>("response/contact/create.xml");
let results = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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 =
<ContactDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<ContactDelete>("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());

View File

@ -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 =
<ContactInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<ContactInfo>("response/contact/info.xml");
let result = object.res_data().unwrap();
let fax = result.info_data.fax.as_ref().unwrap();

View File

@ -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 =
<ContactUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<ContactUpdate>("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());

View File

@ -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 =
<DomainCheck as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<DomainCheck>("response/domain/check.xml");
let result = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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 =
<DomainCreate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<DomainCreate>("response/domain/create.xml");
let result = object.res_data().unwrap();

View File

@ -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 =
<DomainDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<DomainDelete>("response/domain/delete.xml");
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -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 =
<DomainInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<DomainInfo>("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();
<DomainInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
response_from_file::<DomainInfo>("response/domain/info_alt.xml");
}
}

View File

@ -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 =
<DomainRenew as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<DomainRenew>("response/domain/renew.xml");
let result = object.res_data().unwrap();

View File

@ -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 =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<DomainTransfer>("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 =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<DomainTransfer>("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 =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<DomainTransfer>("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 =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<DomainTransfer>("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 =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let object = response_from_file::<DomainTransfer>("response/domain/transfer_query.xml");
let result = object.res_data().unwrap();

View File

@ -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 =
<DomainUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<DomainUpdate>("response/domain/update.xml");
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -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 =
<DomainCheck as Transaction<NameStore>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file_with_ext::<DomainCheck, NameStore>(
"response/extensions/namestore.xml",
);
let ext = object.extension.unwrap();
assert_eq!(ext.data.subproduct, "com".into());
}
}

View File

@ -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 =
<DomainUpdate as Transaction<Update<RgpRestoreRequest>>>::deserialize_response(
xml.as_str(),
)
.unwrap();
let object = response_from_file_with_ext::<DomainUpdate, Update<RgpRestoreRequest>>(
"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 = <DomainInfo as Transaction<Update<RgpRestoreRequest>>>::deserialize_response(
xml.as_str(),
)
.unwrap();
let object = response_from_file_with_ext::<DomainInfo, Update<RgpRestoreRequest>>(
"response/extensions/domain_info_rgp.xml",
);
let ext = object.extension.unwrap();
assert_eq!(ext.data.rgp_status[0].status, "addPeriod");

View File

@ -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 =
<HostCheck as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<HostCheck>("response/host/check.xml");
let result = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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 =
<HostCreate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<HostCreate>("response/host/create.xml");
let result = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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 =
<HostDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<HostDelete>("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());

View File

@ -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 =
<HostInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<HostInfo>("response/host/info.xml");
let result = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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 =
<HostUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let object = response_from_file::<HostUpdate>("response/host/update.xml");
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -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::<Login>("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());

View File

@ -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::<Logout>("response/logout.xml");
assert_eq!(
object.result.code,

View File

@ -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::<MessageAck>("response/message/ack.xml");
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);

View File

@ -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::<MessagePoll>("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::<MessagePoll>("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::<MessagePoll>("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::<MessagePoll>("response/message/poll_empty_queue.xml");
assert_eq!(
object.result.code,

View File

@ -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<Cmd::Response, <NoExtension as Extension>::Response>
where
Cmd: Transaction<NoExtension> + Command + 'c,
{
response_from_file_with_ext::<Cmd, NoExtension>(path)
}
pub(crate) fn response_from_file_with_ext<Cmd, Ext>(
path: &str,
) -> Response<Cmd::Response, Ext::Response>
where
Cmd: Transaction<NoExtension> + Command,
Ext: Extension,
{
let xml = get_xml(path).unwrap();
let rsp =
<ResponseDocument<Cmd::Response, Ext::Response> as EppXml>::deserialize(&xml).unwrap();
assert!(rsp.data.result.code.is_success());
rsp.data
}