self.mock(ByteStreamStubMock, 'Write', Write) s = self.get_server() i = isolate_storage.Item(digest='abc123', size=0) with self.assertRaises(IOError): s.push(i, isolate_storage._IsolateServerGrpcPushState(), '1234') def testPushThrowsCorrectExceptionOnGrpcFailure(self): """Push: if something goes wrong in Isolate, we throw an exception""" def Write(_self, _request, timeout=None): del timeout raiseError(isolate_storage.grpc.StatusCode.INTERNAL_ERROR) self.mock(ByteStreamStubMock, 'Write', Write) s = self.get_server() i = isolate_storage.Item(digest='abc123', size=0) with self.assertRaises(IOError): s.push(i, isolate_storage._IsolateServerGrpcPushState(), '1234') if __name__ == '__main__': if not isolate_storage.grpc: # Don't print to stderr or return error code as this will # show up as a warning and fail in presubmit. print('gRPC could not be loaded; skipping tests') sys.exit(0) isolate_storage.bytestream_pb2.ByteStreamStub = ByteStreamStubMock test_utils.main()
perms.Grant('creator', perms.Role.MAP_CREATOR, 'xyz.com') with test_utils.Login('creator'): response = self.DoPost('/xyz.com/.create', 'xsrf_token=XSRF', 302) location = response.headers['Location'] # initial_domain_role is unset so domain_role should be None. map_object = model.Map.Get(location.split('/')[-1]) self.assertTrue(map_object is not None) # With no initial_domain_role set, domain_role should be None. self.assertEquals(['xyz.com'], map_object.domains) self.assertEquals(None, map_object.domain_role) # Now set the initial_domain_role for xyz.com. with test_utils.RootLogin(): domain.initial_domain_role = perms.Role.MAP_EDITOR domain.Put() # Create another map. with test_utils.Login('creator'): response = self.DoPost('/.create?domain=xyz.com', 'xsrf_token=XSRF', 302) location = response.headers['Location'] # Check the map; initial_domain_role is set so domain_role should be set. map_object = model.Map.Get(location.split('/')[-1]) self.assertTrue(map_object is not None) self.assertEquals(['xyz.com'], map_object.domains) self.assertEquals(perms.Role.MAP_EDITOR, map_object.domain_role) if __name__ == '__main__': test_utils.main()
def test_get_config_dir(os_environ): # Negative - Missing input with pytest.raises(ValueError) as exc: core.get_config_dir(fake_config_cli(config_dir=None)) assert "Missing path" in str(exc.value) # Negative - Bad path with pytest.raises(ValueError) as exc: core.get_config_dir(fake_config_cli(config_dir="/fake/path")) assert "Bad path" in str(exc.value) assert "/fake/path" in str(exc.value) # verify CLI assert core.get_config_dir( fake_config_cli(config_dir=SETTINGS_DIR)) == SETTINGS_DIR # Verify ENV os.environ["KHALEESI_SETTINGS"] = SETTINGS_DIR assert core.get_config_dir( fake_config_cli(config_dir=None)) == SETTINGS_DIR # Verify CLI over ENV os.environ["KHALEESI_SETTINGS"] = "/fake/env/path" assert core.get_config_dir( fake_config_cli(config_dir=SETTINGS_DIR)) == SETTINGS_DIR if __name__ == '__main__': main(locals())
import os import pytest import yaml from test_utils import TEST_DIR, main from ksgen.settings import load_configuration def test_invalid_yml(): path = os.path.join(TEST_DIR, 'data', 'yml-syntax') yaml_path = os.path.join(path, 'dashes.yml') with pytest.raises(yaml.scanner.ScannerError): load_configuration(yaml_path) yaml_path = os.path.join(path, 'spaces.yml') with pytest.raises(yaml.parser.ParserError): load_configuration(yaml_path) yaml_path = os.path.join(path, 'tab.yml') with pytest.raises(yaml.scanner.ScannerError): load_configuration(yaml_path) yaml_path = os.path.join(path, 'map.yml') with pytest.raises(TypeError): load_configuration(yaml_path) if __name__ == '__main__': main(locals())