diff options
author | Matus Valo <matusvalo@gmail.com> | 2019-02-15 05:10:42 -0800 |
---|---|---|
committer | Matus Valo <matusvalo@gmail.com> | 2019-02-15 05:17:30 -0800 |
commit | 984902850b51482a3302aafec66db15e06fee281 (patch) | |
tree | ba8565f6d64b544113b0b17b689fcb465a241741 | |
parent | 093cdb2e28caad08d14abf4e9ca5501082875a6f (diff) | |
download | py-amqp-CI-RMQ.tar.gz |
Added RabbitMQ integration testsCI-RMQ
-rw-r--r-- | .travis.yml | 52 | ||||
-rw-r--r-- | conftest.py | 15 | ||||
-rw-r--r-- | t/integration/test_rmq.py | 91 | ||||
-rw-r--r-- | tox.ini | 15 |
4 files changed, 142 insertions, 31 deletions
diff --git a/.travis.yml b/.travis.yml index 851a7bc..d64bf24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,25 @@ language: python -sudo: false +sudo: required +dist: xenial cache: pip +python: + - '2.7' + - '3.4' + - '3.5' + - '3.6' + - '3.7' + - 'pypy2.7-6.0' + - 'pypy3.5-6.0' + +services: + - rabbitmq env: global: PYTHONUNBUFFERED=yes + matrix: + - MATRIX_TOXENV=unit + - MATRIX_TOXENV=integration-rabbitmq stages: - lint @@ -14,27 +29,6 @@ matrix: fast_finish: true include: - python: 2.7 - env: TOXENV=2.7 - - python: pypy2.7-6.0 - env: TOXENV=pypy - dist: xenial - - python: pypy3.5-6.0 - env: TOXENV=pypy3 - dist: xenial - - python: 3.4 - env: TOXENV=3.4 - - python: 3.5 - env: TOXENV=3.5 - - python: 3.6 - env: TOXENV=3.6 - - python: 3.7 - env: TOXENV=3.7 - sudo: true - dist: xenial - - python: 2.7 - env: TOXENV=flake8 - stage: lint - - python: 3.6 env: TOXENV=flake8 stage: lint - python: 2.7 @@ -47,6 +41,20 @@ matrix: env: TOXENV=apicheck stage: lint +before_install: + # - sudo apt install libcurl4-openssl-dev libssl-dev gnutls-dev + - if [[ -v MATRIX_TOXENV ]]; then export TOXENV=${TRAVIS_PYTHON_VERSION}-${MATRIX_TOXENV}; fi; env + - | + if [[ "$TOXENV" == *integration* ]]; then + sudo echo 'deb https://dl.bintray.com/rabbitmq-erlang/debian xenial main' > /etc/apt/sources.list.d/rabbitmq-bintray.list + sudo apt-key adv --keyserver "hkps.pool.sks-keyservers.net" --recv-keys "0x6B73A36E6026DFCA" + wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | sudo apt-key add - + sudo apt update + sudo apt install rabbitmq-server -y + sudo systemctl enable rabbitmq-server + sudo systemctl start rabbitmq-server + fi + install: - pip install -U pip setuptools wheel | cat - pip install -U tox | cat diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..e48a5f0 --- /dev/null +++ b/conftest.py @@ -0,0 +1,15 @@ +import pytest +def pytest_addoption(parser): + parser.addoption("-E", action="store", metavar="NAME", + help="only run tests matching the environment NAME.") + +def pytest_configure(config): + # register an additional marker + config.addinivalue_line("markers", + "env(name): mark test to run only on named environment") + +def pytest_runtest_setup(item): + envnames = [mark.args[0] for mark in item.iter_markers(name='env')] + if envnames: + if item.config.getoption("-E") not in envnames: + pytest.skip("test requires env in %r" % envnames) diff --git a/t/integration/test_rmq.py b/t/integration/test_rmq.py new file mode 100644 index 0000000..5f8b7e8 --- /dev/null +++ b/t/integration/test_rmq.py @@ -0,0 +1,91 @@ +from __future__ import absolute_import, unicode_literals + +from case import Mock, ANY +import pytest +import amqp + + +@pytest.mark.env('rabbitmq') +def test_connect(): + connection = amqp.Connection() + connection.connect() + connection.close() + + +@pytest.mark.env('rabbitmq') +class test_rabbitmq_operations(): + + @pytest.fixture(autouse=True) + def setup_conn(self): + self.connection = amqp.Connection() + self.connection.connect() + self.channel = self.connection.channel() + yield + self.connection.close() + + @pytest.mark.parametrize( + "publish_method", ('basic_publish', 'basic_publish_confirm') + ) + def test_publish_consume(self, publish_method): + callback = Mock() + self.channel.queue_declare( + queue='py-amqp-unittest', durable=False, exclusive=True + ) + getattr(self.channel, publish_method)( + amqp.Message('Unittest'), routing_key='py-amqp-unittest' + ) + self.channel.basic_consume( + queue='py-amqp-unittest', + callback=callback, + consumer_tag='amq.ctag-PCmzXGkhCw_v0Zq7jXyvkg' + ) + self.connection.drain_events() + callback.assert_called_once_with(ANY) + msg = callback.call_args[0][0] + assert isinstance(msg, amqp.Message) + assert msg.body_size == len('Unittest') + assert msg.body == 'Unittest' + assert msg.frame_method == amqp.spec.Basic.Deliver + assert msg.delivery_tag == 1 + assert msg.ready is True + assert msg.delivery_info == { + 'consumer_tag': 'amq.ctag-PCmzXGkhCw_v0Zq7jXyvkg', + 'delivery_tag': 1, + 'redelivered': False, + 'exchange': '', + 'routing_key': 'py-amqp-unittest' + } + assert msg.properties == {'content_encoding': 'utf-8'} + + self.channel.basic_ack(msg.delivery_tag) + + def test_publish_get(self): + self.channel.queue_declare( + queue='py-amqp-unittest', durable=False, exclusive=True + ) + self.channel.basic_publish( + amqp.Message('Unittest'), routing_key='py-amqp-unittest' + ) + msg = self.channel.basic_get( + queue='py-amqp-unittest', + ) + assert msg.body_size == 8 + assert msg.body == 'Unittest' + assert msg.frame_method == amqp.spec.Basic.GetOk + assert msg.delivery_tag == 1 + assert msg.ready is True + assert msg.delivery_info == { + 'delivery_tag': 1, 'redelivered': False, + 'exchange': '', + 'routing_key': 'py-amqp-unittest', 'message_count': 0 + } + assert msg.properties == { + 'content_encoding': 'utf-8' + } + + self.channel.basic_ack(msg.delivery_tag) + + msg = self.channel.basic_get( + queue='py-amqp-unittest', + ) + assert msg is None @@ -1,12 +1,7 @@ [tox] envlist = - 2.7 - pypy - pypy3 - 3.4 - 3.5 - 3.6 - 3.7 + {2.7,pypy2.7-6.0,pypy3.5-6.0,3.4,3.5,3.6,3.7}-unit + {2.7,pypy2.7-6.0,pypy3.5-6.0,3.4,3.5,3.6,3.7}-integration-rabbitmq flake8 flakeplus apicheck @@ -22,11 +17,13 @@ deps= flake8,flakeplus,pydocstyle: -r{toxinidir}/requirements/pkgutils.txt sitepackages = False recreate = False -commands = py.test -xv --cov=amqp --cov-report=xml --no-cov-on-fail +commands = + unit: py.test -xv --cov=amqp --cov-report=xml --no-cov-on-fail t/unit + integration: py.test -xv -E rabbitmq t/integration basepython = 2.7,flakeplus,flake8,apicheck,linkcheck,pydocstyle: python2.7 - pypy,pypy3: pypy + pypy2.7-6.0,pypy3.5-6.0: pypy 3.4: python3.4 3.5: python3.5 3.6: python3.6 |