def test_get_set(): """Verify that a set value can be retrieved.""" key = 'name' expected_value = 'Guido' kvstore.set(key, expected_value) actual_value = kvstore.get(key) assert expected_value == actual_value
def test_get_set(self): """Verify that a set value can be retrieved.""" key = 'name' expected_value = 'Guido' kvstore.set(key, expected_value) actual_value = kvstore.get(key) self.assertEqual(expected_value, actual_value)
def test_get_set_complex_structures(self): """Verify that complex structures can be stored and retrieved.""" key = 'compex_structure' expected_value = {'k1': 1, 'k2': [2, 3], 'k3': 4.5, 'k4': 'Hello', 'k5': {'a': 'b'}} kvstore.set(key, expected_value) actual_value = kvstore.get(key) self.assertEqual(expected_value, actual_value)
def test_backup_restore_restore_post(run, backup_restore): """Test running restore-post hook.""" packet = None backup_restore.app_id = 'testapp' component = BackupRestore('test-backup-restore') component.restore_post(packet) run.assert_has_calls([]) output = {'setting-1': 'value-1'} run.return_value = json.dumps(output) backup_restore.restore_post(packet) run.assert_has_calls( [call('backups', ['load-settings', '--app-id', 'testapp'])]) assert kvstore.get('setting-1') == 'value-1' with pytest.raises(Exception): kvstore.get('setting-2')
def _settings_backup_pre(self): """Read keys from kvstore and store them in a file to backup.""" if not self.settings: return from plinth import kvstore data = {} for key in self.settings: try: data[key] = kvstore.get(key) except Exception: pass input_ = json.dumps(data).encode() actions.superuser_run('backups', ['dump-settings', '--app-id', self.app_id], input=input_)