| |
@@ -22,6 +22,7 @@
|
| |
import os
|
| |
import tempfile
|
| |
import copy
|
| |
+ import time
|
| |
|
| |
import resultsdb
|
| |
import resultsdb.cli
|
| |
@@ -48,8 +49,12 @@
|
| |
def setup_class(cls):
|
| |
cls.dbfile = tempfile.NamedTemporaryFile(delete=False)
|
| |
cls.dbfile.close()
|
| |
- resultsdb.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s' % cls.dbfile.name
|
| |
- #resultsdb.app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://resultsdb:resultsdb@localhost:5432/resultsdb'
|
| |
+ postgres_port = os.getenv('POSTGRES_5432_TCP', None)
|
| |
+ if postgres_port:
|
| |
+ time.sleep(1) # for some weird reason, docker container is 'up' before postgres is ready
|
| |
+ resultsdb.app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://resultsdb:resultsdb@localhost:%s/resultsdb' % postgres_port
|
| |
+ else:
|
| |
+ resultsdb.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s' % cls.dbfile.name
|
| |
resultsdb.app.config['MESSAGE_BUS_PUBLISH'] = True
|
| |
resultsdb.app.config['MESSAGE_BUS_PLUGIN'] = 'dummy'
|
| |
|
| |
@@ -859,9 +864,11 @@
|
| |
assert data['data'][1]['outcome'] == "FAILED"
|
| |
|
| |
def test_get_results_latest_distinct_on(self):
|
| |
- print("=============== HINT ===============\nThis test requires PostgreSQL, because DISTINCT ON does work differently in SQLite")
|
| |
+ """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""
|
| |
if os.getenv('NO_CAN_HAS_POSTGRES', None):
|
| |
return
|
| |
+ if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
|
| |
+ raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")
|
| |
|
| |
self.helper_create_testcase()
|
| |
|
| |
@@ -880,9 +887,11 @@
|
| |
assert data['data'][0]['data']['scenario'][0] == 'scenario2'
|
| |
|
| |
def test_get_results_latest_distinct_on_more_specific_cases_1(self):
|
| |
- print("=============== HINT ===============\nThis test requires PostgreSQL, because DISTINCT ON does work differently in SQLite")
|
| |
+ """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""
|
| |
if os.getenv('NO_CAN_HAS_POSTGRES', None):
|
| |
return
|
| |
+ if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
|
| |
+ raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")
|
| |
|
| |
'''
|
| |
| id | testcase | scenario |
|
| |
@@ -903,9 +912,11 @@
|
| |
assert len(data['data']) == 4
|
| |
|
| |
def test_get_results_latest_distinct_on_more_specific_cases_2(self):
|
| |
- print("=============== HINT ===============\nThis test requires PostgreSQL, because DISTINCT ON does work differently in SQLite")
|
| |
+ """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""
|
| |
if os.getenv('NO_CAN_HAS_POSTGRES', None):
|
| |
return
|
| |
+ if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
|
| |
+ raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")
|
| |
|
| |
'''
|
| |
| id | testcase | scenario |
|
| |
@@ -928,9 +939,11 @@
|
| |
assert len(data['data']) == 5
|
| |
|
| |
def test_get_results_latest_distinct_on_more_specific_cases_2(self):
|
| |
- print("=============== HINT ===============\nThis test requires PostgreSQL, because DISTINCT ON does work differently in SQLite")
|
| |
+ """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""
|
| |
if os.getenv('NO_CAN_HAS_POSTGRES', None):
|
| |
return
|
| |
+ if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
|
| |
+ raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")
|
| |
|
| |
'''
|
| |
| id | testcase | scenario |
|
| |
@@ -959,9 +972,11 @@
|
| |
assert tc_1s[1]['outcome'] == 'FAILED'
|
| |
|
| |
def test_get_results_latest_distinct_on_with_scenario_not_defined(self):
|
| |
- print("=============== HINT ===============\nThis test requires PostgreSQL, because DISTINCT ON does work differently in SQLite")
|
| |
+ """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""
|
| |
if os.getenv('NO_CAN_HAS_POSTGRES', None):
|
| |
return
|
| |
+ if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
|
| |
+ raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")
|
| |
|
| |
self.helper_create_testcase()
|
| |
self.helper_create_result(outcome="PASSED", testcase=self.ref_testcase_name)
|
| |
We finally got to the point where proper testing can not be done against SQLite, but requires PostgreSQL.
tox-docker is an easy to use tool, that takes care of spinning up (and removing) docker containers. Sadly, the plugin is not (yet?) packaged in Fedora, but this can easily be worked-around with
pip install --user
(works on my setup, at least :-D), so I don't see any major issue here.If somebody wants to go about it without docker, using
pytest
instead oftox
is still an option.