<commit_before>import pytest

from mock import patch, Mock

from spanky.lib import users


class TestCreateUsers(object):

    def setup(self):
        self.conf = [
            {'username': 'foo'},
            {'username': 'bar'},
        ]
        self.user_init = users.UserInit(self.conf)

    def test_build(self):
        self.user_init.create_user = Mock()

        self.user_init.build()

        assert len(self.user_init.create_user.mock_calls) == 2

    @patch.object(users, 'call')
    def test_create_users(self, call):
        call.return_value = 0
        self.user_init.create_user({'username': 'foo'})
        assert call.called

    @patch.object(users, 'call')
    def test_create_users_raises_error_on_fail(self, call):
        call.return_value = 1
        assert pytest.raises(Exception, self.user_init.create_user, {'username': 'foo'})<commit_msg>Create a test asserting the useradd command<commit_after>import pytest

from mock import patch, Mock

from spanky.lib import users


class TestCreateUsers(object):

    def setup(self):
        self.conf = [
            {'username': 'foo'},
            {'username': 'bar'},
        ]
        self.user_init = users.UserInit(self.conf)

    def test_build(self):
        self.user_init.create_user = Mock()

        self.user_init.build()

        assert len(self.user_init.create_user.mock_calls) == 2

    @patch.object(users, 'call')
    def test_create_users(self, call):
        call.return_value = 0
        self.user_init.create_user({'username': 'foo'})
        assert call.called

    @patch.object(users, 'call')
    def test_create_users_raises_error_on_fail(self, call):
        call.return_value = 1
        assert pytest.raises(Exception, self.user_init.create_user, {'username': 'foo'})

    @patch.object(users, 'call')
    def test_useradd_command(self, call):
        call.return_value = 0

        self.user_init.create_user({
            'username': 'foo',
        })

        expected = [
            'useradd', '-U', 'foo'
        ]
        call.assert_called_with(expected)
{'fraction_non_alphanumeric': 0.12397094430992736, 'fraction_numerical': 0.003389830508474576, 'mean_word_length': 2.611888111888112, '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': '2182892', 'n_tokens_mistral': 667, 'n_tokens_neox': 647, 'n_words': 126}