def test_import_config_set_with_auth_error(self): self.mock(gitiles, 'get_log', mock.Mock()) gitiles.get_log.side_effect = net.AuthError('Denied', 500, 'Denied') # Should not raise an exception. gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project'))
def test_import_config_set(self): self.mock_get_log() self.mock_get_archive() gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project')) gitiles.get_log.assert_called_once_with('localhost', 'project', 'HEAD', '/', limit=1, deadline=15) saved_config_set = storage.ConfigSet.get_by_id('config_set') self.assertIsNotNone(saved_config_set) self.assertEqual(saved_config_set.latest_revision, 'a1841f40264376d170269ee9473ce924b7c2c4e9') self.assertTrue( storage.Revision.get_by_id( 'a1841f40264376d170269ee9473ce924b7c2c4e9', parent=saved_config_set.key)) # Import second time, import_revision should not be called. self.mock(gitiles_import, 'import_revision', mock.Mock()) gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project')) self.assertFalse(gitiles_import.import_revision.called)
def test_import_config_set(self): self.mock_get_log() self.mock_get_archive() gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project')) gitiles.get_log.assert_called_once_with( 'localhost', 'project', 'HEAD', '/', limit=1, deadline=15) saved_config_set = storage.ConfigSet.get_by_id('config_set') self.assertIsNotNone(saved_config_set) self.assertEqual( saved_config_set.latest_revision, 'a1841f40264376d170269ee9473ce924b7c2c4e9') self.assertTrue(storage.Revision.get_by_id( 'a1841f40264376d170269ee9473ce924b7c2c4e9', parent=saved_config_set.key)) # Import second time, import_revision should not be called. self.mock(gitiles_import, 'import_revision', mock.Mock()) gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project')) self.assertFalse(gitiles_import.import_revision.called)
def test_deadline_exceeded(self): self.mock_get_log() self.mock(gitiles, 'get_archive', mock.Mock()) gitiles.get_archive.side_effect = urlfetch_errors.DeadlineExceededError # Should not raise an exception. gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project'))
def test_import_config_set_with_auth_error(self): def raise_auth_error(*_, **__): raise auth.AuthorizationError() self.mock(gitiles, 'get_log', mock.Mock(side_effect=raise_auth_error)) # Should not raise an exception. gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project'))
def reimport(self, request): """Reimports a config set.""" if not auth.is_admin(): raise endpoints.ForbiddenException('Only admins are allowed to do this') # Assume it is Gitiles. try: gitiles_import.import_config_set(request.config_set) return message_types.VoidMessage() except gitiles_import.NotFoundError as e: raise endpoints.NotFoundException(e.message) except ValueError as e: raise endpoints.BadRequestException(e.message) except gitiles_import.Error as e: raise endpoints.InternalServerErrorException(e.message)
def reimport(self, request): """Reimports a config set.""" if not auth.is_admin(): raise endpoints.ForbiddenException( 'Only admins are allowed to do this') # Assume it is Gitiles. try: gitiles_import.import_config_set(request.config_set) return message_types.VoidMessage() except gitiles_import.NotFoundError as e: raise endpoints.NotFoundException(e.message) except ValueError as e: raise endpoints.BadRequestException(e.message) except gitiles_import.Error as e: raise endpoints.InternalServerErrorException(e.message)
def reimport(self, request): """Reimports a config set.""" try: validation.validate_config_set(request.config_set) except ValueError: raise endpoints.BadRequestException('invalid config_set "%s"' % request.config_set) if not acl.can_reimport(request.config_set): raise endpoints.ForbiddenException( '%s is now allowed to reimport %r' % (auth.get_current_identity().to_bytes(), request.config_set)) # Assume it is Gitiles. try: gitiles_import.import_config_set(request.config_set) return message_types.VoidMessage() except gitiles_import.NotFoundError as e: raise endpoints.NotFoundException(e.message) except ValueError as e: raise endpoints.BadRequestException(e.message) except gitiles_import.Error as e: raise endpoints.InternalServerErrorException(e.message)
def post(self, config_set): try: gitiles_import.import_config_set(config_set) except gitiles_import.NotFoundError as ex: logging.warning(ex.message)
def test_import_config_set_with_log_failed(self): self.mock(gitiles_import, 'import_revision', mock.Mock()) self.mock(gitiles, 'get_log', mock.Mock(return_value=None)) gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project'))
def test_import_config_set_with_log_failed(self): self.mock(gitiles_import, 'import_revision', mock.Mock()) self.mock(gitiles, 'get_log', mock.Mock(return_value = None)) gitiles_import.import_config_set( 'config_set', gitiles.Location.parse('https://localhost/project'))