<commit_before>from datetime import timedelta
from unittest2 import skipIf
from django.test import TestCase
from django.conf import settings
from restclients.mock_http import MockHTTP
from restclients.models import CacheEntryTimed
from restclients.exceptions import DataFailureException
from restclients.dao import SWS_DAO
from sis_provisioner.cache import BridgeAccountCache, get_cache_time
from sis_provisioner.test import user_file_name_override, fdao_gws_override,\
    fdao_pws_override


CACHE = 'sis_provisioner.cache.BridgeAccountCache'
MEMCACHE = 'myuw.util.cache_implementation.MyUWMemcachedCache'
ONE_HOUR = 60 * 60
FOUR_HOURS = 60 * 60 * 4
ONE_DAY = 60 * 60 * 24


@fdao_pws_override
@fdao_gws_override
@user_file_name_override
class TestCachePolicy(TestCase):

    def test_get_cache_time(self):
        self.assertEquals(get_cache_time("gws", "/group/"),
                          FOUR_HOURS)
        self.assertEquals(get_cache_time("pws", "/identity/v1/person/"),
                          FOUR_HOURS)
        self.assertEquals(get_cache_time("bridge", "/api/author/users/"),
                          ONE_HOUR)
        self.assertEquals(get_cache_time("bridge",
                                         "/api/author/custom_fields"),
                          ONE_DAY)

    def test_cache_expiration(self):
        with self.settings(RESTCLIENTS_DAO_CACHE_CLASS=CACHE):
            cache = BridgeAccountCache()
            ok_response = MockHTTP()
            ok_response.status = 200
            ok_response.data = "xx"
            url = '/group/uw_member/effective_member'

            response = cache.getCache('gws', url, {})
            self.assertEquals(response, None)

            cache.processResponse("gws", url, ok_response)
            response = cache.getCache("gws", url, {})
            self.assertEquals(response["response"].data, 'xx')

            cache_entry = CacheEntryTimed.objects.get(service='gws', url=url)
            orig_time_saved = cache_entry.time_saved
            cache_entry.time_saved = (orig_time_saved -
                                      timedelta(minutes=(60 * 4) - 2))
            cache_entry.save()
            response = cache.getCache("gws", url, {})
            self.assertNotEquals(response, None)

            cache_entry.time_saved = (orig_time_saved -
                                      timedelta(minutes=(60 * 4) + 1))
            cache_entry.save()
            response = cache.getCache("gws", url, {})
            self.assertEquals(response, None)
<commit_msg>remove junk<commit_after>from datetime import timedelta
from unittest2 import skipIf
from django.test import TestCase
from django.conf import settings
from restclients.mock_http import MockHTTP
from restclients.models import CacheEntryTimed
from restclients.exceptions import DataFailureException
from restclients.dao import SWS_DAO
from sis_provisioner.cache import BridgeAccountCache, get_cache_time
from sis_provisioner.test import user_file_name_override, fdao_gws_override,\
    fdao_pws_override


CACHE = 'sis_provisioner.cache.BridgeAccountCache'
ONE_HOUR = 60 * 60
FOUR_HOURS = 60 * 60 * 4
ONE_DAY = 60 * 60 * 24


@fdao_pws_override
@fdao_gws_override
@user_file_name_override
class TestCachePolicy(TestCase):

    def test_get_cache_time(self):
        self.assertEquals(get_cache_time("gws", "/group/"),
                          FOUR_HOURS)
        self.assertEquals(get_cache_time("pws", "/identity/v1/person/"),
                          FOUR_HOURS)
        self.assertEquals(get_cache_time("bridge", "/api/author/users/"),
                          ONE_HOUR)
        self.assertEquals(get_cache_time("bridge",
                                         "/api/author/custom_fields"),
                          ONE_DAY)

    def test_cache_expiration(self):
        with self.settings(RESTCLIENTS_DAO_CACHE_CLASS=CACHE):
            cache = BridgeAccountCache()
            ok_response = MockHTTP()
            ok_response.status = 200
            ok_response.data = "xx"
            url = '/group/uw_member/effective_member'

            response = cache.getCache('gws', url, {})
            self.assertEquals(response, None)

            cache.processResponse("gws", url, ok_response)
            response = cache.getCache("gws", url, {})
            self.assertEquals(response["response"].data, 'xx')

            cache_entry = CacheEntryTimed.objects.get(service='gws', url=url)
            orig_time_saved = cache_entry.time_saved
            cache_entry.time_saved = (orig_time_saved -
                                      timedelta(minutes=(60 * 4) - 2))
            cache_entry.save()
            response = cache.getCache("gws", url, {})
            self.assertNotEquals(response, None)

            cache_entry.time_saved = (orig_time_saved -
                                      timedelta(minutes=(60 * 4) + 1))
            cache_entry.save()
            response = cache.getCache("gws", url, {})
            self.assertEquals(response, None)

{'fraction_non_alphanumeric': 0.09398120375924815, 'fraction_numerical': 0.011197760447910418, 'mean_word_length': 2.370619946091644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4125858', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1415, 'n_words': 261}