def test_is_bootstrap_completed(self): """Tests is_bootstrap_completed under myriad circumstances.""" self.assertFalse(bootstrap.is_bootstrap_completed()) bootstrap.config_model.Config.set('bootstrap_started', True) self.assertFalse(bootstrap.is_bootstrap_completed()) bootstrap.config_model.Config.set('bootstrap_completed', False) self.assertFalse(bootstrap.is_bootstrap_completed()) bootstrap.config_model.Config.set('bootstrap_completed', True) self.assertTrue(bootstrap.is_bootstrap_completed())
def get(self, path): user = users.get_current_user() if not user: self.response.status = httplib.UNAUTHORIZED self.response.out.write( 'You must be logged in to access this app.') return elif user.email().split('@')[1] not in constants.APP_DOMAIN: self.response.status = httplib.FORBIDDEN self.response.out.write('Forbidden.') return if path == '/application.js': self._serve_frontend_javascript() return if self.bootstrap_completed or re.match(r'^/(bootstrap|authorization)', path): self._serve_frontend() else: self._sync_roles_if_necessary() # Re-checks if the bootstrap status did not change since the handler was # first loaded. self.bootstrap_completed = bootstrap.is_bootstrap_completed() if self.bootstrap_completed: self.redirect(path) else: self.redirect(BOOTSTRAP_URL)
def test_get_bootstrap_task_status(self, mock_get_bootstrap_functions, mock_is_new_deployment): """Tests get_bootstrap_task_status.""" config_model.Config.set('bootstrap_started', True) yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=-1) def fake_function1(): pass def fake_function2(): pass mock_get_bootstrap_functions.return_value = { 'fake_function1': fake_function1, 'fake_function2': fake_function2 } fake_entity1 = bootstrap_status_model.BootstrapStatus.get_or_insert( 'fake_function1') fake_entity1.success = True fake_entity1.timestamp = yesterday fake_entity1.details = '' fake_entity1.put() fake_entity2 = bootstrap_status_model.BootstrapStatus.get_or_insert( 'fake_function2') fake_entity2.success = True fake_entity2.timestamp = yesterday fake_entity2.details = '' fake_entity2.put() status = bootstrap.get_bootstrap_task_status() self.assertLen(status, 2) self.assertTrue(bootstrap.is_bootstrap_completed())
def get(self): """Process GET, serving a static maintenance page.""" if constants.MAINTENANCE or not bootstrap.is_bootstrap_completed(): self.response.headers['Content-Type'] = 'text/html' self.response.body_file.write( constants.JINJA.get_template('maintenance.html').render( {'app_name': constants.APP_NAME})) else: self.redirect('/user')
def get_status(self, request): """Gets general bootstrap status, and task status if not yet completed.""" self.check_xsrf_token(self.request_state) response_message = bootstrap_messages.BootstrapStatusResponse() response_message.enabled = bootstrap.is_bootstrap_enabled() response_message.started = bootstrap.is_bootstrap_started() response_message.completed = bootstrap.is_bootstrap_completed() for name, status in bootstrap.get_bootstrap_task_status().iteritems(): response_message.tasks.append( bootstrap_messages.BootstrapTask( name=name, description=status.get('description'), success=status.get('success'), timestamp=status.get('timestamp'), details=status.get('details'))) return response_message
def get(self, path): if path == '/application.js': self._serve_frontend_javascript() return if self.bootstrap_completed or re.match( r'^/(bootstrap|authorization)', path): self._serve_frontend() else: self._sync_roles_if_necessary() # Re-checks if the bootstrap status did not change since the handler was # first loaded. self.bootstrap_completed = bootstrap.is_bootstrap_completed() if self.bootstrap_completed: self.redirect(path) else: self.redirect(BOOTSTRAP_URL)
def get_status(self, request): """Gets general bootstrap and bootstrap task status.""" self.check_xsrf_token(self.request_state) response_message = bootstrap_messages.BootstrapStatusResponse() for name, status in bootstrap.get_bootstrap_task_status().iteritems(): response_message.tasks.append( bootstrap_messages.BootstrapTask( name=name, description=status.get('description'), success=status.get('success'), timestamp=status.get('timestamp'), details=status.get('details'))) response_message.is_update = bootstrap.is_update() response_message.started = bootstrap.is_bootstrap_started() response_message.completed = bootstrap.is_bootstrap_completed() response_message.app_version = constants.APP_VERSION response_message.running_version = config_model.Config.get( 'running_version') return response_message
def __init__(self, *args, **kwargs): """Override RequestHandler init to track app readiness.""" super(FrontendHandler, self).__init__(*args, **kwargs) self.bootstrap_started = bootstrap.is_bootstrap_started() self.bootstrap_completed = bootstrap.is_bootstrap_completed()
def test_is_bootstrap_completed_false_needs_update(self): config_model.Config.set('running_version', '0.0.1-alpha') self.assertFalse(bootstrap.is_bootstrap_completed())
def test_is_bootstrap_completed_true_up_to_date(self): config_model.Config.set('bootstrap_completed', True) config_model.Config.set('running_version', constants.APP_VERSION) self.assertTrue(bootstrap.is_bootstrap_completed())