def test_json_changes(self, user_data, user_data_json, chat_data, chat_data_json, conversations, conversations_json): dict_persistence = DictPersistence( user_data_json=user_data_json, chat_data_json=chat_data_json, conversations_json=conversations_json) user_data_two = user_data.copy() user_data_two.update({4: {5: 6}}) dict_persistence.update_user_data(4, {5: 6}) assert dict_persistence.user_data == user_data_two assert dict_persistence.user_data_json != user_data_json assert dict_persistence.user_data_json == json.dumps(user_data_two) chat_data_two = chat_data.copy() chat_data_two.update({7: {8: 9}}) dict_persistence.update_chat_data(7, {8: 9}) assert dict_persistence.chat_data == chat_data_two assert dict_persistence.chat_data_json != chat_data_json assert dict_persistence.chat_data_json == json.dumps(chat_data_two) conversations_two = conversations.copy() conversations_two.update({'name3': {(1, 2): 3}}) dict_persistence.update_conversation('name3', (1, 2), 3) assert dict_persistence.conversations == conversations_two assert dict_persistence.conversations_json != conversations_json assert dict_persistence.conversations_json == enocde_conversations_to_json( conversations_two)
def dump_conversation_data(self, filename, data): self.zoo_client.ensure_path(filename) data_json = json.dumps( enocde_conversations_to_json(data)).encode('utf-8') self.zoo_client.set(filename, data_json)
def conversations_json(self): """:obj:`str`: The conversations serialized as a JSON-string.""" if self._conversations_json: return self._conversations_json else: return enocde_conversations_to_json(self.conversations)