def testDelete(self):
     postArguments = []
     def _httppost(**kwargs):
         postArguments.append(kwargs)
         raise StopIteration(('HTTP/1.0 200 OK\r\n\r\n', SRU_UPDATE_RESPONSE % ("success", '')))
         yield
     sruUpdate = SruUpdateClient(host='localhost', port=1234, userAgent="testAgent")
     sruUpdate._httppost = _httppost
     list(compose(sruUpdate.delete(identifier='anIdentifier')))
     self.assertEquals(1, len(postArguments))
     arguments = postArguments[0]
     self.assertEquals('localhost', arguments['host'])
     self.assertEquals(1234, arguments['port'])
     self.assertEquals('/update', arguments['request'])
     self.assertEquals({"User-Agent": "testAgent", "Host": 'localhost'}, arguments['headers'])
     self.assertEqualsWS("""<?xml version="1.0" encoding="UTF-8"?>
         <ucp:updateRequest xmlns:srw="http://www.loc.gov/zing/srw/" xmlns:ucp="info:lc/xmlns/update-v1">
         <srw:version>1.0</srw:version>
         <ucp:action>info:srw/action/1/delete</ucp:action>
         <ucp:recordIdentifier>anIdentifier</ucp:recordIdentifier>
         <srw:record>
             <srw:recordPacking>xml</srw:recordPacking>
             <srw:recordSchema>ignored</srw:recordSchema>
             <srw:recordData><ignored/></srw:recordData>
         </srw:record>
     </ucp:updateRequest>""", arguments['body'])
示例#2
0
    def testDelete(self):
        postArguments = []

        def _httppost(**kwargs):
            postArguments.append(kwargs)
            raise StopIteration(('HTTP/1.0 200 OK\r\n\r\n',
                                 SRU_UPDATE_RESPONSE % ("success", '')))
            yield

        sruUpdate = SruUpdateClient(host='localhost',
                                    port=1234,
                                    userAgent="testAgent")
        sruUpdate._httppost = _httppost
        list(compose(sruUpdate.delete(identifier='anIdentifier')))
        self.assertEquals(1, len(postArguments))
        arguments = postArguments[0]
        self.assertEquals('localhost', arguments['host'])
        self.assertEquals(1234, arguments['port'])
        self.assertEquals('/update', arguments['request'])
        self.assertEquals({
            "User-Agent": "testAgent",
            "Host": 'localhost'
        }, arguments['headers'])
        self.assertEqualsWS(
            """<?xml version="1.0" encoding="UTF-8"?>
            <ucp:updateRequest xmlns:srw="http://www.loc.gov/zing/srw/" xmlns:ucp="info:lc/xmlns/update-v1">
            <srw:version>1.0</srw:version>
            <ucp:action>info:srw/action/1/delete</ucp:action>
            <ucp:recordIdentifier>anIdentifier</ucp:recordIdentifier>
            <srw:record>
                <srw:recordPacking>xml</srw:recordPacking>
                <srw:recordSchema>ignored</srw:recordSchema>
                <srw:recordData><ignored/></srw:recordData>
            </srw:record>
        </ucp:updateRequest>""", arguments['body'])
 def testAddFailed(self):
     postArguments = []
     def _httppost(**kwargs):
         postArguments.append(kwargs)
         raise StopIteration(('HTTP/1.0 200 OK\r\n\r\n', SRU_UPDATE_RESPONSE % ("fail", SRU_DIAGNOSTICS)))
         yield
     sruUpdate = SruUpdateClient()
     sruUpdate._httppost = _httppost
     sruUpdate.updateHostAndPort('localhost', 12345)
     try:
         list(compose(sruUpdate.add(identifier='anIdentifier', data='<xml/>')))
         self.fail("should not get here")
     except SruUpdateException, e:
         self.assertEquals(e.url, 'http://localhost:12345/update')
         self.assertEquals(e.status, 'fail')
         self.assertEquals(e.diagnostics, 'Traceback: some traceback')
    def testAddSuccessDataIsNotBytes(self):
        postArguments = []

        def _httppost(**kwargs):
            postArguments.append(kwargs)
            return [
                dict(StatusCode="200"),
                str(SRU_UPDATE_RESPONSE % (b"success", b''), encoding="utf-8")
            ]
            yield

        sruUpdate = SruUpdateClient(host='localhost',
                                    port=1234,
                                    userAgent="testAgent")
        sruUpdate._httppost = _httppost
        list(compose(sruUpdate.add(identifier='anIdentifier', data=b'<xml/>')))
        self.assertEqual(1, len(postArguments))
        arguments = postArguments[0]
        self.assertEqual('localhost', arguments['host'])
        self.assertEqual(1234, arguments['port'])
        self.assertEqual('/update', arguments['request'])
        self.assertEqual({
            "User-Agent": "testAgent",
            "Host": 'localhost'
        }, arguments['headers'])
        self.assertEqualsWS(
            """<?xml version="1.0" encoding="UTF-8"?>
            <ucp:updateRequest xmlns:srw="http://www.loc.gov/zing/srw/" xmlns:ucp="info:lc/xmlns/update-v1">
            <srw:version>1.0</srw:version>
            <ucp:action>info:srw/action/1/replace</ucp:action>
            <ucp:recordIdentifier>anIdentifier</ucp:recordIdentifier>
            <srw:record>
                <srw:recordPacking>xml</srw:recordPacking>
                <srw:recordSchema>rdf</srw:recordSchema>
                <srw:recordData><xml/></srw:recordData>
            </srw:record>
        </ucp:updateRequest>""", str(arguments['body'], encoding="utf-8"))
示例#5
0
    def testAddFailed(self):
        postArguments = []

        def _httppost(**kwargs):
            postArguments.append(kwargs)
            raise StopIteration(
                ('HTTP/1.0 200 OK\r\n\r\n',
                 SRU_UPDATE_RESPONSE % ("fail", SRU_DIAGNOSTICS)))
            yield

        sruUpdate = SruUpdateClient()
        sruUpdate._httppost = _httppost
        sruUpdate.updateHostAndPort('localhost', 12345)
        try:
            list(
                compose(sruUpdate.add(identifier='anIdentifier',
                                      data='<xml/>')))
            self.fail("should not get here")
        except SruUpdateException, e:
            self.assertEquals(e.url, 'http://localhost:12345/update')
            self.assertEquals(e.status, 'fail')
            self.assertEquals(e.diagnostics, 'Traceback: some traceback')
    def testAddFailed(self):
        postArguments = []

        def _httppost(**kwargs):
            postArguments.append(kwargs)
            return [
                dict(StatusCode="200"),
                SRU_UPDATE_RESPONSE % (b"fail", SRU_DIAGNOSTICS)
            ]
            yield

        sruUpdate = SruUpdateClient()
        sruUpdate._httppost = _httppost
        sruUpdate.updateHostAndPort('localhost', 12345)
        try:
            list(
                compose(
                    sruUpdate.add(identifier='anIdentifier', data=b'<xml/>')))
            self.fail("should not get here")
        except SruUpdateException as e:
            self.assertEqual(e.url, 'http://localhost:12345/update')
            self.assertEqual(e.status, 'fail')
            self.assertEqual(e.diagnostics, 'Traceback: some traceback')