def test_chunked_config(self): """ test for storing long values """ from linotp.lib.text_utils import simple_slice from linotp.lib.config.db_api import MAX_VALUE_LEN key_name = 'linotp.chunk_test' key_type = 'text' key_desc = 'description' chunks = [] for cont_value in simple_slice(big_value, MAX_VALUE_LEN): chunks.append(cont_value) _store_continous_entry_db(chunks, key=key_name, val=big_value, typ=key_type, desc=key_desc) conf_keys = list(TestConfigEntries.keys()) # ------------------------------------------------------------------ -- # make sure that the first key entry 'test' is avaliable # and that the keys are representing the calculated number assert key_name in conf_keys, TestConfigEntries entry = TestConfigEntries[key_name] value = entry['value'] from_, to_ = entry['desc'].split(':') # we count from 0 to eg 3 so we have 4 entries assert len(conf_keys) == int(to_) + 1, conf_keys # ------------------------------------------------------------------ -- # check that all entries have the extended key format for i in range(int(from_) + 1, int(to_) + 1): entry_key = "%s__[%d:%d]" % (key_name, i, int(to_)) assert entry_key in TestConfigEntries value += TestConfigEntries[entry_key]['value'] assert value == big_value # finally we check if the original type and description is in the # last entry entry_key = "%s__[%d:%d]" % (key_name, int(to_), int(to_)) entry_type = TestConfigEntries[entry_key]['type'] entry_desc = TestConfigEntries[entry_key]['desc'] assert entry_type == key_type assert entry_desc == key_desc # -------------------------------------------------------------------- # cleanup the shared dictionary for key in list(TestConfigEntries.keys()): del TestConfigEntries[key] return
def test_chunked_config(self): """ test for storing long values """ from linotp.lib.text_utils import simple_slice from linotp.lib.config.db_api import MAX_VALUE_LEN key_name = 'linotp.chunk_test' key_type = 'text' key_desc = 'description' chunks = [] for cont_value in simple_slice(big_value, MAX_VALUE_LEN): chunks.append(cont_value) _store_continous_entry_db(chunks, key=key_name, val=big_value, typ=key_type, desc=key_desc) conf_keys = TestConfigEntries.keys() # ------------------------------------------------------------------ -- # make sure that the first key entry 'test' is avaliable # and that the keys are representing the calculated number self.assertTrue(key_name in conf_keys, TestConfigEntries) entry = TestConfigEntries[key_name] value = entry['value'] from_, to_ = entry['desc'].split(':') # we count from 0 to eg 3 so we have 4 entries self.assertTrue(len(conf_keys) == int(to_) + 1, conf_keys) # ------------------------------------------------------------------ -- # check that all entries have the extended key format for i in range(int(from_) + 1, int(to_) + 1): entry_key = "%s__[%d:%d]" % (key_name, i, int(to_)) self.assertTrue(entry_key in TestConfigEntries) value += TestConfigEntries[entry_key]['value'] self.assertTrue(value == big_value) # finally we check if the original type and description is in the # last entry entry_key = "%s__[%d:%d]" % (key_name, int(to_), int(to_)) entry_type = TestConfigEntries[entry_key]['type'] entry_desc = TestConfigEntries[entry_key]['desc'] self.assertTrue(entry_type == key_type) self.assertTrue(entry_desc == key_desc) # -------------------------------------------------------------------- # cleanup the shared dictionary for key in TestConfigEntries.keys(): del TestConfigEntries[key] return