Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Quicksetup in 0.10.1 (#966) #976

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiida/control/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def determine_setup(self):
break

# This will work for the default Debian postgres setup
if not self.pg_execute:
if self.pg_execute == _pg_execute_not_connected:
dbinfo['user'] = 'postgres'
if _try_subcmd(
non_interactive=bool(not self.interactive), **dbinfo):
Expand Down
14 changes: 14 additions & 0 deletions aiida/control/tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
###########################################################################
"""Unit tests for postgres database maintenance functionality"""
import unittest
import mock

from pgtest.pgtest import PGTest

from aiida.control.postgres import Postgres


def _try_connect_always_fail(**kwargs): # pylint: disable=unused-argument
"""Always return False"""
return False


class PostgresTest(unittest.TestCase):
"""Test the public API provided by the `Postgres` class"""

Expand Down Expand Up @@ -51,6 +57,14 @@ def correct_setup(interactive, dbinfo): # pylint: disable=unused-argument
self.postgres.determine_setup()
self.assertTrue(self.postgres.pg_execute)

@mock.patch(
'aiida.control.postgres._try_connect', new=_try_connect_always_fail)
@mock.patch('aiida.control.postgres._try_subcmd')
def test_fallback_on_subcmd(self, try_subcmd):
"""Ensure that accessing postgres via subcommand is tried if psychopg does not work."""
self._setup_postgres()
self.assertTrue(try_subcmd.call_count >= 1)

def test_create_drop_db_user(self):
"""Check creating and dropping a user works"""
self._setup_postgres()
Expand Down