Skip to content

Commit

Permalink
Merge pull request #291 from NikolayBaranovv/feat_add_docker_tests
Browse files Browse the repository at this point in the history
Feat: add docker tests
  • Loading branch information
psi29a authored Oct 1, 2024
2 parents 3e2c57c + 77b8c86 commit 7b5795d
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 262 deletions.
49 changes: 25 additions & 24 deletions .github/workflows/txmongo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,47 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
mongodb-version: ['4.2', '4.4']
python-version: ['3.8', '3.11', '3.12']
mongodb-version: ['3.6', '4.2', '4.4']
steps:
- uses: actions/checkout@v3
- name: Start MongoDB (27017)
uses: supercharge/mongodb-github-action@1.8.0
- uses: actions/checkout@v4
- name: Start MongoDB on port 27017
uses: supercharge/mongodb-github-action@1.11.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Setup Python
uses: actions/setup-python@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install tox and any other packages
python-version: ${{ matrix.python-version }}
- name: Install tox
run: pip install tox
- name: Run tox
run: tox -e basic
- name: Run basic tests in tox
run: tox -f py${{ matrix.python-version }} basic
- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
name: code-coverage-report-${{ matrix.mongodb-version }}-${{ matrix.python-version }}
path: htmlcov

advanced:
runs-on: ubuntu-20.04
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
python-version: ['3.8', '3.11', '3.12']
mongodb-version: ['4.2', '4.4']
steps:
- uses: actions/checkout@v3
- name: Install MongoDB 4.4
- uses: actions/checkout@v4
- name: Install MongoDB ${{ matrix.mongodb-version }}
run: |
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
wget -qO - https://www.mongodb.org/static/pgp/server-${{ matrix.mongodb-version }}.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/${{ matrix.mongodb-version }} multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-${{ matrix.mongodb-version }}.list
sudo apt-get update
sudo apt-get install -y --allow-downgrades mongodb-org-server=4.4.18
- name: Setup Python
uses: actions/setup-python@v4
sudo apt-get install -y --allow-downgrades mongodb-org-server
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
python-version: ${{ matrix.python-version }}
- name: Install tox and any other packages
run: pip install tox
- name: Run tox
run: tox -e advanced
- name: Run advanced tests in tox
run: tox -f py${{ matrix.python-version }} advanced
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ build
.download_cache
.coverage
venv/
venv*/
docs/build/
_trial_temp/
_trial_temp_*
txmongo.egg-info
.idea/
dist/
htmlcov/
.tox/
data/mongo
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ language: python
python:
- "3.5"
- "3.8"
- "3.11"
- "pypy3"


env:
- TOX_ENV=tw189
- TOX_ENV=tw1910
- TOX_ENV=tw203
- TOX_ENV=tw217
- TOX_ENV=tw2210
- TOX_ENV=tw2310
- TOX_ENV=twlatest
- TOX_ENV=twtrunk
- TOX_ENV=pymongo_313
- TOX_ENV=pymongo_470
- TOX_ENV=pymongo_latest


matrix:
Expand Down
43 changes: 43 additions & 0 deletions bin/run_tests_with_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
import argparse
import os
from subprocess import run

parser = argparse.ArgumentParser(description='Run tests with dockerized MongoDB')
parser.add_argument('--mongodb-version', type=str, help='MongoDB version', required=True)
# for test_basic
parser.add_argument('--mongodb-port', type=str, help='MongoDB Port (default 27017)', default='27017')
# for test_auth
parser.add_argument('--mongodb-port-auth', type=str, help='MongoDB Port (default 27018)', default='27018')
# for test_replicaset
parser.add_argument('--mongodb-port-1', type=str, help='MongoDB 1 Replica Port (default 37017)', default='37017')
parser.add_argument('--mongodb-port-2', type=str, help='MongoDB 2 Replica Port (default 37018)', default='37018')
parser.add_argument('--mongodb-port-3', type=str, help='MongoDB 3 Replica Port (default 37019)', default='37019')

args, tox_args = parser.parse_known_args()

mongodb_network_name = 'txmongo-tests-advanced-network'
run(['docker', 'network', 'create', mongodb_network_name])

mongodb_basic_test_container_name = 'txmongo-tests-basic-mongodb'

run(['docker', 'run', '--rm', '-d', '-p', f'{args.mongodb_port}:27017', '--name', mongodb_basic_test_container_name, f'mongo:{args.mongodb_version}'])

run(['tox', *tox_args], env={
**os.environ,
'TXMONGO_RUN_MONGOD_IN_DOCKER': 'yes',
'TXMONGO_MONGOD_DOCKER_VERSION': args.mongodb_version,
'TXMONGO_MONGOD_DOCKER_PORT_AUTH': args.mongodb_port_auth,
'TXMONGO_MONGOD_DOCKER_PORT_1': args.mongodb_port_1,
'TXMONGO_MONGOD_DOCKER_PORT_2': args.mongodb_port_2,
'TXMONGO_MONGOD_DOCKER_PORT_3': args.mongodb_port_3,
'TXMONGO_MONGOD_DOCKER_NETWORK_NAME': mongodb_network_name,
})
run(['docker', 'stop', mongodb_basic_test_container_name])

run(['docker', 'network', 'rm', "--force", mongodb_network_name])

# if need manually delete containers:
# docker container rm --force $(docker ps -q --filter "name=txmongo-tests-")
# run some version:
# ./bin/run_tests_with_docker.py --mongodb-version 4.4 -f advanced py3.11 pymongo480 tw247
12 changes: 10 additions & 2 deletions docs/source/NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Changelog
=========

Release 24.0.0 (2024-09-18)
Release 24.0.0 (2024-09-16)
---------------------------

API Changes
^^^^^^^^^^^
^^^^^^^^

- This is the last release that supports Python <3.8 and MongoDB <4.0


Release UPCOMING (yyyy-mm-dd)
-----------------------------

API Changes
^^^^^^^^^^^

- PyMongo 4+ is now supported. If you will migrate from PyMongo 3 to PyMongo 4, please be sure
to check their PyMongo's guide because newer version has a number of incompatible changes.

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Twisted
Twisted~=24.7.0
pymongo>=3.0,<4.9
setuptools~=71.1.0
-e .
Loading

0 comments on commit 7b5795d

Please sign in to comment.