Send readonly=1 when database is created in readonly mode

This commit is contained in:
Itai Shirav 2017-02-07 16:36:41 +02:00
parent f22073e2e6
commit 5b03e66048
2 changed files with 15 additions and 1 deletions

View File

@ -146,6 +146,8 @@ class Database(object):
params['user'] = self.username
if self.password:
params['password'] = self.password
if self.readonly:
params['readonly'] = '1'
return params
def _substitute(self, query, model_class=None):

View File

@ -2,7 +2,7 @@
import unittest
from infi.clickhouse_orm.database import Database
from infi.clickhouse_orm.database import Database, DatabaseException
from infi.clickhouse_orm.models import Model
from infi.clickhouse_orm.fields import *
from infi.clickhouse_orm.engines import *
@ -117,6 +117,18 @@ class DatabaseTestCase(unittest.TestCase):
p = list(self.database.select("SELECT * from $table", Person))[0]
self.assertEquals(p.first_name, s)
def test_readonly(self):
orig_database = self.database
self.database = Database(orig_database.db_name, readonly=True)
with self.assertRaises(DatabaseException):
self._insert_and_check(self._sample_data(), len(data))
self.assertEquals(self.database.count(Person), 0)
with self.assertRaises(DatabaseException):
self.database.drop_table(Person)
with self.assertRaises(DatabaseException):
self.database.drop_database()
self.database = orig_database
def _sample_data(self):
for entry in data:
yield Person(**entry)