<commit_before># coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for generic controller behavior."""

import datetime
import re
import types

from core.controllers import base
from core.domain import exp_services
from core.platform import models
from core.tests import test_utils
import feconf
import main

import webapp2
import webtest

current_user_services = models.Registry.import_current_user_services()

FORTY_EIGHT_HOURS_IN_SECS = 48 * 60 * 60
PADDING = 1


class BaseHandlerTest(test_utils.GenericTestBase):

    def test_dev_indicator_appears_in_dev_and_not_in_production(self):
        """Test dev indicator appears in dev and not in production."""

        with self.swap(feconf, 'DEV_MODE', True):
            response = self.testapp.get('/gallery')
            self.assertIn('<div class="oppia-dev-mode">', response.body)

        with self.swap(feconf, 'DEV_MODE', False):
            response = self.testapp.get('/gallery')
            self.assertNotIn('<div class="oppia-dev-mode">', response.body)

    def test_that_no_get_results_in_500_error(self):
        """Test that no GET request results in a 500 error."""

        for route in main.URLS:
            # This was needed for the Django tests to pass (at the time we had
            # a Django branch of the codebase).
            if isinstance(route, tuple):
                continue
            else:
                url = route.template
            url = re.sub('<([^/^:]+)>', 'abc123', url)

            # Some of these will 404 or 302. This is expected.
            response = self.testapp.get(url, expect_errors=True)
            self.log_line(
                'Fetched %s with status code %s' % (url, response.status_int))
            self.assertIn(response.status_int, [200, 302, 404])

        # TODO(sll): Add similar tests for POST, PUT, DELETE.
        # TODO(sll): Set a self.payload attr in the BaseHandler for
        #     POST, PUT and DELETE. Something needs to regulate what
        #     the fields in the payload should be.

    def test_requests_for_invalid_paths(self):
        """Test that requests for invalid paths result in a 404 error."""

        response = self.testapp.get('/gallery/extra', expect_errors=True)
        self.assertEqual(response.status_int, 404)

        response = self.testapp.get('/gallery/data/extra', expect_errors=True)
        self.assertEqual(response.status_int, 404)

        response = self.testapp.post('/gallery/extra', {}, expect_errors=True)
        self.assertEqual(response.status_int, 404)

        response = self.testapp.put('/gallery/extra', {}, expect_errors=True)
        self.assertEqual(response.status_int, 404)

    def test_redirect_in_both_logged_in_and_logged_out_states(self):
        "Test for a redirect in both logged in and logged out states on '/'."

        # Logged out state
        response = self.testapp.get('/')
        self.assertEqual(response.status_int, 302)

        # Login and assert that there is a redirect
        self.login('<EMAIL>')
        response = self.testapp.get('/')
        self.assertEqual(response.status_int, 302)

<commit_msg>Signup user, also check for redirect location<commit_after># coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for generic controller behavior."""

import datetime
import re
import types

from core.controllers import base
from core.domain import exp_services
from core.platform import models
from core.tests import test_utils
import feconf
import main

import webapp2
import webtest

current_user_services = models.Registry.import_current_user_services()

FORTY_EIGHT_HOURS_IN_SECS = 48 * 60 * 60
PADDING = 1


class BaseHandlerTest(test_utils.GenericTestBase):

    def setUp(self):
        super(BaseHandlerTest, self).setUp()
        self.signup('<EMAIL>', 'user')

    def test_dev_indicator_appears_in_dev_and_not_in_production(self):
        """Test dev indicator appears in dev and not in production."""

        with self.swap(feconf, 'DEV_MODE', True):
            response = self.testapp.get('/gallery')
            self.assertIn('<div class="oppia-dev-mode">', response.body)

        with self.swap(feconf, 'DEV_MODE', False):
            response = self.testapp.get('/gallery')
            self.assertNotIn('<div class="oppia-dev-mode">', response.body)

    def test_that_no_get_results_in_500_error(self):
        """Test that no GET request results in a 500 error."""

        for route in main.URLS:
            # This was needed for the Django tests to pass (at the time we had
            # a Django branch of the codebase).
            if isinstance(route, tuple):
                continue
            else:
                url = route.template
            url = re.sub('<([^/^:]+)>', 'abc123', url)

            # Some of these will 404 or 302. This is expected.
            response = self.testapp.get(url, expect_errors=True)
            self.log_line(
                'Fetched %s with status code %s' % (url, response.status_int))
            self.assertIn(response.status_int, [200, 302, 404])

        # TODO(sll): Add similar tests for POST, PUT, DELETE.
        # TODO(sll): Set a self.payload attr in the BaseHandler for
        #     POST, PUT and DELETE. Something needs to regulate what
        #     the fields in the payload should be.

    def test_requests_for_invalid_paths(self):
        """Test that requests for invalid paths result in a 404 error."""

        response = self.testapp.get('/gallery/extra', expect_errors=True)
        self.assertEqual(response.status_int, 404)

        response = self.testapp.get('/gallery/data/extra', expect_errors=True)
        self.assertEqual(response.status_int, 404)

        response = self.testapp.post('/gallery/extra', {}, expect_errors=True)
        self.assertEqual(response.status_int, 404)

        response = self.testapp.put('/gallery/extra', {}, expect_errors=True)
        self.assertEqual(response.status_int, 404)

    def test_redirect_in_both_logged_in_and_logged_out_states(self):
        "Test for a redirect in both logged in and logged out states on '/'."

        # Logged out state
        response = self.testapp.get('/')
        self.assertEqual(response.status_int, 302)
        self.assertIn('gallery', response.headers['location'])

        # Login and assert that there is a redirect
        self.login('<EMAIL>')
        response = self.testapp.get('/')
        self.assertEqual(response.status_int, 302)
        self.assertIn('my_explorations', response.headers['location'])
        self.logout()


{'fraction_non_alphanumeric': 0.09927140255009108, 'fraction_numerical': 0.016133229247983348, 'mean_word_length': 2.929959100204499, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6174705', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2111, 'n_words': 691}