cement.ext.ext_dummy

The Dummy Extension provides several ‘placeholder’ type handlers to either mock operations or provide local-only usage during development. A perfect example is the DummyMailHandler that can be use during development or staging to prevent real email messages from being sent externally.

Requirements

  • No external dependencies

Configuration

  • See each handler’s documentation regarding what configurations they support.

Usage

from cement.core.foundation import CementApp

class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        extensions = ['dummy']
        output_handler = 'dummy'
        mail_handler = 'dummy'

with MyApp() as app:
    app.run()
class cement.ext.ext_dummy.DummyMailHandler(*args, **kw)

Bases: cement.core.mail.CementMailHandler

This class implements the cement.core.mail.IMail interface, but is intended for use in development as no email is actually sent.

Usage

class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        mail_handler = 'dummy'

with MyApp() as app:
    app.run()

    app.mail.send('This is my fake message',
        subject='This is my subject',
        to=['john@example.com', 'rita@example.com'],
        from_addr='me@example.com',
        )

The above will print the following to console:

======================================================================
DUMMY MAIL MESSAGE
----------------------------------------------------------------------

To: john@example.com, rita@example.com
From: me@example.com
CC:
BCC:
Subject: This is my subject

---

This is my fake message

----------------------------------------------------------------------

Configuration

This handler supports the following configuration settings:

  • to - Default to addresses (list, or comma separated depending on the ConfigHandler in use)
  • from_addr - Default from_addr address
  • cc - Default cc addresses (list, or comma separated depending on the ConfigHandler in use)
  • bcc - Default bcc addresses (list, or comma separated depending on the ConfigHandler in use)
  • subject - Default subject
  • subject_prefix - Additional string to prepend to the subject

You can add these to any application configuration file under a [mail.dummy] section, for example:

~/.myapp.conf

[myapp]

# set the mail handler to use
mail_handler = dummy


[mail.dummy]

# default to addresses (comma separated list)
to = me@example.com

# default from address
from = someone_else@example.com

# default cc addresses (comma separated list)
cc = jane@example.com, rita@example.com

# default bcc addresses (comma separated list)
bcc = blackhole@example.com, someone_else@example.com

# default subject
subject = This is The Default Subject

# additional prefix to prepend to the subject
subject_prefix = MY PREFIX >
class Meta

Bases: object

Handler meta-data.

label = 'dummy'

Unique identifier for this handler

DummyMailHandler.send(body, **kw)

Mimic sending an email message, but really just print what would be sent to console. Keyword arguments override configuration defaults (cc, bcc, etc).

Parameters:
  • body (multiline string) – The message body to send
  • to (list) – List of recipients (generally email addresses)
  • from_addr (str) – Address (generally email) of the sender
  • cc (list) – List of CC Recipients
  • bcc (list) – List of BCC Recipients
  • subject (str) – Message subject line
Returns:

Boolean (True if message is sent successfully, False otherwise)

Usage

# Using all configuration defaults
app.mail.send('This is my message body')

# Overriding configuration defaults
app.mail.send('My message body'
    to=['john@example.com'],
    from_addr='me@example.com',
    cc=['jane@example.com', 'rita@example.com'],
    subject='This is my subject',
    )
class cement.ext.ext_dummy.DummyOutputHandler(*args, **kw)

Bases: cement.core.output.CementOutputHandler

This class is an internal implementation of the cement.core.output.IOutput interface. It does not take any parameters on initialization, and does not actually output anything.

class Meta

Bases: object

Handler meta-data

interface

The interface this class implements.

alias of IOutput

label = 'dummy'

The string identifier of this handler.

overridable = False

Whether or not to include dummy as an available to choice to override the output_handler via command line options.

DummyOutputHandler.render(data_dict, template=None, **kw)

This implementation does not actually render anything to output, but rather logs it to the debug facility.

Parameters:
  • data_dict – The data dictionary to render.
  • template – The template parameter is not used by this implementation at all.
Returns:

None