<commit_before>########
# Copyright (c) 2015 GigaSpaces Technologies Ltd. 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.


import json
import os
import pkg_resources
import subprocess
import jinja2

import cosmo_tester
from cosmo_tester.framework.testenv import TestCase


SHELL_SCRIPT_TEMPLATE = 'run_old_rest_client_in_shell.template'
PYTHON_SCRIPT_TEMPLATE = 'use_old_rest_client.template'
SHELL_SCRIPT_NAME = 'test_old_client.sh'
PYTHON_SCRIPT_NAME = 'test_old_client.py'
VENV_NAME = 'cfy_32_cli_env'
CFY_CLIENT_VERSION = '3.2'


class RestApiBackwardsCompatibilityTest(TestCase):

    def setUp(self):
        super(RestApiBackwardsCompatibilityTest, self).setUp()
        self._render_python_script()
        self._render_shell_script()

    def tearDown(self):
        if os.path.exists(PYTHON_SCRIPT_NAME):
            os.remove(PYTHON_SCRIPT_NAME)

        if os.path.exists(SHELL_SCRIPT_NAME):
            os.remove(SHELL_SCRIPT_NAME)

        super(RestApiBackwardsCompatibilityTest, self).tearDown()

    def _render_python_script(self):
        python_script_template = pkg_resources.resource_string(
            cosmo_tester.__name__,
            'resources/scripts/{0}'.format(PYTHON_SCRIPT_TEMPLATE)
        )
        rendered_python_script = jinja2.Template(python_script_template). \
            render(cfy_manager_ip=self.env.management_ip)
        with open(os.path.join(self.workdir, PYTHON_SCRIPT_NAME), 'w') as f:
            f.write(rendered_python_script)

    def _render_shell_script(self):
        shell_script_template = pkg_resources.resource_string(
            cosmo_tester.__name__,
            'resources/scripts/{0}'.format(SHELL_SCRIPT_TEMPLATE)
        )
        template_values = {'work_dir': self.workdir,
                           'venv_name': VENV_NAME,
                           'client_version': CFY_CLIENT_VERSION,
                           'python_script_name': PYTHON_SCRIPT_NAME}
        rendered_shell_script = jinja2.Template(shell_script_template).\
            render(template_values)<commit_msg>CFY-5994 - removed unnecessary teardown<commit_after>########
# Copyright (c) 2015 GigaSpaces Technologies Ltd. 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.


import json
import os
import pkg_resources
import subprocess
import jinja2

import cosmo_tester
from cosmo_tester.framework.testenv import TestCase


SHELL_SCRIPT_TEMPLATE = 'run_old_rest_client_in_shell.template'
PYTHON_SCRIPT_TEMPLATE = 'use_old_rest_client.template'
SHELL_SCRIPT_NAME = 'test_old_client.sh'
PYTHON_SCRIPT_NAME = 'test_old_client.py'
VENV_NAME = 'cfy_32_cli_env'
CFY_CLIENT_VERSION = '3.2'


class RestApiBackwardsCompatibilityTest(TestCase):

    def setUp(self):
        super(RestApiBackwardsCompatibilityTest, self).setUp()
        self._render_python_script()
        self._render_shell_script()

    def _render_python_script(self):
        python_script_template = pkg_resources.resource_string(
            cosmo_tester.__name__,
            'resources/scripts/{0}'.format(PYTHON_SCRIPT_TEMPLATE)
        )
        rendered_python_script = jinja2.Template(python_script_template). \
            render(cfy_manager_ip=self.env.management_ip)
        with open(os.path.join(self.workdir, PYTHON_SCRIPT_NAME), 'w') as f:
            f.write(rendered_python_script)

    def _render_shell_script(self):
        shell_script_template = pkg_resources.resource_string(
            cosmo_tester.__name__,
            'resources/scripts/{0}'.format(SHELL_SCRIPT_TEMPLATE)
        )
        template_values = {'work_dir': self.workdir,
                           'venv_name': VENV_NAME,
                           'client_version': CFY_CLIENT_VERSION,
                           'python_script_name': PYTHON_SCRIPT_NAME}
        rendered_shell_script = jinja2.Template(shell_script_template).\
            render(template_values)
{'fraction_non_alphanumeric': 0.08091664976678159, 'fraction_numerical': 0.007706347596836341, 'mean_word_length': 3.376220053238687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '146522', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1479, 'n_words': 328}