def get_data(): """ Return some Dict """ from aiida.plugins import DataFactory data = DataFactory('dict')(dict={'data': 'test'}) data.store() return data
def test_create_use_destroy_profile2(self): """ Test temporary test profile creation * The profile gets created, the dbenv loaded * Data can be stored in the db * reset_db deletes all data added after profile creation * destroy_all removes all traces of the test run Note: This test function loads the dbenv - i.e. you cannot run similar test functions (that create profiles) in the same test session. aiida.manage.configuration.reset_profile() was not yet enough, see https://github.com/aiidateam/aiida-core/issues/3482 """ with Capturing() as output: self.profile_manager.create_profile() self.assertTrue(self.profile_manager.root_dir_ok, msg=output) self.assertTrue(self.profile_manager.config_dir_ok, msg=output) self.assertTrue(self.profile_manager.repo_ok, msg=output) from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER self.assertEqual(AIIDA_CONFIG_FOLDER, self.profile_manager.config_dir, msg=output) from aiida.orm import load_node from aiida.plugins import DataFactory data = DataFactory('dict')(dict={'key': 'value'}) data.store() data_pk = data.pk self.assertTrue(load_node(data_pk)) with self.assertRaises(TestManagerError): self.test_create_aiida_db() self.profile_manager.reset_db() with self.assertRaises(Exception): load_node(data_pk) temp_dir = self.profile_manager.root_dir self.profile_manager.destroy_all() with self.assertRaises(Exception): self.profile_manager.postgres.db_exists( self.profile_manager.dbinfo['db_name']) self.assertFalse(os.path.exists(temp_dir)) self.assertIsNone(self.profile_manager.root_dir) self.assertIsNone(self.profile_manager.pg_cluster)