<commit_before># Copyright (C) 2014 SEE AUTHORS FILE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Unittests for the special puppet parser
"""

from . import TestCase
import mock
import replugin.funcworker.puppet as ppt
import replugin.funcworker.puppet
import datetime
NOW = datetime.datetime.now()


class TestPuppetParser(TestCase):
    def setUp(self):
        self.app_logger = mock.MagicMock('logging.Logger').__call__()

    ##################################################################
    # The "puppet:Run" family
    ##################################################################
    def test_run_no_params(self):
        """puppet:Run with no params parses correctly"""
        expected = ["puppet agent --test --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run'
        }

        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    def test_run_noop(self):
        """puppet:Run with noop param parses correctly"""
        expected = ["puppet agent --test --noop --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'noop': True
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    def test_run_tags(self):
        """puppet:Run with tags parses correctly"""
        expected = ["puppet agent --test --tags tag1 tag2 tag3 --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'tags': ['tag1', 'tag2', 'tag3']
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    def test_run_server(self):
        """puppet:Run with specific server params parses correctly"""
        expected = ["puppet agent --test --server puppetmaster01.example.com --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'server': 'puppetmaster01.example.com'
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    '''
    # FIXME
    def test_run_enable(self):
        """puppet:Run with agent enable parses correctly"""
        expected = ["puppet agent --enable --color=false && puppet agent --test --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'enable': True
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)
    '''
    ##################################################################
    # The "puppet:Enable" family
    ##################################################################
    def test_enable(self):
        """puppet:Enable with no params parses correctly"""
        expected = ["puppet agent --enable --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Enable'
        }
        (update, cmd) = ppt._parse_Enable(params, self.app_logger)
        self.assertEqual(cmd, expected)

    ##################################################################
    # The "puppet:Disable" family<commit_msg>Add notes to the commented out unit test<commit_after># Copyright (C) 2014 SEE AUTHORS FILE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Unittests for the special puppet parser
"""

from . import TestCase
import mock
import replugin.funcworker.puppet as ppt
import replugin.funcworker.puppet
import datetime
NOW = datetime.datetime.now()


class TestPuppetParser(TestCase):
    def setUp(self):
        self.app_logger = mock.MagicMock('logging.Logger').__call__()

    ##################################################################
    # The "puppet:Run" family
    ##################################################################
    def test_run_no_params(self):
        """puppet:Run with no params parses correctly"""
        expected = ["puppet agent --test --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run'
        }

        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    def test_run_noop(self):
        """puppet:Run with noop param parses correctly"""
        expected = ["puppet agent --test --noop --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'noop': True
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    def test_run_tags(self):
        """puppet:Run with tags parses correctly"""
        expected = ["puppet agent --test --tags tag1 tag2 tag3 --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'tags': ['tag1', 'tag2', 'tag3']
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    def test_run_server(self):
        """puppet:Run with specific server params parses correctly"""
        expected = ["puppet agent --test --server puppetmaster01.example.com --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'server': 'puppetmaster01.example.com'
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)

    '''
    # FIXME
    #
    # No longer valid. See DE7743 for details. (Basically, we don't get to use
    # shell '&&' chars anymore and so puppet:Run doesn't allow enable:True any more.
    #
    def test_run_enable(self):
        """puppet:Run with agent enable parses correctly"""
        expected = ["puppet agent --enable --color=false && puppet agent --test --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Run',
            'enable': True
        }
        (update, cmd) = ppt._parse_Run(params, self.app_logger)
        self.assertEqual(cmd, expected)
    '''
    ##################################################################
    # The "puppet:Enable" family
    ##################################################################
    def test_enable(self):
        """puppet:Enable with no params parses correctly"""
        expected = ["puppet agent --enable --color=false"]
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'puppet',
            'subcommand': 'Enable'
        }
        (update, cmd) = ppt._parse_Enable(params, self.app_logger)
        self.assertEqual(cmd, expected)

    ##################################################################
    # The "puppet:Disable" family
{'fraction_non_alphanumeric': 0.19257431559158736, 'fraction_numerical': 0.003994830219715662, 'mean_word_length': 2.7170305676855895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5294646', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2301, 'n_words': 676}