Exemple #1
0
 def test_set(self):
     self.app.conf.couchbase_backend_settings = None
     x = CouchbaseBackend(app=self.app)
     x._connection = MagicMock()
     x._connection.set = MagicMock()
     # should return None
     assert x.set(sentinel.key, sentinel.value) is None
Exemple #2
0
 def test_init_no_couchbase(self):
     prev, module.Couchbase = module.Couchbase, None
     try:
         with pytest.raises(ImproperlyConfigured):
             CouchbaseBackend(app=self.app)
     finally:
         module.Couchbase = prev
Exemple #3
0
 def test_set_expires(self):
     self.app.conf.couchbase_backend_settings = None
     x = CouchbaseBackend(app=self.app, expires=30)
     assert x.expires == 30
     x._connection = MagicMock()
     x._connection.set = MagicMock()
     # should return None
     assert x.set(sentinel.key, sentinel.value, states.SUCCESS) is None
Exemple #4
0
 def test_delete(self):
     self.app.conf.couchbase_backend_settings = {}
     x = CouchbaseBackend(app=self.app)
     x._connection = Mock()
     mocked_delete = x._connection.delete = Mock()
     mocked_delete.return_value = None
     # should return None
     assert x.delete('1f3fab') is None
     x._connection.delete.assert_called_once_with('1f3fab')
Exemple #5
0
 def test_get(self):
     self.app.conf.couchbase_backend_settings = {}
     x = CouchbaseBackend(app=self.app)
     x._connection = Mock()
     mocked_get = x._connection.get = Mock()
     mocked_get.return_value.value = sentinel.retval
     # should return None
     assert x.get('1f3fab') == sentinel.retval
     x._connection.get.assert_called_once_with('1f3fab')
Exemple #6
0
 def test_config_params(self):
     self.app.conf.couchbase_backend_settings = {
         'bucket': 'mycoolbucket',
         'host': ['here.host.com', 'there.host.com'],
         'username': '******',
         'password': '******',
         'port': '1234',
     }
     x = CouchbaseBackend(app=self.app)
     assert x.bucket == 'mycoolbucket'
     assert x.host == ['here.host.com', 'there.host.com']
     assert x.username == 'johndoe'
     assert x.password == 'mysecret'
     assert x.port == 1234
 def test_config_params(self):
     self.app.conf.couchbase_backend_settings = {
         'bucket': 'mycoolbucket',
         'host': ['here.host.com', 'there.host.com'],
         'username': '******',
         'password': '******',
         'port': '1234',
     }
     x = CouchbaseBackend(app=self.app)
     self.assertEqual(x.bucket, 'mycoolbucket')
     self.assertEqual(
         x.host,
         ['here.host.com', 'there.host.com'],
     )
     self.assertEqual(
         x.username,
         'johndoe',
     )
     self.assertEqual(x.password, 'mysecret')
     self.assertEqual(x.port, 1234)
Exemple #8
0
 def test_init_settings_is_None(self):
     self.app.conf.couchbase_backend_settings = None
     CouchbaseBackend(app=self.app)
Exemple #9
0
 def test_init_no_settings(self):
     self.app.conf.couchbase_backend_settings = []
     with pytest.raises(ImproperlyConfigured):
         CouchbaseBackend(app=self.app)
Exemple #10
0
 def setup(self):
     self.backend = CouchbaseBackend(app=self.app)
Exemple #11
0
 def test_expires_is_timedelta(self):
     b = CouchbaseBackend(expires=timedelta(minutes=1), app=self.app)
     assert b.expires == 60
Exemple #12
0
 def test_expires_is_None(self):
     b = CouchbaseBackend(expires=None, app=self.app)
     assert b.expires == self.app.conf.result_expires.total_seconds()
Exemple #13
0
 def test_expires_is_int(self):
     b = CouchbaseBackend(expires=48, app=self.app)
     assert b.expires == 48
Exemple #14
0
 def test_expires_defaults_to_config(self):
     self.app.conf.result_expires = 10
     b = CouchbaseBackend(expires=None, app=self.app)
     assert b.expires == 10