Configuring tests

Issue Summary

Hi there, I’m new here and I’m trying to run the docker-compose tests described here https://redash.io/help/open-source/dev-guide/docker
But many of the tests were failing because it couldn’t connect to the database

Technical details:

To run the tests I did the following steps:

  1. Ran docker-compose up
  2. docker-compose run --rm postgres psql -h postgres -U postgres -c "create database tests"
  3. docker-compose run --rm server tests

Here I put one unit test output, which is the same as all other:

self = <tests.test_authentication.TestApiKeyAuthentication testMethod=test_disabled_user_api_key>

    def setUp(self):
        super(TestApiKeyAuthentication, self).setUp()
        self.api_key = "10"
>       self.query = self.factory.create_query(api_key=self.api_key)

tests/test_authentication.py:27: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/factories.py:287: in create_query
    args = {"user": self.user, "data_source": self.data_source, "org": self.org}
tests/factories.py:192: in data_source
    self._data_source = data_source_factory.create(org=self.org)
tests/factories.py:28: in create
    db.session.commit()
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/scoping.py:162: in do
    return getattr(self.registry(), name)(*args, **kwargs)
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py:1027: in commit
    self.transaction.commit()
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py:494: in commit
    self._prepare_impl()
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py:473: in _prepare_impl
    self.session.flush()
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py:2470: in flush
    self._flush(objects)
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py:2608: in _flush
    transaction.rollback(_capture_exception=True)
/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py:68: in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py:153: in reraise
    raise value
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py:2568: in _flush
    flush_context.execute()
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/unitofwork.py:422: in execute
    rec.execute(self)
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/unitofwork.py:589: in execute
    uow,
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py:264: in save_obj
    ) in states_to_update
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py:1434: in _finalize_insert_update_commands
    mapper.dispatch.after_insert(mapper, connection, state)
/usr/local/lib/python3.7/site-packages/sqlalchemy/event/attr.py:322: in __call__
    fn(*args, **kw)
/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/events.py:627: in wrap
    fn(*arg, **kw)
redash/models/__init__.py:1516: in data_source_scanner_after_insert
    apply_scan(target)
querylayer/event_listeners.py:23: in apply_scan
    schema = target.get_schema()
redash/models/__init__.py:206: in get_schema
    schema = query_runner.get_schema(get_stats=refresh)
redash/query_runner/__init__.py:197: in get_schema
    self._get_tables(schema_dict)
redash/query_runner/pg.py:233: in _get_tables
    self._get_definitions(schema, query)
redash/query_runner/pg.py:186: in _get_definitions
    results, error = self.run_query(query, None)
redash/query_runner/pg.py:252: in run_query
    connection = self._get_connection()
redash/query_runner/pg.py:246: in _get_connection
    **self.ssl_config
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

dsn = 'dbname=test sslmode=prefer', connection_factory = None, cursor_factory = None, kwargs = {'dbname': 'test', 'host': None, 'password': None, 'port': None, ...}, kwasync = {'async_': True}

    def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
        """
        Create a new database connection.
    
        The connection parameters can be specified as a string:
    
            conn = psycopg2.connect("dbname=test user=postgres password=secret")
    
        or using a set of keyword arguments:
    
            conn = psycopg2.connect(database="test", user="postgres", password="secret")
    
        Or as a mix of both. The basic connection parameters are:
    
        - *dbname*: the database name
        - *database*: the database name (only as keyword argument)
        - *user*: user name used to authenticate
        - *password*: password used to authenticate
        - *host*: database host address (defaults to UNIX socket if not provided)
        - *port*: connection port number (defaults to 5432 if not provided)
    
        Using the *connection_factory* parameter a different class or connections
        factory can be specified. It should be a callable object taking a dsn
        argument.
    
        Using the *cursor_factory* parameter, a new default cursor factory will be
        used by cursor().
    
        Using *async*=True an asynchronous connection will be created. *async_* is
        a valid alias (for Python versions where ``async`` is a keyword).
    
        Any other keyword parameter will be passed to the underlying client
        library: the list of supported parameters depends on the library version.
    
        """
        kwasync = {}
        if 'async' in kwargs:
            kwasync['async'] = kwargs.pop('async')
        if 'async_' in kwargs:
            kwasync['async_'] = kwargs.pop('async_')
    
        if dsn is None and not kwargs:
            raise TypeError('missing dsn and no parameters')
    
        dsn = _ext.make_dsn(dsn, **kwargs)
>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       psycopg2.OperationalError: could not connect to server: No such file or directory
E               Is the server running locally and accepting
E               connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py:126: OperationalError

It is passing None as host, password and so on:
cursor_factory = None, kwargs = {'dbname': 'test', 'host': None, 'password': None, 'port': None, ...}, kwasync = {'async_': True}

  • Redash Version: latest main branch from redash github
  • Browser/OS: chrome / manjaro
  • How did you install Redash: cloned the repo and then docker-compose up