Skip to content

Commit 678e04f

Browse files
committed
#485 refactor of all tests
1 parent 4266ab9 commit 678e04f

14 files changed

+166
-175
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2013-2018, Roy Russo
1+
Copyright 2013-2019, Roy Russo
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

docs/source/developer-guide.rst

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,25 @@ Once the distribution is built, you can start the server with ``python applicati
5757
Running Tests
5858
-------------
5959

60-
1. ``/tests/scripts`` contains ``start_clusters.sh`` which will start up 3 ES clusters on ports 9200, 8200, 7200. These are versions 2.x, 5.x, and 6.x respectively.
61-
2. Edit ``start_clusters.sh`` to point to your local ES binaries.
62-
3. Source the virtual environment:
60+
All tests run using docker containers for specific versions of ES. Running the entire suite will run against all containers, one at a time.
61+
62+
To run all tests across all ES major versions:
6363

6464
.. code-block:: bash
6565
66-
source ../environments/elastichq/bin/activate
66+
./run-tests.sh
6767
68-
4. To run tests:
68+
To run tests for a specific major version of ES:
6969

7070
.. code-block:: bash
7171
72-
elastichq/run_tests
73-
72+
python manage.py run-tests --esv=<MAJOR_VERSION>
7473
7574
Notes
7675
~~~~~
7776

78-
* Coverage report will be appear under ``/tests/cover``.
79-
* All tests will fail without those 3 clusters running. They are the 3 major versions that HQ currently supports.
80-
* The scripts under ``/tests/scripts`` allow for starting, stopping, and listing all clusters. You will need to edit those for the tests to run.
77+
* Coverage report will be appear under ``/tests/htmlcov``.
78+
* HTML report of pytest output will appear under ``/tests/htmlout11.
8179
8280
Building Documentation
8381
----------------------

manage.py

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -95,60 +95,67 @@ class PyTest(Command):
9595
"""
9696
Runs all unittests. You MUST make sure that all clusters configured are running for the tests to pass!
9797
"""
98+
version = None
9899

99-
def run(self):
100+
def get_options(self):
101+
options = (
102+
Option('-E', '--esv',
103+
dest='version',
104+
default=self.version),
105+
106+
)
107+
return options
108+
109+
def run(self, version):
100110
import pytest
101111

102112
tests_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tests')
103113
sys.path.append(os.path.abspath(tests_path))
104114

105-
pytest.main(
106-
[
107-
tests_path,
108-
'--verbose',
109-
'--color=yes',
110-
'-c=' + tests_path + '/pytest.ini',
115+
default_test_args = [
116+
tests_path,
117+
'--ignore=node_modules',
118+
'--verbose',
119+
'--color=yes',
120+
'-c=' + tests_path + '/pytest.ini',
121+
'--docker-compose-remove-volumes',
122+
# '-s', # WARNING: Turning this on, breaks the tests on a Mac.
123+
'--cov=' + tests_path,
124+
'--cov-report=html:' + tests_path + '/htmlcov',
125+
'--self-contained-html'
126+
]
127+
128+
sig = None
129+
if version is None:
130+
hq_args = [
111131
'--docker-compose=' + tests_path + '/hq_docker-compose.yml',
112-
'--docker-compose-remove-volumes',
113-
'-m=hq_ops',
114-
'-s', # verbose logging
115-
'--cov=' + tests_path,
116-
'--cov-report=html:' + tests_path + '/htmlcov',
117132
'--html=' + tests_path + '/htmlout/hq_ops.html',
118-
'--self-contained-html'
119-
])
120-
121-
pytest.main(
122-
[
123-
tests_path,
124-
'--verbose',
125-
'--color=yes',
126-
'-c=' + tests_path + '/pytest.ini',
127-
'--docker-compose=' + tests_path + '/v2_docker-compose.yml',
128-
'--docker-compose-remove-volumes',
129-
'-m=es_versions',
130-
'-s', # verbose logging
131-
'--cov=' + tests_path,
132-
'--html=' + tests_path + '/htmlout/es_2.html',
133-
'--self-contained-html'
134-
])
135-
136-
pytest.main(
137-
[
138-
tests_path,
139-
'--verbose',
140-
'--color=yes',
141-
'-c=' + tests_path + '/pytest.ini',
142-
'--docker-compose=' + tests_path + '/v5_docker-compose.yml',
143-
'--docker-compose-remove-volumes',
144-
'-m=es_versions',
145-
'-s', # verbose logging
146-
'--cov=' + tests_path,
147-
'--html=' + tests_path + '/htmlout/es_5.html',
148-
'--self-contained-html'
149-
])
150-
151-
return None
133+
'-m=hq_ops'
134+
]
135+
sig = pytest.main(default_test_args + hq_args)
136+
137+
if version is not None:
138+
if "2" in version:
139+
v2_args = ['--docker-compose=' + tests_path + '/v2_docker-compose.yml', '-m=es_versions',
140+
'--html=' + tests_path + '/htmlout/es_2.html']
141+
sig = pytest.main(default_test_args + v2_args)
142+
143+
if "5" in version:
144+
v5_args = ['--docker-compose=' + tests_path + '/v5_docker-compose.yml', '-m=es_versions',
145+
'--html=' + tests_path + '/htmlout/es_5.html']
146+
sig = pytest.main(default_test_args + v5_args)
147+
148+
if "6" in version:
149+
v6_args = ['--docker-compose=' + tests_path + '/v6_docker-compose.yml', '-m=es_versions',
150+
'--html=' + tests_path + '/htmlout/es_6.html']
151+
sig = pytest.main(default_test_args + v6_args)
152+
153+
if "7" in version:
154+
v7_args = ['--docker-compose=' + tests_path + '/v7_docker-compose.yml', '-m=es_versions',
155+
'--html=' + tests_path + '/htmlout/es_7.html']
156+
sig = pytest.main(default_test_args + v7_args)
157+
158+
return sig
152159

153160

154161
manager.add_command("runserver", Server())

run-tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
python manage.py run-tests
4+
5+
python manage.py run-tests --esv=2
6+
7+
python manage.py run-tests --esv=5
8+
9+
python manage.py run-tests --esv=6
10+
11+
python manage.py run-tests --esv=7

run_tests.sh

Lines changed: 0 additions & 97 deletions
This file was deleted.

tests/combined/test_connections.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
__author__ = 'royrusso'
22

3-
import logging
4-
53
import pytest
64

75
pytest_plugins = ["docker_compose"]
8-
LOGGER = logging.getLogger(__name__)
96

107

118
@pytest.mark.hq_ops
12-
def test_get_clusters(session_scoped_container_getter, fixture):
9+
def test_get_clusters(fixture):
1310
fixture.clear_all_clusters()
1411

1512
response = fixture.app.get('/api/clusters')

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@pytest.fixture(scope="session", autouse=True)
2020
def wait_for_api(session_scoped_container_getter):
2121
"""Wait for the api from elasticsearch to become responsive"""
22+
LOGGER.info("Waiting on API...")
2223
request_session = requests.Session()
2324
retries = Retry(total=20,
2425
backoff_factor=0.1,
@@ -60,7 +61,7 @@ def create_indices(session_scoped_container_getter):
6061
Creates indices for testing. Applies mapping and populates with test data.
6162
:return:
6263
"""
63-
LOGGER.info("******** Creating Indices...")
64+
print("******** Creating Indices...")
6465
try:
6566
cur_path = os.path.dirname(__file__)
6667
test_data_path = os.path.join(cur_path, 'data')

tests/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<head>
3+
4+
</head>
5+
6+
<a href="htmlcov/index.html">Coverage Report</a>
7+
<hr/>
8+
<a href="htmlout/hq_ops.html">ElasticHQ Tests</a><br/>
9+
<a href="htmlout/es_2.html">Elasticsearch 2.x Tests</a><br/>
10+
<a href="htmlout/es_5.html">Elasticsearch 5.x Tests</a><br/>
11+
<a href="htmlout/es_6.html">Elasticsearch 6.x Tests</a><br/>
12+
<a href="htmlout/es_7.html">Elasticsearch 7.x Tests</a>
13+
</html>

tests/pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ markers =
33
hq_ops: HQ-specific operations. Uses Flask + ES 2.x for now.
44
es_versions: Elasticsearch version-specific operations.
55

6-
addopts = ''
6+
;addopts = ''
77

88
log_cli = 1
99
log_cli_level = INFO
1010
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
1111
log_cli_date_format=%Y-%m-%d %H:%M:%S
12+
1213
;
1314
;log_file = pytest.log
1415
;log_file_level = DEBUG

tests/scripts/kill_clusters.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)