<commit_before>"""A collection of sanity tests for an ECS deployment
that's already been spun up.
"""
import httplib
import os
import unittest

from nose.plugins.attrib import attr
import requests


class SanityTestCase(unittest.TestCase):
    """An abstract base class for all sanity tests."""

    def get_env_and_run_func(self, the_test_func):
        endpoint = os.environ.get('ECS_ENDPOINT', None)
        key = os.environ.get('ECS_KEY', None)
        secret = os.environ.get('ECS_SECRET', None)
        if endpoint and key and secret:
            auth = requests.auth.HTTPBasicAuth(key, secret)
            the_test_func(endpoint, auth)


@attr('sanity')
class TasksTestCase(SanityTestCase):
    """A collection of sanity tests for the /_tasks endpoint."""

    def test_request_too_large(self):
        sizes = {
            3 * 1024: httplib.CREATED,
            6 * 1024: httplib.REQUEST_ENTITY_TOO_LARGE,
        }

        for (size, expected_status_code) in sizes.iteritems():
            def the_test(endpoint, auth):
                url = '%s/v1.0/tasks' % endpoint
                body = {
                    'docker_image': 'ubuntu',
                    'tag': 'latest',
                    'cmd': [
                        'echo',
                        '0' * size,<commit_msg>update sanity tests ... v1.0 -> v1.1<commit_after>"""A collection of sanity tests for an ECS deployment
that's already been spun up.
"""
import httplib
import os
import unittest

from nose.plugins.attrib import attr
import requests

#
# defines the api version that this set of tests validates
#
_api_version = r'v1.1'


class SanityTestCase(unittest.TestCase):
    """An abstract base class for all sanity tests."""

    def get_env_and_run_func(self, the_test_func):
        endpoint = os.environ.get('ECS_ENDPOINT', None)
        key = os.environ.get('ECS_KEY', None)
        secret = os.environ.get('ECS_SECRET', None)
        if endpoint and key and secret:
            auth = requests.auth.HTTPBasicAuth(key, secret)
            the_test_func(endpoint, auth)


@attr('sanity')
class TasksTestCase(SanityTestCase):
    """A collection of sanity tests for the /_tasks endpoint."""

    def test_request_too_large(self):
        sizes = {
            3 * 1024: httplib.CREATED,
            6 * 1024: httplib.REQUEST_ENTITY_TOO_LARGE,
        }

        for (size, expected_status_code) in sizes.iteritems():
            def the_test(endpoint, auth):
                url = '%s/%s/tasks' % (endpoint, _api_version)
                body = {
                    'docker_image': 'ubuntu:14.04',
                    'cmd': [
                        'echo',
                        '0' * size,
{'fraction_non_alphanumeric': 0.10614525139664804, 'fraction_numerical': 0.01266294227188082, 'mean_word_length': 2.1900237529691213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6692071', 'n_tokens_mistral': 834, 'n_tokens_neox': 785, 'n_words': 214}