Skip to main content

A testsupport utility module for python

Project description

quiltz-testsupport

A package for test support

Purpose

At QWAN we're building some applications in python. We collect usefull stuff in quiltz packages:

  • quiltz-domain contains domain level modules like, entity id's, results, an email anonymizer, validators and parsers
  • quiltz-testsupport (this package) contains test support modules, that supports mainly non unit tests, like integrating with smtp, probing asynchronous results and asserting log statements
  • quiltz-messaging contains a messaging domain concept and an engines to send the messages. Currently only smtp sending is supported.

modules in this packag

logging

With the logging module you can assert log statements in a test using the log_collector fixture:

in test:

from quiltz.testsupport import log_collector
def test_logs_hello(log_collector):
    foo()
    log_collector.assert_info('hello info')

in production

def foo():
    logger = logging.getLogger()
    logger.info('hello info')

probing

With the probing module you can probe for async results:

from hamcrest import assert_that, equal_to
from quiltz.testsupport import probe_that

def test_stub_server_collects_message_for_recepient(self):        
    message = aMessage(recipient='rob@mailinator.com', sender='no-reply@qwan.eu', subject='test', body='hello test')
    self.message_engine.send([message])

    probe_that(lambda: self.server.messages == [stringified_message(message)])
    # or
    probe_that(lambda: assert_that(self.server.messages, equal_to([
        stringified_message(message)
    ])))
    # or
    probe_that(lambda: self.server.messages, equal_to([
        stringified_message(message)
    ]))

smtp

With the smtp module you can create a stub smtp server that collects smtp messages

from hamcrest import assert_that, equal_to
from quiltz.testsupport import probe_that
def server()
    server = StubSmtpServer(hostname='localhost', port=9925)
    server.start()
    yield(server)
    server.stop()

def test_collects_message_for_recepient(self, server): 
    message_engine = SMTPClientForTest(host='localhost', port='9925')
    message = aMessage(recipient='rob@mailinator.com', sender='no-reply@qwan.eu', subject='test', body='hello test')
    message_engine.send([message])

    probe_that(lambda: assert_that(server.messages, equal_to([
        stringified_message(message)
    ])))

installing

pip install quiltz-testsupport

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quiltz_testsupport-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quiltz_testsupport-0.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file quiltz_testsupport-0.2.0.tar.gz.

File metadata

  • Download URL: quiltz_testsupport-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for quiltz_testsupport-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9bfed7cbf53867b1f969af24734e6c05ccd2ba73544bb60d0c3d3bee91b9ddc1
MD5 ff6c6c5c494651a234f13f78befb21e3
BLAKE2b-256 a7a2be8779f3f71410a79b7caac82075ec426ce4be284ed4f120b248cb43a3bb

See more details on using hashes here.

File details

Details for the file quiltz_testsupport-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: quiltz_testsupport-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for quiltz_testsupport-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bc4900041e6c9a63ed6867cf4e2eb1fb8063c3011c136245dec6243d80440e9
MD5 1455cf3f952e989f1e1e3b08c9a2de45
BLAKE2b-256 3ba3b7ef493e89b8eba9d470069fe635100395b6b35fe8a153e293c7dee48741

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page