<commit_before>#!/usr/bin/env python

from pyvows import Vows, expect

#from provy.more.debian import PipRole
from provy.more.debian.database.postgresql import PostgreSQLRole

from unit.tools.role_context import RoleContext
from unit.tools.extra_assertions import *


@Vows.batch
class TestPostgresqlRoleUserCreation(RoleContext):

    def _role_class(self):
        return PostgreSQLRole

    class WhenUsernameIsProvidedAndPasswordIsAsked(RoleContext):
        def topic(self):
            self.role = self._get_role()
            self.role.mock_method("execute", True)
            return self.role.create_user("foo", ask_password=True)

        def should_create_a_user_with_password_prompt_via_createuser_command(self, topic):
            expect(self.role.execute).to_have_been_called_with("createuser -P foo", stdout=False)

        def should_have_created_the_user(self, topic):
            expect(topic).to_be_true()

    class WhenUsernameIsProvidedButPasswordPromptIsBypassed(RoleContext):
        def topic(self):
            self.role = self._get_role()
            self.role.mock_method("execute", True)
            return self.role.create_user("foo", ask_password=False)

        def should_create_a_user_without_password(self, topic):
            expect(self.role.execute).to_have_been_called_with("createuser foo", stdout=False)

        def should_have_created_the_user(self, topic):
            expect(topic).to_be_true()


@Vows.batch
class TestPostgresqlRoleUserRemoval(RoleContext):

    def _role_class(self):
        return PostgreSQLRole

    class WhenUserIsDropped(RoleContext):
        def topic(self):
            self.role = self._get_role()
            self.role.mock_method("execute", True)
            return self.role.drop_user("foo")

        def should_drop_the_user_by_the_name(self, topic):
            expect(self.role.execute).to_have_been_called_with("dropuser foo", stdout=False)

        def should_have_dropped_the_user(self, topic):
            expect(topic).to_be_true()
<commit_msg>Refactoring PostgreSQLRole tests<commit_after>#!/usr/bin/env python

from pyvows import Vows, expect

#from provy.more.debian import PipRole
from provy.more.debian.database.postgresql import PostgreSQLRole

from unit.tools.role_context import RoleContext
from unit.tools.extra_assertions import *


class PostgreSQLRoleContext(RoleContext):

    def _role_class(self):
        return PostgreSQLRole


@Vows.batch
class TestPostgresqlRoleUserCreation(PostgreSQLRoleContext):

    class WhenUsernameIsProvidedAndPasswordIsAsked(RoleContext):
        def topic(self):
            self.role = self._get_role()
            self.role.mock_method("execute", True)
            return self.role.create_user("foo", ask_password=True)

        def should_create_a_user_with_password_prompt_via_createuser_command(self, topic):
            expect(self.role.execute).to_have_been_called_with("createuser -P foo", stdout=False)

        def should_have_created_the_user(self, topic):
            expect(topic).to_be_true()

    class WhenUsernameIsProvidedButPasswordPromptIsBypassed(RoleContext):
        def topic(self):
            self.role = self._get_role()
            self.role.mock_method("execute", True)
            return self.role.create_user("foo", ask_password=False)

        def should_create_a_user_without_password(self, topic):
            expect(self.role.execute).to_have_been_called_with("createuser foo", stdout=False)

        def should_have_created_the_user(self, topic):
            expect(topic).to_be_true()


@Vows.batch
class TestPostgresqlRoleUserRemoval(PostgreSQLRoleContext):

    class WhenUserIsDropped(RoleContext):
        def topic(self):
            self.role = self._get_role()
            self.role.mock_method("execute", True)
            return self.role.drop_user("foo")

        def should_drop_the_user_by_the_name(self, topic):
            expect(self.role.execute).to_have_been_called_with("dropuser foo", stdout=False)

        def should_have_dropped_the_user(self, topic):
            expect(topic).to_be_true()

{'fraction_non_alphanumeric': 0.09119882324099043, 'fraction_numerical': 0.0, 'mean_word_length': 3.533333333333333, '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': '3827924', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1218, 'n_words': 198}