Ejemplo n.º 1
0
    def test_current_term_id_caching(self):
        """Fetches current term ID from the loch instead of cache when asked."""
        import json
        from boac.models import json_cache
        from boac.models.json_cache import JsonCache

        index_row = JsonCache.query.filter_by(key='current_term_index').first()
        index_row.json = json.loads('{"current_term_name": "Spring 2020"}')
        json_cache.update_jsonb_row(index_row)

        assert(sis_terms.current_term_id()) == '2202'
        assert(sis_terms.current_term_id(use_cache=False)) == '2178'
Ejemplo n.º 2
0
 def end(self):
     row = JsonCache.query.filter_by(key=self.key()).first()
     if row and row.json.get('start'):
         progress = row.json
         if progress.get('end'):
             app.logger.error(f'Job {self.key()} is already ended: {progress}')
             return False
         progress['end'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
         update_jsonb_row(row)
         return progress
     else:
         app.logger.error(f'Job {self.key()} has not started')
         return False
Ejemplo n.º 3
0
 def update(self, step_description, properties={}):
     row = JsonCache.query.filter_by(key=self.key()).first()
     if row is None:
         app.logger.error(f'No active progress record to append step "{step_description}" to {self.key()}')
         return False
     progress = row.json
     if (not progress.get('start')) or progress.get('end') or (progress.get('steps') is None):
         app.logger.error(f'Progress record {progress} not ready to append step {step_description} to {self.key()}')
         return False
     progress.update(properties)
     now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     step = f'{now} : {step_description}'
     progress['steps'].append(step)
     update_jsonb_row(row)
     return progress
Ejemplo n.º 4
0
    def test_refresh_current_term_index(self, app):
        """Deletes existing index from the cache and adds a fresh one."""
        from boac.api.cache_utils import refresh_current_term_index
        from boac.models import json_cache
        from boac.models.json_cache import JsonCache

        index_row = JsonCache.query.filter_by(key='current_term_index').first()
        index_row.json = 'old'
        json_cache.update_jsonb_row(index_row)
        index = json_cache.fetch('current_term_index')
        assert (index) == 'old'

        refresh_current_term_index()

        index = json_cache.fetch('current_term_index')
        assert (index['current_term_name']) == 'Fall 2017'
        assert (index['future_term_name']) == 'Spring 2018'