示例#1
0
def user(name,
         password,
         superuser=False,
         createdb=False,
         createrole=False,
         inherit=True,
         login=True,
         connection_limit=None,
         encrypted_password=False):
    """
    Require the existence of a PostgreSQL user.

    The password and options provided will only be applied when creating
    a new user (existing users will *not* be modified).

    ::

        from burlap import require

        require.postgres.user('dbuser', password='******')

        require.postgres.user('dbuser2', password='******',
            createdb=True, create_role=True, connection_limit=20)

    """
    if not user_exists(name):
        create_user(name, password, superuser, createdb, createrole, inherit,
                    login, connection_limit, encrypted_password)
示例#2
0
 def test_create_user_with_no_options(self, _run_as_pg):
     from burlap import postgres
     postgres.create_user('foo', 'bar')
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN UNENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
示例#3
0
 def test_create_user_with_no_connection_limit(self, _run_as_pg):
     from burlap import postgres
     postgres.create_user('foo', 'bar', connection_limit=-1)
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN CONNECTION LIMIT -1 UNENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
示例#4
0
 def test_create_user_with_no_connection_limit(self, _run_as_pg):
     from burlap import postgres
     postgres.create_user('foo', 'bar', connection_limit=-1)
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN CONNECTION LIMIT -1 UNENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
示例#5
0
 def test_create_user_with_no_options(self, _run_as_pg):
     from burlap import postgres
     postgres.create_user('foo', 'bar')
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN UNENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
示例#6
0
def test_create_and_drop_user(postgres_server):

    from burlap.postgres import create_user, drop_user, user_exists

    create_user('alice', password='******')
    assert user_exists('alice')

    drop_user('alice')
    assert not user_exists('alice')
示例#7
0
def test_create_and_drop_user(postgres_server):

    from burlap.postgres import create_user, drop_user, user_exists

    create_user('alice', password='******')
    assert user_exists('alice')

    drop_user('alice')
    assert not user_exists('alice')
示例#8
0
 def test_create_user_with_custom_options(self, _run_as_pg):
     from burlap import postgres
     postgres.create_user('foo', 'bar', superuser=True, createdb=True,
                          createrole=True, inherit=False, login=False,
                          connection_limit=20, encrypted_password=True)
     expected = (
         'psql -c "CREATE USER foo SUPERUSER CREATEDB CREATEROLE '
         'NOINHERIT NOLOGIN CONNECTION LIMIT 20 '
         'ENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
示例#9
0
 def test_create_user_with_custom_options(self, _run_as_pg):
     from burlap import postgres
     postgres.create_user('foo',
                          'bar',
                          superuser=True,
                          createdb=True,
                          createrole=True,
                          inherit=False,
                          login=False,
                          connection_limit=20,
                          encrypted_password=True)
     expected = ('psql -c "CREATE USER foo SUPERUSER CREATEDB CREATEROLE '
                 'NOINHERIT NOLOGIN CONNECTION LIMIT 20 '
                 'ENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
示例#10
0
def user(name, password, superuser=False, createdb=False,
         createrole=False, inherit=True, login=True, connection_limit=None,
         encrypted_password=False):
    """
    Require the existence of a PostgreSQL user.

    The password and options provided will only be applied when creating
    a new user (existing users will *not* be modified).

    ::

        from burlap import require

        require.postgres.user('dbuser', password='******')

        require.postgres.user('dbuser2', password='******',
            createdb=True, create_role=True, connection_limit=20)

    """
    if not user_exists(name):
        create_user(name, password, superuser, createdb, createrole, inherit,
                    login, connection_limit, encrypted_password)