<commit_before>"""
Tests for branding page
"""
import datetime
from pytz import UTC
from django.conf import settings
from django.test.utils import override_settings

from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import editable_modulestore
from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
import student.views

MITX_FEATURES_WITH_STARTDATE = settings.MITX_FEATURES.copy()
MITX_FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False
MITX_FEATURES_WO_STARTDATE = settings.MITX_FEATURES.copy()
MITX_FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True


@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class AnonymousIndexPageTest(ModuleStoreTestCase):
    """
    Tests that anonymous users can access the '/' page,  Need courses with start date
    """
    def setUp(self):
        self.store = editable_modulestore()
        self.course = CourseFactory.create()
        self.course.days_early_for_beta = 5
        self.course.enrollment_start = datetime.datetime.now(UTC) + datetime.timedelta(days=3)
        self.store.save_xmodule(self.course)

    @override_settings(MITX_FEATURES=MITX_FEATURES_WITH_STARTDATE)
    def test_none_user_index_access_with_startdate_fails(self):
        with self.assertRaises(Exception):
            student.views.index(self.factory.get('/'), user=None)  # pylint: disable=E1101

    @override_settings(MITX_FEATURES=MITX_FEATURES_WITH_STARTDATE)
    def test_anon_user_with_startdate_index(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)

    @override_settings(MITX_FEATURES=MITX_FEATURES_WO_STARTDATE)
    def test_anon_user_no_startdate_index(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)<commit_msg>fixes a branding test which was passing for a trivial (wrong) reason<commit_after>"""
Tests for branding page
"""
import datetime
from pytz import UTC
from django.conf import settings
from django.test.utils import override_settings
from django.test.client import RequestFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import editable_modulestore
from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
import student.views

MITX_FEATURES_WITH_STARTDATE = settings.MITX_FEATURES.copy()
MITX_FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False
MITX_FEATURES_WO_STARTDATE = settings.MITX_FEATURES.copy()
MITX_FEATURES_WO_STARTDATE['DISABLE_START_DATES'] = True


@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class AnonymousIndexPageTest(ModuleStoreTestCase):
    """
    Tests that anonymous users can access the '/' page,  Need courses with start date
    """
    def setUp(self):
        self.store = editable_modulestore()
        self.factory = RequestFactory()
        self.course = CourseFactory.create()
        self.course.days_early_for_beta = 5
        self.course.enrollment_start = datetime.datetime.now(UTC) + datetime.timedelta(days=3)
        self.store.save_xmodule(self.course)

    @override_settings(MITX_FEATURES=MITX_FEATURES_WITH_STARTDATE)
    def test_none_user_index_access_with_startdate_fails(self):
        """
        This was a "before" test for a bugfix.  If someone fixes the bug another way in the future
        and this test begins failing (but the other two pass), then feel free to delete this test.
        """
        with self.assertRaisesRegexp(AttributeError, "'NoneType' object has no attribute 'is_authenticated'"):
            student.views.index(self.factory.get('/'), user=None)  # pylint: disable=E1101

    @override_settings(MITX_FEATURES=MITX_FEATURES_WITH_STARTDATE)
    def test_anon_user_with_startdate_index(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)

    @override_settings(MITX_FEATURES=MITX_FEATURES_WO_STARTDATE)
    def test_anon_user_no_startdate_index(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)
{'fraction_non_alphanumeric': 0.08238095238095237, 'fraction_numerical': 0.005714285714285714, 'mean_word_length': 4.942008486562942, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3200610', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1296, 'n_words': 249}