def test_parse_uri(self):
        self.assertEqual(([("localhost", 27017)], None, None, None),
                         _parse_uri("localhost", 27017))
        self.assertEqual(([("localhost", 27018)], None, None, None),
                         _parse_uri("localhost", 27018))
        self.assertRaises(InvalidURI, _parse_uri,
                          "http://foobar.com", 27017)
        self.assertRaises(InvalidURI, _parse_uri,
                          "http://[email protected]", 27017)

        self.assertEqual(([("localhost", 27017)], None, None, None),
                         _parse_uri("mongodb://localhost", 27017))
        self.assertEqual(([("localhost", 27017)], None, "fred", "foobar"),
                         _parse_uri("mongodb://*****:*****@localhost",
                                               27017))
        self.assertEqual(([("localhost", 27017)], "baz", "fred", "foobar"),
                         _parse_uri("mongodb://*****:*****@localhost/baz",
                                               27017))
        self.assertEqual(([("example1.com", 27017), ("example2.com", 27017)],
                          None, None, None),
                         _parse_uri("mongodb://example1.com:27017,example2.com:27017",
                                               27018))
        self.assertEqual(([("localhost", 27017),
                           ("localhost", 27018),
                           ("localhost", 27019)], None, None, None),
                         _parse_uri("mongodb://localhost,localhost:27018,localhost:27019",
                                               27017))

        self.assertEqual(([("localhost", 27018)], None, None, None),
                         _parse_uri("localhost:27018", 27017))
        self.assertEqual(([("localhost", 27017)], "foo", None, None),
                         _parse_uri("localhost/foo", 27017))
        self.assertEqual(([("localhost", 27017)], None, None, None),
                         _parse_uri("localhost/", 27017))
Example #2
0
    def setup_backend(self):
        from pymongo import ASCENDING, DESCENDING
        from pymongo.connection import Connection, _parse_uri
        from pymongo.errors import AutoReconnect

        _connection = None
        uri = self.options.pop('uri', u'')
        _connection_attempts = 0

        hosts, database, user, password = _parse_uri(uri, Connection.PORT)

        # Handle auto reconnect signals properly
        while _connection_attempts < 5:
            try:
                if _connection is None:
                    _connection = Connection(uri)
                database = _connection[database]
                break
            except AutoReconnect:
                _connection_attempts += 1
                time.sleep(0.1)

        self.database = database

        # setup correct indexes
        database.tickets.ensure_index([('record_hash', ASCENDING)], unique=True)
        database.tickets.ensure_index([('solved', ASCENDING), ('level', ASCENDING)])
        database.occurrences.ensure_index([('time', DESCENDING)])
Example #3
0
    def setup_backend(self):
        from pymongo import ASCENDING, DESCENDING
        from pymongo.connection import Connection, _parse_uri
        from pymongo.errors import AutoReconnect

        _connection = None
        uri = self.options.pop('uri', u'')
        _connection_attempts = 0

        hosts, database, user, password = _parse_uri(uri, Connection.PORT)

        # Handle auto reconnect signals properly
        while _connection_attempts < 5:
            try:
                if _connection is None:
                    _connection = Connection(uri)
                database = _connection[database]
                break
            except AutoReconnect:
                _connection_attempts += 1
                time.sleep(0.1)

        self.database = database

        # setup correct indexes
        database.tickets.ensure_index([('record_hash', ASCENDING)],
                                      unique=True)
        database.tickets.ensure_index([('solved', ASCENDING),
                                       ('level', ASCENDING)])
        database.occurrences.ensure_index([('time', DESCENDING)])
Example #4
0
    def _connect(self, args, out, name = None, db = None, collection = None):
        """
        connect to a mongod
        """

        if type(args).__name__ == 'dict':
            out('{"ok" : 0, "errmsg" : "_connect must be a POST request"}')
            return

        if "server" in args:
            try:
                uri = args.getvalue('server')
                info = connection._parse_uri(uri)
            except Exception, e:
                print uri
                print e
                out('{"ok" : 0, "errmsg" : "invalid server uri given", "server" : "%s"}' % uri)
                return
Example #5
0
    def _connect(self, args, out, name=None, db=None, collection=None):
        """
        connect to a mongod
        """

        if type(args).__name__ == 'dict':
            out('{"ok" : 0, "errmsg" : "_connect must be a POST request"}')
            return

        if "server" in args:
            try:
                uri = args.getvalue('server')
                info = connection._parse_uri(uri)
            except Exception, e:
                print uri
                print e
                out('{"ok" : 0, "errmsg" : "invalid server uri given", "server" : "%s"}'
                    % uri)
                return
Example #6
0
    def setup_backend(self):
        from pymongo.connection import Connection, _parse_uri
        from pymongo.errors import AutoReconnect

        _connection = None
        uri = self.options.pop('uri', u'')
        _connection_attempts = 0

        hosts, database, user, password = _parse_uri(uri, Connection.PORT)

        # Handle auto reconnect signals properly
        while _connection_attempts < 5:
            try:
                if _connection is None:
                    _connection = Connection(uri)
                database = _connection[database]
                break
            except AutoReconnect:
                _connection_attempts += 1
                time.sleep(0.1)

        self.database = database
    def test_parse_uri(self):
        self.assertEqual(([("localhost", 27017)], None, None, None, None, {}),
                         _parse_uri("localhost", 27017))
        self.assertEqual(([("localhost", 27018)], None, None, None, None, {}),
                         _parse_uri("localhost", 27018))
        self.assertRaises(InvalidURI, _parse_uri,
                          "http://foobar.com", 27017)
        self.assertRaises(InvalidURI, _parse_uri,
                          "http://[email protected]", 27017)

        self.assertEqual(([("localhost", 27017)], None, None, None, None, {}),
                         _parse_uri("mongodb://localhost", 27017))
        self.assertEqual(([("localhost", 27017)], None,
                          "fred", "foobar", None, {}),
                         _parse_uri("mongodb://*****:*****@localhost",
                                               27017))
        self.assertEqual(([("localhost", 27017)], "baz",
                          "fred", "foobar", None, {}),
                         _parse_uri("mongodb://*****:*****@localhost/baz",
                                               27017))
        self.assertEqual(([("example1.com", 27017), ("example2.com", 27017)],
                          None, None, None, None, {}),
                         _parse_uri("mongodb://"
                                    "example1.com:27017,example2.com:27017",
                                    27018))
        self.assertEqual(([("localhost", 27017),
                           ("localhost", 27018),
                           ("localhost", 27019)], None, None, None, None, {}),
                         _parse_uri("mongodb://localhost,"
                                    "localhost:27018,localhost:27019",
                                    27017))

        self.assertEqual(([("localhost", 27018)], None, None, None, None, {}),
                         _parse_uri("localhost:27018", 27017))
        self.assertEqual(([("localhost", 27017)], "foo", None, None, None, {}),
                         _parse_uri("localhost/foo", 27017))
        self.assertEqual(([("localhost", 27017)], None, None, None, None, {}),
                         _parse_uri("localhost/", 27017))

        self.assertEqual(([("localhost", 27017)], "test",
                          None, None, "yield_historical.in", {}),
                         _parse_uri("mongodb://"
                                    "localhost/test.yield_historical.in",
                                    27017))
        self.assertEqual(([("localhost", 27017)], "test", "fred",
                          "foobar", "yield_historical.in", {}),
                         _parse_uri("mongodb://*****:*****@localhost/"
                                    "test.yield_historical.in",
                                    27017))
        self.assertEqual(([("example1.com", 27017), ("example2.com", 27017)],
                          "test", None, None, "yield_historical.in", {}),
                         _parse_uri("mongodb://example1.com:27017,example2.com"
                                    ":27017/test.yield_historical.in",
                                    27017))
        self.assertEqual(([("localhost", 27017)], "test", "fred", "foobar",
                          "yield_historical.in", {'slaveok': 'true'}),
                         _parse_uri("mongodb://*****:*****@localhost/"
                                    "test.yield_historical.in?slaveok=true",
                                    27017))
Example #8
0
    def test_parse_uri(self):
        self.assertEqual(([("localhost", 27017)], None, None, None, None, {}),
                         _parse_uri("localhost", 27017))
        self.assertEqual(([("localhost", 27018)], None, None, None, None, {}),
                         _parse_uri("localhost", 27018))
        self.assertRaises(InvalidURI, _parse_uri,
                          "http://foobar.com", 27017)
        self.assertRaises(InvalidURI, _parse_uri,
                          "http://[email protected]", 27017)

        self.assertEqual(([("localhost", 27017)], None, None, None, None, {}),
                         _parse_uri("mongodb://localhost", 27017))
        self.assertEqual(([("localhost", 27017)], None,
                          "fred", "foobar", None, {}),
                         _parse_uri("mongodb://*****:*****@localhost",
                                               27017))
        self.assertEqual(([("localhost", 27017)], "baz",
                          "fred", "foobar", None, {}),
                         _parse_uri("mongodb://*****:*****@localhost/baz",
                                               27017))
        self.assertEqual(([("example1.com", 27017), ("example2.com", 27017)],
                          None, None, None, None, {}),
                         _parse_uri("mongodb://"
                                    "example1.com:27017,example2.com:27017",
                                    27018))
        self.assertEqual(([("localhost", 27017),
                           ("localhost", 27018),
                           ("localhost", 27019)], None, None, None, None, {}),
                         _parse_uri("mongodb://localhost,"
                                    "localhost:27018,localhost:27019",
                                    27017))

        self.assertEqual(([("localhost", 27018)], None, None, None, None, {}),
                         _parse_uri("localhost:27018", 27017))
        self.assertEqual(([("localhost", 27017)], "foo", None, None, None, {}),
                         _parse_uri("localhost/foo", 27017))
        self.assertEqual(([("localhost", 27017)], None, None, None, None, {}),
                         _parse_uri("localhost/", 27017))

        self.assertEqual(([("localhost", 27017)], "test",
                          None, None, "yield_historical.in", {}),
                         _parse_uri("mongodb://"
                                    "localhost/test.yield_historical.in",
                                    27017))
        self.assertEqual(([("localhost", 27017)], "test", "fred",
                          "foobar", "yield_historical.in", {}),
                         _parse_uri("mongodb://*****:*****@localhost/"
                                    "test.yield_historical.in",
                                    27017))
        self.assertEqual(([("example1.com", 27017), ("example2.com", 27017)],
                          "test", None, None, "yield_historical.in", {}),
                         _parse_uri("mongodb://example1.com:27017,example2.com"
                                    ":27017/test.yield_historical.in",
                                    27017))
        self.assertEqual(([("localhost", 27017)], "test", "fred", "foobar",
                          "yield_historical.in", {'slaveok': 'true'}),
                         _parse_uri("mongodb://*****:*****@localhost/"
                                    "test.yield_historical.in?slaveok=true",
                                    27017))