Ejemplo n.º 1
0
    def test_removes_and_restores(self, app):
        from boac.api.cache_utils import refresh_calnet_attributes
        from boac.models import json_cache
        from boac.models.json_cache import JsonCache
        removed_advisor = coe_advisor_uid
        removed_ldap_record = '2040'
        all_active_uids = {
            u.uid
            for u in AuthorizedUser.get_all_active_users()
        }
        assert {removed_advisor, removed_ldap_record}.issubset(all_active_uids)
        calnet_filter = JsonCache.key.like('calnet_user_%')
        all_cached_uids = {
            r.json['uid']
            for r in JsonCache.query.filter(calnet_filter).all()
        }
        assert {removed_advisor, removed_ldap_record}.issubset(all_cached_uids)
        AuthorizedUser.query.filter_by(uid=removed_advisor).delete()
        JsonCache.query.filter_by(
            key=f'calnet_user_for_uid_{removed_ldap_record}').delete()
        std_commit(allow_test_environment=True)

        refresh_calnet_attributes()
        assert json_cache.fetch(
            f'calnet_user_for_uid_{removed_ldap_record}') is not None
        assert json_cache.fetch(
            f'calnet_user_for_uid_{removed_advisor}') is None
Ejemplo n.º 2
0
 def test_academic_standing_options(self):
     json_cache.clear('%')
     assert json_cache.fetch(
         'cohort_filter_options_academic_standing') is None
     options = academic_standing_options(2172)
     assert len(options) == 4
     assert json_cache.fetch(
         'cohort_filter_options_academic_standing') is not None
Ejemplo n.º 3
0
 def test_academic_plans_for_cohort_owner(self):
     json_cache.clear('%')
     assert json_cache.fetch(
         f'cohort_filter_options_academic_plans_for_{coe_advisor}') is None
     options = academic_plans_for_cohort_owner(coe_advisor)
     assert len(options) == 5
     assert json_cache.fetch(
         f'cohort_filter_options_academic_plans_for_{coe_advisor}'
     ) is not None
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'
Ejemplo n.º 5
0
 def test_colleges(self):
     json_cache.clear('%')
     assert json_cache.fetch('cohort_filter_options_colleges') is None
     options = colleges()
     assert len(options) == 3
     assert json_cache.fetch('cohort_filter_options_colleges') is not None