Skip to content

Instantly share code, notes, and snippets.

@justinvdm
Created September 25, 2013 09:58
Show Gist options
  • Select an option

  • Save justinvdm/6697516 to your computer and use it in GitHub Desktop.

Select an option

Save justinvdm/6697516 to your computer and use it in GitHub Desktop.
diff --git a/vumi/transports/mtn_nigeria/tests/test_xml_over_tcp.py b/vumi/transports/mtn_nigeria/tests/test_xml_over_tcp.py
index b61cb96..17998d7 100644
--- a/vumi/transports/mtn_nigeria/tests/test_xml_over_tcp.py
+++ b/vumi/transports/mtn_nigeria/tests/test_xml_over_tcp.py
@@ -124,12 +124,10 @@ class XmlOverTcpClientTestCase(unittest.TestCase, XmlOverTcpClientServerMixin):
def test_packet_body_serializing(self):
body = XmlOverTcpClient.serialize_body(
'DummyPacket',
- [('requestId', '123456789abcdefg'),
- ('foo', 1234)])
+ [('requestId', '123456789abcdefg')])
expected_body = (
"<DummyPacket>"
"<requestId>123456789abcdefg</requestId>"
- "<foo>1234</foo>"
"</DummyPacket>")
self.assertEqual(body, expected_body)
diff --git a/vumi/transports/mtn_nigeria/xml_over_tcp.py b/vumi/transports/mtn_nigeria/xml_over_tcp.py
index 393dda0..99d4e49 100644
--- a/vumi/transports/mtn_nigeria/xml_over_tcp.py
+++ b/vumi/transports/mtn_nigeria/xml_over_tcp.py
@@ -352,16 +352,10 @@ class XmlOverTcpClient(Protocol):
cls.serialize_header_field(session_id, cls.SESSION_ID_HEADER_SIZE),
cls.serialize_header_field(length, cls.LENGTH_HEADER_SIZE))
- @staticmethod
- def ensure_str(s):
- return s if isinstance(s, basestring) else str(s)
-
@classmethod
def serialize_body(cls, packet_type, params):
root = ET.Element(packet_type)
for param_name, param_value in params:
- param_name = cls.ensure_str(param_name)
- param_value = cls.ensure_str(param_value)
ET.SubElement(root, param_name).text = param_value
return ET.tostring(root).encode(cls.ENCODING)
@@ -396,7 +390,7 @@ class XmlOverTcpClient(Protocol):
# NOTE: The protocol requires request ids to be number only ids. With a
# request id length of 10 digits, generating ids using randint could
# well cause collisions to occur, although this should be unlikely.
- return randint(0, (10 ** cls.REQUEST_ID_LENGTH) - 1)
+ return str(randint(0, (10 ** cls.REQUEST_ID_LENGTH) - 1))
def login(self):
params = [
@hodgestar
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment