<commit_before># -*- coding: utf-8 -*-
'''
integration tests for mac_system
'''

# Import python libs
from __future__ import absolute_import
import datetime
import random
import string

# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath, destructiveTest
from salt.ext.six.moves import range
ensure_in_syspath('../../')

# Import salt libs
import integration
import salt.utils


def __random_string(size=6):
    '''
    Generates a random username
    '''
    return 'RS-' + ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for x in range(size)
    )


TEST_USER = __random_string()
NO_USER = __random_string()


class MacShadowModuleTest(integration.ModuleCase):
    '''
    Validate the mac_system module
    '''

    def setUp(self):
        '''
        Get current settings
        '''
        if not salt.utils.is_darwin():
            self.skipTest('Test only available on Mac OS X')

        if not salt.utils.which('dscl'):
            self.skipTest('Test requires dscl binary')

        if not salt.utils.which('pwpolicy'):
            self.skipTest('Test requires pwpolicy binary')

        if salt.utils.get_uid(salt.utils.get_user()) != 0:
            self.skipTest('Test requires root')

    def tearDown(self):
        '''
        Reset to original settings
        '''
        self.run_function('user.delete', [TEST_USER])

    @destructiveTest
    def test_info(self):
        '''
        Test shadow.info
        '''
        self.run_function('user.add', [TEST_USER])

        # Correct Functionaliry
        ret = self.run_function('shadow.info', [TEST_USER])
        self.assertEqual(ret['name'], TEST_USER)

        # User does not exist
        ret = self.run_function('shadow.info', [NO_USER])
        self.assertEqual(ret['name'], '')

    @destructiveTest
    def test_get_account_created(self):
        '''
        Test shadow.get_account_created
        '''
        self.run_function('user.add', [TEST_USER])

        # Correct Functionality
        text_date = self.run_function('shadow.get_account_created', [TEST_USER])
        self.assertNotEqual(text_date, 'Invalid Timestamp')<commit_msg>Add test for _convert_to_datetime<commit_after># -*- coding: utf-8 -*-
'''
integration tests for mac_system
'''

# Import python libs
from __future__ import absolute_import
import datetime
import random
import string

# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath, destructiveTest
from salt.ext.six.moves import range
ensure_in_syspath('../../')

# Import salt libs
import integration
import salt.utils


def __random_string(size=6):
    '''
    Generates a random username
    '''
    return 'RS-' + ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for x in range(size)
    )


TEST_USER = __random_string()
NO_USER = __random_string()


class MacShadowModuleTest(integration.ModuleCase):
    '''
    Validate the mac_system module
    '''

    def setUp(self):
        '''
        Get current settings
        '''
        if not salt.utils.is_darwin():
            self.skipTest('Test only available on Mac OS X')

        if not salt.utils.which('dscl'):
            self.skipTest('Test requires dscl binary')

        if not salt.utils.which('pwpolicy'):
            self.skipTest('Test requires pwpolicy binary')

        if salt.utils.get_uid(salt.utils.get_user()) != 0:
            self.skipTest('Test requires root')

    def tearDown(self):
        '''
        Reset to original settings
        '''
        self.run_function('user.delete', [TEST_USER])

    def test_convert_to_datetime(self):
        '''
        Test shadow._convert_to_datetime
        '''
        # Correct Functionality
        self.assertEqual(
            self.run_function('shadow._convert_to_datetime', [1297428974]),
            '2011-02-11 07:56:14')

        # Bad Epoch Timestamp (TypeError)
        self.assertEqual(
            self.run_function('shadow._convert_to_datetime', ['spongebob']),
            'Invalid Timestamp')

        # Bad Epoch Timestamp (ValueError)
        self.assertEqual(
            self.run_function('shadow._convert_to_datetime', [-1234567890123]),
            'Invalid Timestamp')

    @destructiveTest
    def test_info(self):
        '''
        Test shadow.info
        '''
        self.run_function('user.add', [TEST_USER])

        # Correct Functionaliry
        ret = self.run_function('shadow.info', [TEST_USER])
        self.assertEqual(ret['name'], TEST_USER)

        # User does not exist
        ret = self.run_function('shadow.info', [NO_USER])
        self.assertEqual(ret['name'], '')

    @destructiveTest
    def test_get_account_created(self):
        '''
        Test shadow.get_account_created
        '''
        self.run_function('user.add', [TEST_USER])

        # Correct Functionality
        text_date = self.run_function('shadow.get_account_created', [TEST_USER])
        self.assertNotEqual(text_date, 'Invalid Timestamp')
{'fraction_non_alphanumeric': 0.1152386658677851, 'fraction_numerical': 0.008587976832434592, 'mean_word_length': 2.6080691642651295, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1069515', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1418, 'n_words': 323}