From a62a48e276e1dcf85e0ba7e40d9086ce7f5a0c85 Mon Sep 17 00:00:00 2001 From: Jacobi Petrucciani Date: Mon, 22 Jul 2019 13:29:51 -0400 Subject: [PATCH] adding some attributes stuff, adding dbg helper to tests --- .travis.yml | 2 ++ qoo/queues.py | 6 +++++- setup.cfg | 3 +++ tests/conftest.py | 2 +- tests/test_qoo.py | 21 ++++++++++++++++++--- tox.ini | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7aa9cd1..4c1aed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,3 +22,5 @@ deploy: on: branch: master tags: true + password: + secure: cmGJerE74ddOd3WXFgOvb2hhFG8ohmkszuzEUoV4c65O1V0UkTIgul0xnRmKamyZbhx0py63yKo9fRyiPOmKOksp444MCMlJ/LaS1wfgfWEXjNRD0pxGfG6Do+NM+L25yEPv7VANTPpPXMEXy0dwf1DYv9EwLh/7p8mbsGhxM24vgxCLt30NFuOofnuYWg+fp3T5RExXInDDDf393932AV792bFJxv8XpUceThytzfgQh2pum43ZKemWRDk8tpAE9Qq0BL/KyNDkf83aV/ZxAomH+jT3EN1QMS1QdNKGVMx7kbXVn6nEzOG5/7h1EzGVcj08xrhLxZtUv/dD6IwX8LrE95egP9xT2JjUS2DKiS8nIW+Rmf0yPNtl+FjUjwqm5BNOzDye0czCLQiVuC1BPvhStw4QxPvbLFcZ0dEKCZPhX6F8vxoLa2belRgqr1FKFMyZVYuYJmGZru4/G4T8Pp3dClflK/TrYdLBA+Jtuwo8R3p3zy7VWwkPNfk+Xo2H9LRO5y7X9bToichTDmIfhOhxtNVhPyElyRdnIAmdYwLQS18FlrddtzCeNgrc8grN8R0rPBthI2d+z6K+IFMghka4NgFqGxUYUp6ZAwzWXcgqN+IUeS17XIM1z7wrMzg33njLiLUSWoZ8CN2czXKXefFcdd07n/dCk5yBFaV3Eb8= diff --git a/qoo/queues.py b/qoo/queues.py index bcc5bc8..f9445f0 100644 --- a/qoo/queues.py +++ b/qoo/queues.py @@ -1,5 +1,5 @@ """ -queue class +qoo queue and job class """ import boto3 import os @@ -19,8 +19,12 @@ def __init__(self, sqs_message: dict, queue: "Queue") -> None: self._md5 = self._data["MD5OfBody"] self._id = self._data["MessageId"] self._body = jsonl(self._data["Body"]) + self._attributes = self._data["Attributes"] self._received_at = float(time.time()) self.elapsed = time.time() - self._body["created_at"] + self.approximate_receive_count = int( + self._attributes["ApproximateReceiveCount"] + ) for key in self._body: setattr(self, key, self._body[key]) self.handle = self._data["ReceiptHandle"] diff --git a/setup.cfg b/setup.cfg index 885b668..33a183c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,3 +7,6 @@ ignore_missing_imports = True ignore = N802,N807,W503 max-line-length = 100 max-complexity = 20 + +[tool:pytest] +log_print = False diff --git a/tests/conftest.py b/tests/conftest.py index 74d3474..80fc31f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,7 +31,7 @@ def queue() -> Generator: def fifo_queue() -> Generator: """fixture that provides a fifo SQS qoo.""" with mock_sqs(): - yield qoo.create("qoo-fifo", fifo=True) + yield qoo.create("qoo.fifo", fifo=True) @pytest.fixture diff --git a/tests/test_qoo.py b/tests/test_qoo.py index 7bd6f28..8ad180d 100644 --- a/tests/test_qoo.py +++ b/tests/test_qoo.py @@ -1,13 +1,27 @@ """ pytest the qoo functionality """ +import json import os -import qoo import pytest +import qoo +import sys import time from moto import mock_sqs +def dbg(text): + """debug printer for tests""" + if isinstance(text, dict): + text = json.dumps(text, sort_keys=True, indent=2) + caller = sys._getframe(1) + print("") + print("----- {} line {} ------".format(caller.f_code.co_name, caller.f_lineno)) + print(text) + print("-----") + print("") + + def test_login(): """ Ensure that login sets the correct environment variables. @@ -32,8 +46,8 @@ def test_queues_can_be_created(): @mock_sqs def test_fifo_queues_can_be_created(): """test that we can create a queue""" - queue = qoo.create("test_queue", fifo=True) - assert queue.name == "test_queue" + queue = qoo.create("test_queue.fifo", fifo=True) + assert queue.name == "test_queue.fifo" assert queue.created_at < time.time() assert queue.maximum_message_size == 262144 assert queue.fifo @@ -60,6 +74,7 @@ def test_can_send_and_receive_job(queue): job = queue.receive() assert job assert job.md5_matches + assert job.approximate_receive_count == 1 def test_can_delete_job(queue_with_job): diff --git a/tox.ini b/tox.ini index 1f2d333..8ea6e44 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py{35,36,37} [testenv] commands = - pytest --cov qoo --cov-report term [] + pytest -s --cov qoo --cov-report term [] deps = pytest pytest-cov