<commit_before>import json
from copy import deepcopy
from datetime import datetime, timedelta
import calendar
from onyx.encryption import encrypt, decrypt
from flask import url_for
from flask.sessions import SecureCookieSessionInterface
from nose.tools import (
    assert_equals,
    assert_is_not_none,
    assert_is_none,
    assert_not_equals
)
from werkzeug.http import parse_cookie
from tests.base import BaseTestCase


class TestNewtabServing(BaseTestCase):

    def test_missing_payload(self):
        """
        A call without a payload errors
        """
        response = self.client.post(url_for('v1_links.fetch'),
                                    content_type='application/json')
        assert_equals(response.status_code, 400)
        assert_is_none(response.headers.get('Set-Cookie'))
        assert_equals(int(response.headers.get('Content-Length')), 0)

    def test_missing_mime_type(self):
        """
        A call without a mimetype errors
        """
        response = self.client.post(url_for('v1_links.fetch'),
                                    data=json.dumps({'locale': 'en-US', 'directoryCount': 1}))
        assert_equals(response.status_code, 400)
        assert_is_none(response.headers.get('Set-Cookie'))
        assert_equals(int(response.headers.get('Content-Length')), 0)

    def test_unknown_locale(self):
        """
        A call with an unknown locale yields an HTTP 204 response
        """
        response = self.client.post(url_for('v1_links.fetch'),
                                    content_type='application/json',
                                    data=json.dumps({'locale': 'zh-CN', 'directoryCount': 1}))
        assert_equals(response.status_code, 204)
        assert_equals(int(response.headers.get('Content-Length')), 0)
<commit_msg>new test for v1 to account for missing directoryCount parameter. remove mimetype requirement in test<commit_after>import json
from copy import deepcopy
from datetime import datetime, timedelta
import calendar
from onyx.encryption import encrypt, decrypt
from flask import url_for
from flask.sessions import SecureCookieSessionInterface
from nose.tools import (
    assert_equals,
    assert_is_not_none,
    assert_is_none,
    assert_not_equals
)
from werkzeug.http import parse_cookie
from tests.base import BaseTestCase


class TestNewtabServing(BaseTestCase):

    def test_missing_payload(self):
        """
        A call without a payload errors
        """
        response = self.client.post(url_for('v1_links.fetch'),
                                    content_type='application/json')
        assert_equals(response.status_code, 400)
        assert_is_none(response.headers.get('Set-Cookie'))
        assert_equals(int(response.headers.get('Content-Length')), 0)

    def test_missing_dircount(self):
        """
        A call without directoryCount errors
        """
        response = self.client.post(url_for('v1_links.fetch'),
                                    content_type='application/json',
                                    data=json.dumps({'locale': 'en-US'}))
        assert_equals(response.status_code, 400)
        assert_is_none(response.headers.get('Set-Cookie'))
        assert_equals(int(response.headers.get('Content-Length')), 0)

    def test_unknown_locale(self):
        """
        A call with an unknown locale yields an HTTP 204 response
        """
        response = self.client.post(url_for('v1_links.fetch'),
                                    content_type='application/json',
                                    data=json.dumps({'locale': 'zh-CN', 'directoryCount': {"organic": 1}}))
        assert_equals(response.status_code, 204)
        assert_equals(int(response.headers.get('Content-Length')), 0)

{'fraction_non_alphanumeric': 0.10050653159157558, 'fraction_numerical': 0.010663822980538524, 'mean_word_length': 2.649805447470817, 'pattern_counts': {'":': 1, '<': 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': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1961432', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1001, 'n_words': 217}