<commit_before>import json
from unittest2 import skipIf
from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.core.urlresolvers import reverse
from myuw.test.api import missing_url, get_user, get_user_pass


FDAO_SWS = 'restclients.dao_implementation.sws.File'
SESSION = 'django.contrib.sessions.middleware.SessionMiddleware'
COMMON = 'django.middleware.common.CommonMiddleware'
CSRF_VIEW = 'django.middleware.csrf.CsrfViewMiddleware'
AUTH = 'django.contrib.auth.middleware.AuthenticationMiddleware'
REMOTE_USER = 'django.contrib.auth.middleware.RemoteUserMiddleware'
MESSAGE = 'django.contrib.messages.middleware.MessageMiddleware'
XFRAME = 'django.middleware.clickjacking.XFrameOptionsMiddleware'
USER_SERVICE = 'userservice.user.UserServiceMiddleware'
AUTH_BACKEND = 'django.contrib.auth.backends.ModelBackend'


@override_settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                   MIDDLEWARE_CLASSES=(SESSION,
                                       COMMON,
                                       CSRF_VIEW,
                                       AUTH,
                                       REMOTE_USER,
                                       MESSAGE,
                                       XFRAME,
                                       USER_SERVICE,
                                       ),
                   AUTHENTICATION_BACKENDS=(AUTH_BACKEND,)
                   )
class TestApiThrive(TestCase):
    def setUp(self):
        self.client = Client()

    @skipIf(missing_url("myuw_thrive_api"), "thrive urls not configured")
    def test_javerage_email(self):
        url = reverse("myuw_thrive_api")
        get_user('javerage')
        self.client.login(username='javerage',
                          password=get_user_pass('<PASSWORD>'))

        session = self.client.session
        session["myuw_override_date"] = "2015-02-12"
        session.save()

        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["title"], "Internships and Exploration")

        session["myuw_override_date"] = "2015-02-21"
        session.save()
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["title"], "Revisiting Plans, Exploring Options")

    def test_error(self):
        url = reverse("myuw_thrive_api")
        get_user('jerror')
        self.client.login(username='jerror',
                          password=get_user_pass('<PASSWORD>'))
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)<commit_msg>fix unit test<commit_after>import json
from unittest2 import skipIf
from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.core.urlresolvers import reverse
from myuw.test.api import missing_url, get_user, get_user_pass


FDAO_SWS = 'restclients.dao_implementation.sws.File'
SESSION = 'django.contrib.sessions.middleware.SessionMiddleware'
COMMON = 'django.middleware.common.CommonMiddleware'
CSRF_VIEW = 'django.middleware.csrf.CsrfViewMiddleware'
AUTH = 'django.contrib.auth.middleware.AuthenticationMiddleware'
REMOTE_USER = 'django.contrib.auth.middleware.RemoteUserMiddleware'
MESSAGE = 'django.contrib.messages.middleware.MessageMiddleware'
XFRAME = 'django.middleware.clickjacking.XFrameOptionsMiddleware'
USER_SERVICE = 'userservice.user.UserServiceMiddleware'
AUTH_BACKEND = 'django.contrib.auth.backends.ModelBackend'


@override_settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                   MIDDLEWARE_CLASSES=(SESSION,
                                       COMMON,
                                       CSRF_VIEW,
                                       AUTH,
                                       REMOTE_USER,
                                       MESSAGE,
                                       XFRAME,
                                       USER_SERVICE,
                                       ),
                   AUTHENTICATION_BACKENDS=(AUTH_BACKEND,)
                   )
class TestApiThrive(TestCase):
    def setUp(self):
        self.client = Client()

    @skipIf(missing_url("myuw_thrive_api"), "thrive urls not configured")
    def test_javerage_email(self):
        url = reverse("myuw_thrive_api")
        get_user('javerage')
        self.client.login(username='javerage',
                          password=get_user_pass('<PASSWORD>'))
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)
        data = json.loads(response.content)
        self.assertEquals(data["title"], "Fail Forward")

        session = self.client.session
        session["myuw_override_date"] = "2015-02-12"
        session.save()
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)

        session["myuw_override_date"] = "2015-02-21"
        session.save()
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)
{'fraction_non_alphanumeric': 0.09247104247104247, 'fraction_numerical': 0.010038610038610039, 'mean_word_length': 2.2811906269791007, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3183967', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1411, 'n_words': 218}