From 3e2d8e19d5699bf70e009d7666466102d0d54847 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 11 Feb 2019 23:08:32 +0100 Subject: [PATCH] Test setup fixes. --- .dockerignore | 2 ++ .gitignore | 2 -- .travis.yml | 2 +- Dockerfile | 6 ++---- Makefile | 5 ++--- bin/docker-entrypoint | 5 +++++ docker-compose.yml | 1 + pytest.ini | 3 +-- setup.cfg | 3 +++ src/redash_stmo/data_sources/health.py | 2 +- tests/test_datasource_version.py | 4 ++-- 11 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9d0b71a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +build +dist diff --git a/.gitignore b/.gitignore index 03be7d9..8f24cdc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -htmlcov -.tox .coverage coverage.xml .cache diff --git a/.travis.yml b/.travis.yml index 83722d1..3fe9b04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ sudo: false +dist: xenial language: python python: - '2.7' services: - docker -- redis install: - pip install --upgrade pip setuptools wheel script: diff --git a/Dockerfile b/Dockerfile index 97a99af..d2500cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,13 @@ FROM mozilla/redash:latest -COPY . /redash-stmo - ENV PYTHONUNBUFFERED=0 \ - PYTHONPATH=/app/ \ + PYTHONPATH=/redash-stmo:/redash-stmo/src:/app \ REDASH_LOG_LEVEL="INFO" \ REDASH_REDIS_URL=redis://redis:6379/0 \ REDASH_DATABASE_URL=postgresql://postgres@postgres/postgres USER root -RUN pip uninstall -y redash-stmo && pip install -e /redash-stmo +RUN pip uninstall -y redash-stmo USER redash ENTRYPOINT ["/redash-stmo/bin/docker-entrypoint"] diff --git a/Makefile b/Makefile index dbe4863..9d77446 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,8 @@ release: build test: docker-compose build --pull - docker-compose up --no-start - docker-compose start postgres - docker-compose run --rm server sh -c "/redash-stmo/bin/wait-for-it.sh postgres:5432 -- python manage.py database create_tables" + docker-compose up -d + docker-compose run --rm server sh -c "/redash-stmo/bin/wait-for-it.sh postgres:5432 -- python /app/manage.py database create_tables" docker-compose run --rm postgres psql -h postgres -U postgres -c "create database tests;" || echo "Test database exists already." docker-compose run --rm $(CI_ENV) server tests docker-compose down diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 6d7c2b6..a1055f3 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -2,6 +2,7 @@ set -e server() { + pip install --user -e /redash-stmo exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --name redash -w${REDASH_WEB_WORKERS:-4} redash.wsgi:app } @@ -10,6 +11,8 @@ create_db() { } tests() { + pip install --user /redash-stmo + pip install --user pytest mock pytest-cov pytest-flake8 export REDASH_DATABASE_URL="postgresql://postgres@postgres/tests" if [ $# -eq 0 ]; then @@ -24,6 +27,8 @@ tests() { fi } +# always install inside the running container + case "$1" in tests) shift diff --git a/docker-compose.yml b/docker-compose.yml index d31b79e..b4548c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: environment: QUEUES: "queries,scheduled_queries,celery" WORKERS_COUNT: 2 + REDASH_REDIS_URL: "redis://redis:6379/0" redis: image: redis:3.0-alpine restart: unless-stopped diff --git a/pytest.ini b/pytest.ini index ecea4e4..589e8b1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,3 @@ [pytest] norecursedirs = .git .* -addopts = -rsxX --showlocals --tb=native --cov=redash_stmo --cov-report xml --cov-report term --cov-report html --cov-config .coveragerc --cov-config /redash-stmo/.coveragerc -python_paths = . +addopts = --flake8 -rsxX --showlocals --tb=native --cov=redash_stmo --cov-report xml --cov-report term --cov-config .coveragerc --cov-config /redash-stmo/.coveragerc diff --git a/setup.cfg b/setup.cfg index 79bc678..462a4b4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,6 @@ # 3. If at all possible, it is good practice to do this. If you cannot, you # will need to generate wheels for each Python version that you support. universal=1 + +[flake8] +ignore=E501,E127,E128,E124,W503 diff --git a/src/redash_stmo/data_sources/health.py b/src/redash_stmo/data_sources/health.py index 72d7ff6..df4f05e 100644 --- a/src/redash_stmo/data_sources/health.py +++ b/src/redash_stmo/data_sources/health.py @@ -66,7 +66,7 @@ def update_health_status(): except NotImplementedError: logger.info(u"Unable to compute health status without test query for %s", data_source.name) continue - except Exception as e: + except Exception: logger.warning(u"Failed health check for the data source: %s", data_source.name, exc_info=1) statsd_client.incr('update_health_status.error') logger.info(u"task=update_health_status state=error ds_id=%s runtime=%.2f", data_source.id, time.time() - start_time) diff --git a/tests/test_datasource_version.py b/tests/test_datasource_version.py index 5667774..a9e7575 100644 --- a/tests/test_datasource_version.py +++ b/tests/test_datasource_version.py @@ -24,7 +24,7 @@ class TestDatasourceVersion(BaseTestCase): self.patched_runner_type.return_value = runner_type self.patched_run_query.return_value = (json.dumps({ "rows": - [{ "version": version_string.format(version=expected_version) }] + [{"version": version_string.format(version=expected_version)}] }), None) rv = self.make_request('get', '/api/data_sources/{}/version'.format(self.data_source.id), user=self.admin) self.assertEqual(200, rv.status_code) @@ -58,7 +58,7 @@ class TestDatasourceVersion(BaseTestCase): self.patched_runner_type.return_value = "pg" self.patched_run_query.return_value = (json.dumps({ "rows": - [{ "bad_json": "foo" }] + [{"bad_json": "foo"}] }), None) rv = self.make_request('get', '/api/data_sources/{}/version'.format(self.data_source.id), user=self.admin) self.assertEqual(200, rv.status_code)