diff --git a/integration_tests/test_client_it.py b/integration_tests/test_client_it.py index f6b5aac..8638dff 100644 --- a/integration_tests/test_client_it.py +++ b/integration_tests/test_client_it.py @@ -281,7 +281,6 @@ def test_store(self): finally: client.delete_index(index) - def test_ensure_index_exists(self): client = self.get_client() index = Index(self.index.name + "-ensure") @@ -736,6 +735,32 @@ def test_shards(self): self.assertEquals(100, response.result.row.columns[0]) self.assertEquals(shard_width*3, response.result.row.columns[1]) + def test_field_opts(self): + client = self.get_client() + schema = client.schema() + index = schema.index("index_wkeys", keys=True, track_existence=True, shard_width=2 ** 10) + try: + # create the schema + index.field("field_wkeys", + keys=True, + cache_type=CacheType.LRU, + cache_size=1000) + client.sync_schema(schema) + + # check that the correct schema was created + schema = client.schema() + index = schema.index("index_wkeys") + self.assertEqual("index_wkeys", index.name) + self.assertTrue(index.keys) + self.assertTrue(index.track_existence) + field = index.field("field_wkeys") + self.assertEqual("field_wkeys", field.name) + self.assertTrue(field.keys) + self.assertEqual(CacheType.LRU, field.cache_type) + self.assertEqual(1000, field.cache_size) + finally: + client.delete_index(index) + def test_create_index_fail(self): server = MockServer(404) with server: diff --git a/pilosa/client.py b/pilosa/client.py index ed841e5..fa71b16 100644 --- a/pilosa/client.py +++ b/pilosa/client.py @@ -486,13 +486,17 @@ def __connect(self): def decode_field_meta_options(field_info): meta = field_info.get("options", {}) - return { + opts = { "cache_size": meta.get("cacheSize", 50000), "cache_type": CacheType(meta.get("cacheType", "")), "time_quantum": TimeQuantum(meta.get("timeQuantum", "")), "int_min": meta.get("min", 0), - "int_max": meta.get("max", 0), + "int_max": meta.get("max", 0) } + keys_opt = meta.get("keys") + if keys_opt is not None: + opts["keys"] = keys_opt + return opts class URI: diff --git a/pilosa/orm.py b/pilosa/orm.py index b88f590..484a4b2 100644 --- a/pilosa/orm.py +++ b/pilosa/orm.py @@ -70,6 +70,9 @@ def __init__(self, value): def __str__(self): return self.value + def __repr__(self): + return "TimeQuantum(%s)" % self.value + def __eq__(self, other): if isinstance(other, TimeQuantum): return self.value == other.value @@ -107,6 +110,9 @@ def __init__(self, value): def __str__(self): return self.value + def __repr__(self): + return "CacheType(%s)" % self.value + def __eq__(self, other): if isinstance(other, CacheType): return self.value == other.value diff --git a/tests/test_client.py b/tests/test_client.py index e8a6144..03b2c32 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -59,7 +59,7 @@ def test_create_client(self): # create with invalid type self.assertRaises(PilosaError, Client, 15000) - def test_decode_field_meta_options(self): + def test_decode_default_field_meta_options(self): field_info = {} options = decode_field_meta_options(field_info) target = { @@ -72,7 +72,6 @@ def test_decode_field_meta_options(self): self.assertEquals(target, options) - class URITestCase(unittest.TestCase): def test_default(self): @@ -317,7 +316,7 @@ def test_node_url(self): def get_schema(index_keys, field_keys): - from pilosa.orm import Schema, Index, Field + from pilosa.orm import Schema schema = Schema() index = schema.index("foo", keys=index_keys) field = index.field("bar", keys=field_keys)