Skip to content

Commit

Permalink
adding some attributes stuff, adding dbg helper to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetrucciani committed Jul 22, 2019
1 parent 0ccc430 commit a62a48e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=
6 changes: 5 additions & 1 deletion qoo/queues.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
queue class
qoo queue and job class
"""
import boto3
import os
Expand All @@ -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"]
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ ignore_missing_imports = True
ignore = N802,N807,W503
max-line-length = 100
max-complexity = 20

[tool:pytest]
log_print = False
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions tests/test_qoo.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a62a48e

Please sign in to comment.