def testAdd(self):
        sruUpload = SruUpload(apiKey="apiKey")
        socket = CallTrace()

        answers = ["""HTTP/1.0 200 OK\r\n\r\n""", SUCCESS_SRU_UPLOAD_RESPONSE, ""]
        def recv(size):
            return answers.pop(0)
            
        socket.methods['recv'] = recv
        sruUpload._socket = lambda: socket

        lico(sruUpload.add(identifier="IDENTIFIER", lxmlNode=parse(StringIO("""<oai:record xmlns:oai="%(oai)s"><oai:metadata><xml/></oai:metadata></oai:record>""" % namespaces))))
        self.assertEquals([
            "connect(('localhost', 8000))", 
            "send('POST /update HTTP/1.0\r\n')", 
            "send('Content-Type: text/xml\r\n')", 
            "send('Content-Length: 609\r\n')", 
            "send('Authorization: apiKey\r\n')", 
            "send('\r\n')", 
            'sendall(\'<ucp:updateRequest xmlns:ucp="info:lc/xmlns/update-v1">\n            <srw:version xmlns:srw="http://www.loc.gov/zing/srw/">1.0</srw:version>\n            <ucp:action>info:srw/action/1/replace</ucp:action>\n            <ucp:recordIdentifier>IGNORED</ucp:recordIdentifier>\n            <srw:record xmlns:srw="http://www.loc.gov/zing/srw/">\n                <srw:recordPacking>xml</srw:recordPacking>\n                <srw:recordSchema>rdf</srw:recordSchema>\n                <srw:recordData><xml xmlns:oai="http://www.openarchives.org/OAI/2.0/"/></srw:recordData>\n            </srw:record>\n        </ucp:updateRequest>\')', 
            'recv(1024)', 
            'recv(1024)', 
            'recv(1024)', 
            'close()'], [str(m) for m in socket.calledMethods])
 def testFailedUpload(self):
     sruUpload = SruUpload(apiKey="apiKey")
     sruUpload._send = lambda data: "HTTP/1.0 200 Ok\r\n\r\n" + FAILED_SRU_UPLOAD_RESPONSE
     self.assertRaises(SruUploadException, lambda: lico(sruUpload.add(identifier="IDENTIFIER", lxmlNode=parse(StringIO("""<oai:record xmlns:oai="%(oai)s"><oai:metadata><xml/></oai:metadata></oai:record>""" % namespaces)))))