Ejemplo n.º 1
0
 def testRewriteAll(self):
     orig = 'http://'
     url = urlrewrite.rewrite(orig,
         hostname='localhost', port=5984,
         username='******', password='******',
         path='/mushin')
     self.assertEquals(url, 'http://*****:*****@localhost:5984/mushin')
Ejemplo n.º 2
0
 def testNoRewriteAll(self):
     orig = 'http://*****:*****@ana:5985/mushint'
     url = urlrewrite.rewrite(orig,
         hostname='localhost', port=5984,
         username='******', password='******',
         path='/mushin')
     self.assertEquals(url, orig)
Ejemplo n.º 3
0
    def doLater(self, args):

        c = self.getRootCommand()

        try:
            url = args[0]
        except IndexError:
            self.stdout.write('Please give a database to replicate with.\n')
            return

        # urlparse really needs a scheme there
        if not url.startswith('http'):
            url = 'http://' + url

        server = c.getNewServer()
        # FIXME: don't poke privately
        client = server._couch

        # if a username was given, but no password, ask for it
        parsed = urlparse.urlparse(url)
        password = None
        if parsed.username and not parsed.password:
            password = c.getPassword(
                prompt='\nPassword for target database %s: ' % url)

        jane = urlrewrite.rewrite(url, hostname=HOST, port=PORT,
            password=password, path='/' + DB)

        dbs = [
          c.dbName,
          jane,
        ]


        for source, target in [(dbs[0], dbs[1]), (dbs[1], dbs[0])]:
            s = json.dumps({
              "source": source,
              "target": target,
              "continuous": True})
            self.info('replicating from %s to %s',
                urlrewrite.rewrite_safe(source),
                urlrewrite.rewrite_safe(target))

            try:
                d = client.post('/_replicate', s)
            except Exception, e:
                self.stdout.write('Exception %r\n', e)
                self.stdout.write(
                    'FAILED: local server failed for source %s\n' %
                        source.encode('utf-8'))
                self.stdout.write('Is the server running ?\n')
                defer.returnValue(e)
                return

            error = None # set with a non-newline string in case of error

            try:
                result = yield d
            except twerror.Error, e:
                error = 'CouchDB returned error response %r' % e.status
                try:
                    self.debug('CouchDB message: %r', e.message)
                    r = json.loads(e.message)
                    error = 'CouchDB returned error reason: %s' % r['reason']
                except:
                    pass
Ejemplo n.º 4
0
 def testDefaultUsername(self):
     url = urlrewrite.rewrite('http://:80', hostname='localhost',
         username='******')
     self.assertEquals(url, 'http://thomas:@localhost:80')
Ejemplo n.º 5
0
 def testDefaultHost(self):
     url = urlrewrite.rewrite('http://:80', hostname='localhost')
     self.assertEquals(url, 'http://localhost:80')