Beispiel #1
0
    def setUp(self):
        super(BaseMongoTest, self).setUp()
        self._DB_NAME = "test_database"
        Connection.setup(self._DB_NAME)
        Connection.client.drop_database(self._DB_NAME)

        # Convenience attribute for integration tests
        self.db = Connection.client[self._DB_NAME]
Beispiel #2
0
# -*- coding: utf-8 -*-
from tavi import Connection
import logging

Connection.setup("test_database")


class LogCapture(logging.Handler):
    MSG_TYPES = ["debug", "info", "warning", "error", "critical"]

    def __init__(self, *args, **kwargs):
        self.reset()
        logging.Handler.__init__(self, *args, **kwargs)

    def __enter__(self):
        logging.getLogger().addHandler(self)
        return self

    def __exit__(self, type_, value, traceback):
        logging.getLogger().removeHandler(self)
        self.close()

    def emit(self, record):
        self.messages[record.levelname.lower()].append(record.getMessage())

    def reset(self):
        self.messages = {t: [] for t in self.MSG_TYPES}
Beispiel #3
0
 def test_setup_with_uri(self):
     Connection.setup("test_database", host="mongodb://localhost:27017")
     self.assertEqual(self.db, Connection.database)
Beispiel #4
0
 def test_has_a_client_attribute(self):
     Connection.setup("test_database", host="mongodb://localhost:27017")
     self.assertEqual(self.client, Connection.client)
Beispiel #5
0
 def test_setup_with_host_and_port(self):
     Connection.setup("test_database", host="localhost", port=27017)
     self.assertEqual(self.db, Connection.database)