<commit_before># -*- coding: utf-8 -*-
'''
    :codeauthor: :email:`<NAME> <<EMAIL>>`
'''

# Import Salt Testing Libs
from salttesting import TestCase, skipIf
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON

ensure_in_syspath('../../')

# Import Salt Libs
from salt.modules import mac_user
from salt.exceptions import SaltInvocationError, CommandExecutionError

# Import python Libs
import pwd
import grp


@skipIf(NO_MOCK, NO_MOCK_REASON)
class MacUserTestCase(TestCase):
    '''
    TestCase for the salt.modules.mac_user modules
    '''

    mac_user.__context__ = {}
    mac_user.__grains__ = {}
    mac_user.__salt__ = {}

    mock_pwall = [pwd.struct_passwd(('_amavisd', '*', 83, 83, 'AMaViS Daemon',
                                    '/var/virusmails', '/usr/bin/false')),
                  pwd.struct_passwd(('_appleevents', '*', 55, 55,
                                     'AppleEvents Daemon',
                                    '/var/empty', '/usr/bin/false')),
                  pwd.struct_passwd(('_appowner', '*', 87, 87,
                                     'Application Owner',
                                     '/var/empty', '/usr/bin/false'))]
    mock_pwnam = pwd.struct_passwd(('_TEST_GROUP', '*', 83, 83, 'AMaViS Daemon',
                                    '/var/virusmails', '/usr/bin/false'))
    mock_getgrgid = grp.struct_group(('_TEST_GROUP', '*', 83, []))
    mock_getgrall = [grp.struct_group(('accessibility', '*', 90, [])),
                     grp.struct_group(('admin', '*', 80, ['root', 'admin']))]
    mock_info_ret = {'shell': '/bin/bash', 'name': 'test', 'gid': 4376,
                     'groups': ['TEST_GROUP'], 'home': '/Users/foo',
                     'fullname': 'TEST USER', 'uid': 4376}

    def test_osmajor(self):
        '''
        Tests version of OS X
        '''
        with patch.dict(mac_user.__grains__, {'kernel': 'Darwin',
                                              'osrelease': '10.9.1'}):
            self.assertEqual(mac_user._osmajor(), 10.9)

    @skipIf(True, 'Waiting on some clarifications from bug report #10594')
    def test_flush_dscl_cache(self):
        # TODO: Implement tests after clarifications come in
        pass

    def test_dscl(self):
        '''
        Tests the creation of a dscl node
        '''
        mac_mock = MagicMock(return_value={'pid': 4948,
                                           'retcode': 0,
                                           'stderr': '',
                                           'stdout': ''})
        with patch.dict(mac_user.__salt__, {'cmd.run_all': mac_mock}):
            with patch.dict(mac_user.__grains__, {'kernel': 'Darwin',
                                                  'osrelease': '10.9.1'}):
                self.assertEqual(mac_user._dscl('username'), {'pid': 4948,
                                                              'retcode': 0,
                                                              'stderr': '',
                                                              'stdout': ''})

    @patch('pwd.getpwall', MagicMock(return_value=mock_pwall))
    def test_first_avail_uid(self):
        '''
        Tests the availability of the next uid
        '''
        self.assertEqual(mac_user._first_avail_uid(), 501)

    # 'add' function tests: 4
    # Only tested error handling
    # Full functionality tests covered in integration testing

    @patch('salt.modules.mac_user.info', MagicMock(return_value=mock_info_ret))
    def test_add_user_exists(self):
        '''
        Tests if the user exists or not
        '''
        self.assertRaises(CommandExecutionError, mac_user.add, 'test')<commit_msg>TST: Updated mac_user tests for modifications to OS release handling<commit_after># -*- coding: utf-8 -*-
'''
    :codeauthor: :email:`<NAME> <<EMAIL>>`
'''

# Import Salt Testing Libs
from salttesting import TestCase, skipIf
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON

ensure_in_syspath('../../')

# Import Salt Libs
from salt.modules import mac_user
from salt.exceptions import SaltInvocationError, CommandExecutionError

# Import python Libs
import pwd
import grp


@skipIf(NO_MOCK, NO_MOCK_REASON)
class MacUserTestCase(TestCase):
    '''
    TestCase for the salt.modules.mac_user modules
    '''

    mac_user.__context__ = {}
    mac_user.__grains__ = {}
    mac_user.__salt__ = {}

    mock_pwall = [pwd.struct_passwd(('_amavisd', '*', 83, 83, 'AMaViS Daemon',
                                    '/var/virusmails', '/usr/bin/false')),
                  pwd.struct_passwd(('_appleevents', '*', 55, 55,
                                     'AppleEvents Daemon',
                                    '/var/empty', '/usr/bin/false')),
                  pwd.struct_passwd(('_appowner', '*', 87, 87,
                                     'Application Owner',
                                     '/var/empty', '/usr/bin/false'))]
    mock_pwnam = pwd.struct_passwd(('_TEST_GROUP', '*', 83, 83, 'AMaViS Daemon',
                                    '/var/virusmails', '/usr/bin/false'))
    mock_getgrgid = grp.struct_group(('_TEST_GROUP', '*', 83, []))
    mock_getgrall = [grp.struct_group(('accessibility', '*', 90, [])),
                     grp.struct_group(('admin', '*', 80, ['root', 'admin']))]
    mock_info_ret = {'shell': '/bin/bash', 'name': 'test', 'gid': 4376,
                     'groups': ['TEST_GROUP'], 'home': '/Users/foo',
                     'fullname': 'TEST USER', 'uid': 4376}

    @skipIf(True, 'Waiting on some clarifications from bug report #10594')
    def test_flush_dscl_cache(self):
        # TODO: Implement tests after clarifications come in
        pass

    def test_dscl(self):
        '''
        Tests the creation of a dscl node
        '''
        mac_mock = MagicMock(return_value={'pid': 4948,
                                           'retcode': 0,
                                           'stderr': '',
                                           'stdout': ''})
        with patch.dict(mac_user.__salt__, {'cmd.run_all': mac_mock}):
            with patch.dict(mac_user.__grains__,
                            {'kernel': 'Darwin', 'osrelease': '10.9.1',
                             'osrelease_info': (10, 9, 1)}):
                self.assertEqual(mac_user._dscl('username'), {'pid': 4948,
                                                              'retcode': 0,
                                                              'stderr': '',
                                                              'stdout': ''})

    @patch('pwd.getpwall', MagicMock(return_value=mock_pwall))
    def test_first_avail_uid(self):
        '''
        Tests the availability of the next uid
        '''
        self.assertEqual(mac_user._first_avail_uid(), 501)

    # 'add' function tests: 4
    # Only tested error handling
    # Full functionality tests covered in integration testing

    @patch('salt.modules.mac_user.info', MagicMock(return_value=mock_info_ret))
    def test_add_user_exists(self):
        '''
        Tests if the user exists or not
        '''
        self.assertRaises(CommandExecutionError, mac_user.add, 'test')
{'fraction_non_alphanumeric': 0.13381828163601428, 'fraction_numerical': 0.016332692835575074, 'mean_word_length': 1.7581377744133233, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '803497', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2017, 'n_words': 443}