Пример #1
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.db = Database('localhost', 27017, 'backdrop_test')

    def test_alive(self):
        assert_that(self.db.alive(), is_(True))

    def test_getting_a_repository(self):
        repository = self.db.get_repository('my_bucket')
        assert_that(repository, instance_of(Repository))
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.db = Database('localhost', 27017, 'backdrop_test')

    def test_alive(self):
        assert_that(self.db.alive(), is_(True))

    def test_getting_a_repository(self):
        repository = self.db.get_repository('my_bucket')
        assert_that(repository, instance_of(Repository))
Пример #3
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.db = Database(HOST, PORT, DB_NAME)
        self.db.mongo_database["my_capped_collection"].drop()

    def test_alive(self):
        assert_that(self.db.alive(), is_(True))

    def test_getting_a_repository(self):
        repository = self.db.get_repository('my_bucket')
        assert_that(repository, instance_of(Repository))

    def test_getting_a_collection(self):
        collection = self.db.get_collection('my_collection')
        assert_that(collection, instance_of(MongoDriver))

    def test_create_capped_collection(self):
        self.db.create_capped_collection("my_capped_collection", 1234)

        assert_that(self.db.mongo_database["my_capped_collection"].options(),
                    is_({"capped": True, "size": 1234}))

    def test_get_collection_names(self):
        self.db.create_capped_collection("foo", 1234)

        assert_that('foo', is_in(self.db.collection_names()))
Пример #4
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        self.hosts = ['localhost']
        self.port = 27017
        self.db = Database(self.hosts, self.port, 'test')

    @patch('os.getenv', return_value='test')
    @patch('pymongo.MongoClient')
    @patch('pymongo.MongoReplicaSetClient')
    def test_get_replica_set_client(self, MongoReplicaSetClient, MongoClient, getenv):
        client = self.db.get_client(self.hosts, self.port)

        assert not MongoClient.called
        MongoReplicaSetClient.assert_called_once_with('localhost:27017', replicaSet='test')

    @patch('os.getenv', return_value='')
    @patch('pymongo.MongoClient')
    @patch('pymongo.MongoReplicaSetClient')
    def test_get_non_replica_set_client(self, MongoReplicaSetClient, MongoClient, getenv):
        client = self.db.get_client(self.hosts, self.port)

        MongoClient.assert_called_once_with('localhost:27017')
        assert not MongoReplicaSetClient.called
Пример #5
0
class TestBucketRepositoryIntegration(unittest.TestCase):

    def setUp(self):
        self.db = Database(HOST, PORT, DB_NAME)
        self.db._mongo.drop_database(DB_NAME)
        self.mongo_collection = self.db.get_collection(BUCKET)
        self.repository = BucketConfigRepository(self.db)

    def test_saving_a_config_with_default_values(self):
        config = BucketConfig("some_bucket", data_group="group", data_type="type")

        self.repository.save(config)

        results = list(self.mongo_collection._collection.find())

        assert_that(len(results), is_(1))
        assert_that(results[0], has_entries({
            "name": "some_bucket",
            "raw_queries_allowed": False,
            "bearer_token": None,
            "upload_format": "csv"
        }))

    def test_saving_a_realtime_config_creates_a_capped_collection(self):
        config = BucketConfig("realtime_bucket", data_group="group", data_type="type", realtime=True)

        self.repository.save(config)

        assert_that(self.db.mongo_database["realtime_bucket"].options(), is_({"capped": True, "size": 5040}))

    def test_retrieves_config_by_name(self):
        self.repository.save(BucketConfig("not_my_bucket", data_group="group", data_type="type"))
        self.repository.save(BucketConfig("my_bucket", data_group="group", data_type="type"))
        self.repository.save(BucketConfig("someones_bucket", data_group="group", data_type="type"))

        config = self.repository.retrieve(name="my_bucket")

        assert_that(config.name, is_("my_bucket"))

    def test_retrieves_config_for_service_and_data_type(self):
        self.repository.save(BucketConfig("b1", data_group="my_service", data_type="my_type"))
        self.repository.save(BucketConfig("b2", data_group="my_service", data_type="not_my_type"))
        self.repository.save(BucketConfig("b3", data_group="not_my_service", data_type="my_type"))

        config = self.repository.get_bucket_for_query(data_group="my_service", data_type="my_type")

        assert_that(config.name, is_("b1"))
Пример #6
0
class TestUserRepositoryIntegration(object):
    def setUp(self):
        self.db = Database(HOST, PORT, DB_NAME)
        self.db._mongo.drop_database(DB_NAME)
        self.mongo_collection = self.db.get_collection("users")._collection
        self.mongo_collection.drop()
        self.repository = UserConfigRepository(self.db)

    def test_saving_a_config_with_no_buckets(self):
        config = UserConfig(email="*****@*****.**")

        self.repository.save(config)

        results = list(self.mongo_collection.find())

        assert_that(len(results), is_(1))
        assert_that(results[0], has_entries({
            "email": "*****@*****.**",
            "buckets": [],
        }))
 def setUp(self):
     self.db = Database('localhost', 27017, 'backdrop_test')
Пример #8
0
 def setUp(self):
     self.db = Database(HOST, PORT, DB_NAME)
     self.db._mongo.drop_database(DB_NAME)
     self.mongo_collection = self.db.get_collection("users")._collection
     self.mongo_collection.drop()
     self.repository = UserConfigRepository(self.db)
Пример #9
0
 def setUp(self):
     self.db = Database(HOST, PORT, DB_NAME)
     self.db._mongo.drop_database(DB_NAME)
     self.mongo_collection = self.db.get_collection(BUCKET)
     self.repository = BucketConfigRepository(self.db)
Пример #10
0
 def setUp(self):
     self.db = Database(HOST, PORT, DB_NAME)
     self.db.mongo_database["my_capped_collection"].drop()
Пример #11
0
 def setUp(self):
     self.db = Database('localhost', 27017, 'backdrop_test')
Пример #12
0
 def setUp(self):
     self.hosts = ['localhost']
     self.port = 27017
     self.db = Database(self.hosts, self.port, 'test')