def test_pool_import_export(self): # Create two pools first pool_config_input = { "foo": { "description": "foo_test", "slots": 1 }, 'default_pool': { 'description': 'Default pool', 'slots': 128 }, "baz": { "description": "baz_test", "slots": 2 }, } with open('pools_import.json', mode='w') as file: json.dump(pool_config_input, file) # Import json pool_command.pool_import( self.parser.parse_args(['pools', 'import', 'pools_import.json'])) # Export json pool_command.pool_export( self.parser.parse_args(['pools', 'export', 'pools_export.json'])) with open('pools_export.json', mode='r') as file: pool_config_output = json.load(file) self.assertEqual(pool_config_input, pool_config_output, "Input and output pool files are not same") os.remove('pools_import.json') os.remove('pools_export.json')
def test_pool_import_invalid_pools(self): pool_config_input = {"foo": {"description": "foo_test"}} with open('pools_import_invalid.json', mode='w') as file: json.dump(pool_config_input, file) with pytest.raises(SystemExit): pool_command.pool_import(self.parser.parse_args(['pools', 'import', 'pools_import_invalid.json']))
def test_pool_import_invalid_json(self): with open('pools_import_invalid.json', mode='w') as file: file.write("not valid json") with self.assertRaises(SystemExit): pool_command.pool_import( self.parser.parse_args( ['pools', 'import', 'pools_import_invalid.json']))
def test_pool_import_nonexistent(self): with self.assertRaises(SystemExit): pool_command.pool_import( self.parser.parse_args(['pools', 'import', 'nonexistent.json']))