<commit_before>import test_utils
from nose.tools import eq_

from webpagemaker.api.views import BLOCKED_MSG

from msie_user_agents import internet_explorers

SIMPLE_HTML = "<!DOCTYPE html><html><head><title>hi</title></head>" + \
              "<body>hello.</body></html>"

class BrowserBlockingTests(test_utils.TestCase):
    def _request_published_page_as(self, user_agent):
        response = self.client.post('/api/page', {'html': SIMPLE_HTML})
        page_id = response.content
        response = self.client.get(page_id, HTTP_USER_AGENT=user_agent)
        return response

    def test_known_problem_browsers_cannot_see_published_pages(self):
        # TODO: Do we want a (semi-)comprehensive list of problem browsers?
        for user_agent in internet_explorers:
            response = self._request_published_page_as(user_agent)
            eq_(response.status_code, 403)<commit_msg>Fixed #458 by reducing the number of publishing requests made by tests.<commit_after>import test_utils
from nose.tools import eq_

from webpagemaker.api.views import BLOCKED_MSG

from msie_user_agents import internet_explorers

SIMPLE_HTML = "<!DOCTYPE html><html><head><title>hi</title></head>" + \
              "<body>hello.</body></html>"

class BrowserBlockingTests(test_utils.TestCase):
    page_id = None
    
    def _request_published_page_as(self, user_agent):
        if self.page_id is None:
            response = self.client.post('/api/page', {'html': SIMPLE_HTML})
            self.page_id = response.content
        response = self.client.get(self.page_id, HTTP_USER_AGENT=user_agent)
        return response

    def test_known_problem_browsers_cannot_see_published_pages(self):
        # TODO: Do we want a (semi-)comprehensive list of problem browsers?
        for user_agent in internet_explorers:
            response = self._request_published_page_as(user_agent)
            eq_(response.status_code, 403)
{'fraction_non_alphanumeric': 0.09422175950026028, 'fraction_numerical': 0.004685059864653826, 'mean_word_length': 3.7107843137254903, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4256562', 'n_tokens_mistral': 603, 'n_tokens_neox': 567, 'n_words': 124}