copy/deepcopy should duplicate informations
This commit is contained in:
parent
6910371779
commit
a269cbcc93
4 changed files with 43 additions and 0 deletions
|
@ -59,6 +59,16 @@ async def test_copy():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_copy_information():
|
||||||
|
od = make_description()
|
||||||
|
async with await Config(od) as cfg:
|
||||||
|
await cfg.information.set('key', 'value')
|
||||||
|
async with await cfg.config.copy() as ncfg:
|
||||||
|
assert await ncfg.information.get('key') == 'value'
|
||||||
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_copy_force_store_value():
|
async def test_copy_force_store_value():
|
||||||
od = make_description()
|
od = make_description()
|
||||||
|
|
|
@ -654,6 +654,9 @@ class _CommonConfig(SubConfig):
|
||||||
duplicated_settings = duplicated_config.cfgimpl_get_settings()
|
duplicated_settings = duplicated_config.cfgimpl_get_settings()
|
||||||
await duplicated_values._p_.importation(connection,
|
await duplicated_values._p_.importation(connection,
|
||||||
await self.cfgimpl_get_values()._p_.exportation(connection))
|
await self.cfgimpl_get_values()._p_.exportation(connection))
|
||||||
|
await duplicated_values._p_.importation_informations(connection,
|
||||||
|
await self.cfgimpl_get_values()._p_.exportation_informations(connection),
|
||||||
|
)
|
||||||
properties = await self.cfgimpl_get_settings()._p_.exportation(connection)
|
properties = await self.cfgimpl_get_settings()._p_.exportation(connection)
|
||||||
await duplicated_settings._p_.importation(connection,
|
await duplicated_settings._p_.importation(connection,
|
||||||
properties)
|
properties)
|
||||||
|
|
|
@ -293,6 +293,18 @@ class Values:
|
||||||
connection):
|
connection):
|
||||||
self._storage.set_informations({})
|
self._storage.set_informations({})
|
||||||
|
|
||||||
|
async def exportation_informations(self,
|
||||||
|
connection,
|
||||||
|
):
|
||||||
|
return deepcopy(self._storage.get_informations())
|
||||||
|
|
||||||
|
async def importation_informations(self,
|
||||||
|
connection,
|
||||||
|
informations,
|
||||||
|
):
|
||||||
|
#deepcopy(informations)
|
||||||
|
return self._storage.set_informations(informations)
|
||||||
|
|
||||||
async def exportation(self,
|
async def exportation(self,
|
||||||
connection):
|
connection):
|
||||||
return deepcopy(self._storage.get_values())
|
return deepcopy(self._storage.get_values())
|
||||||
|
|
|
@ -231,6 +231,24 @@ class Values:
|
||||||
await connection.execute("DELETE FROM information WHERE session_id = $1",
|
await connection.execute("DELETE FROM information WHERE session_id = $1",
|
||||||
self._storage.database_id)
|
self._storage.database_id)
|
||||||
|
|
||||||
|
async def exportation_informations(self,
|
||||||
|
connection,
|
||||||
|
):
|
||||||
|
informations = {}
|
||||||
|
for path, key, value in await connection.fetch("SELECT path, key, value FROM information WHERE session_id = $1", self._storage.database_id):
|
||||||
|
path = self._storage.load_path(path)
|
||||||
|
informations.setdefault(path, {})[key] = loads(value)
|
||||||
|
return informations
|
||||||
|
|
||||||
|
async def importation_informations(self,
|
||||||
|
connection,
|
||||||
|
informations,
|
||||||
|
):
|
||||||
|
for path, path_infos in informations.items():
|
||||||
|
for key, value in path_infos.items():
|
||||||
|
await connection.execute("INSERT INTO information(key, value, session_id, path) VALUES "
|
||||||
|
"($1, $2, $3, $4)", key, dumps(value), self._storage.database_id, path)
|
||||||
|
|
||||||
async def exportation(self,
|
async def exportation(self,
|
||||||
connection):
|
connection):
|
||||||
# log.debug('exportation')
|
# log.debug('exportation')
|
||||||
|
|
Loading…
Reference in a new issue