Skip to content

Commit

Permalink
Minor enhancements.
Browse files Browse the repository at this point in the history
- Adjust documentation
- Add Python 3.x support both source and supporting files
- Adjust test cases
- Add virtualenv support
  • Loading branch information
rickypc committed Jan 19, 2016
1 parent 98ce005 commit 7a03064
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 103 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.2.2 (2016.01.19)
==================

* Adjust documentation
* Add Python 3.x support

0.2.1 (2015.12.20)
==================

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install_devel_deps:
pip install coverage mock

lint:clean
flake8 --max-complexity 10
flake8 --max-complexity 10 src/$(LIBRARY_NAME)/*.py
pylint --rcfile=setup.cfg src/$(LIBRARY_NAME)/*.py

test:clean
Expand Down
97 changes: 41 additions & 56 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,35 @@ I will try to accomodate as much as I could as time permit. **There is no need t

If you are interested to contribute back to this project, please see **Contributing** section.

Example
'''''''

+----------------+----------------------+---------------------------+-----------------+
| Open Mailbox | host=imap.domain.com | [email protected] | password=secret |
+----------------+----------------------+---------------------------+-----------------+
| ${LATEST} = | Wait For Email | [email protected] | timeout=300 |
+----------------+----------------------+---------------------------+-----------------+
| ${HTML} = | Open Link From Email | ${LATEST} |
+----------------+----------------------+---------------------------------------------+
| Should Contain | ${HTML} | Your email address has been updated |
+----------------+----------------------+---------------------------------------------+
| Close Mailbox |
+-------------------------------------------------------------------------------------+

Multipart Email Example
'''''''''''''''''''''''

+----------------+----------------------+---------------------------+-----------------+
| Open Mailbox | host=imap.domain.com | [email protected] | password=secret |
+----------------+----------------------+---------------------------+-----------------+
| ${LATEST} = | Wait For Email | [email protected] | timeout=300 |
+----------------+----------------------+---------------------------+-----------------+
| ${parts} = | Walk Multipart Email | ${LATEST} |
+----------------+----------------------+---------------------------+-----------------+
| :FOR | ${i} | IN RANGE | ${parts} |
+----------------+----------------------+---------------------------+-----------------+
| \\ | Walk Multipart Email | ${LATEST} |
+----------------+----------------------+---------------------------------------------+
| \\ | ${content-type} = | Get Multipart Content Type |
+----------------+----------------------+---------------------------------------------+
| \\ | Continue For Loop If | '${content-type}' != 'text/html' |
+----------------+----------------------+---------------------------+-----------------+
| \\ | ${payload} = | Get Multipart Payload | decode=True |
+----------------+----------------------+---------------------------+-----------------+
| \\ | Should Contain | ${payload} | your email |
+----------------+----------------------+---------------------------+-----------------+
| \\ | ${HTML} = | Open Link From Email | ${LATEST} |
+----------------+----------------------+---------------------------+-----------------+
| \\ | Should Contain | ${HTML} | Your email |
+----------------+----------------------+---------------------------+-----------------+
| Close Mailbox |
+-------------------------------------------------------------------------------------+
Examples
''''''''

.. code:: robotframework
*** Settings ***
Library ImapLibrary
*** Test Cases ***
Email Verification
Open Mailbox host=imap.domain.com [email protected] password=secret
${LATEST} = Wait For Email [email protected] timeout=300
${HTML} = Open Link From Email ${LATEST}
Should Contain ${HTML} Your email address has been updated
Close Mailbox
Multipart Email Verification
Open Mailbox host=imap.domain.com [email protected] password=secret
${LATEST} = Wait For Email [email protected] timeout=300
${parts} = Walk Multipart Email ${LATEST}
:FOR ${i} IN RANGE ${parts}
\\ Walk Multipart Email ${LATEST}
\\ ${content-type} = Get Multipart Content Type
\\ Continue For Loop If '${content-type}' != 'text/html'
\\ ${payload} = Get Multipart Payload decode=True
\\ Should Contain ${payload} your email
\\ ${HTML} = Open Link From Email ${LATEST}
\\ Should Contain ${HTML} Your email
Close Mailbox
Installation
------------
Expand All @@ -75,15 +61,15 @@ Using ``pip``

The recommended installation method is using pip_:

.. code:: bash
.. code:: console
pip install robotframework-imaplibrary
The main benefit of using ``pip`` is that it automatically installs all
dependencies needed by the library. Other nice features are easy upgrading
and support for un-installation:

.. code:: bash
.. code:: console
pip install --upgrade robotframework-imaplibrary
pip uninstall robotframework-imaplibrary
Expand All @@ -92,7 +78,7 @@ Notice that using ``--upgrade`` above updates both the library and all
its dependencies to the latest version. If you want, you can also install
a specific version:

.. code:: bash
.. code:: console
pip install robotframework-imaplibrary==x.x.x
Expand Down Expand Up @@ -128,23 +114,23 @@ and its dependencies yourself.

- Find each public key used to sign the package:

.. code:: bash
.. code:: console
gpg --keyserver pgp.mit.edu --search-keys D1406DE7
- Select the number from the list to import the public key

- Verify the package against its PGP signature:

.. code:: bash
.. code:: console
gpg --verify robotframework-imaplibrary-x.x.x.tar.gz.asc robotframework-imaplibrary-x.x.x.tar.gz
- Extract each source distribution to a temporary location.

- Go to each created directory from the command line and install each project using:

.. code:: bash
.. code:: console
python setup.py install
Expand Down Expand Up @@ -174,11 +160,10 @@ Usage
To write tests with Robot Framework and ImapLibrary,
ImapLibrary must be imported into your Robot test suite.

+-----------------------+
| *** Settings *** |
+---------+-------------+
| Library | ImapLibrary |
+---------+-------------+
.. code:: robotframework
*** Settings ***
Library ImapLibrary
See `Robot Framework User Guide`_ for more information.

Expand All @@ -190,7 +175,7 @@ Building Keyword Documentation

The `Keyword Documentation`_ can be found online, if you need to generate the keyword documentation, run:

.. code:: bash
.. code:: console
make doc
Expand All @@ -199,7 +184,7 @@ Run Unit Tests, and Test Coverage Report

Test the testing library, talking about dogfooding, let's run:

.. code:: bash
.. code:: console
make test
Expand Down
1 change: 0 additions & 1 deletion analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
IMAP Library - a IMAP email testing library.
"""

from __future__ import print_function
from os.path import split
from re import sub
import sys
Expand Down
4 changes: 2 additions & 2 deletions doc/ImapLibrary.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ disable=locally-disabled
[sdist]
formats=gztar,zip

[TYPECHECK]
ignored-modules=urllib2

[wheel]
universal=1
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

LIBRARY_NAME = 'ImapLibrary'
CWD = abspath(dirname(__file__))
execfile(join(CWD, 'src', LIBRARY_NAME, 'version.py'))
VERSION_PATH = join(CWD, 'src', LIBRARY_NAME, 'version.py')
exec(compile(open(VERSION_PATH).read(), VERSION_PATH, 'exec'))

with codecs.open(join(CWD, 'README.rst'), encoding='utf-8') as reader:
LONG_DESCRIPTION = reader.read()
Expand All @@ -47,10 +48,11 @@
'Topic :: Software Development :: Testing',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
],
keywords='robot framework testing automation imap email mail softwaretesting',
platforms='any',
packages=find_packages('src'),
package_dir={'': 'src'},
install_requires=['robotframework >= 2.6.0']
install_requires=['future', 'robotframework >= 2.6.0']
)
16 changes: 10 additions & 6 deletions src/ImapLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
IMAP Library - a IMAP email testing library.
"""

from email import message_from_string
from imaplib import IMAP4, IMAP4_SSL
from ImapLibrary.version import get_version
from re import findall
from time import sleep, time
import email
import urllib2
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from builtins import str as ustr
from ImapLibrary.version import get_version

__version__ = get_version()

Expand Down Expand Up @@ -239,11 +243,11 @@ def open_link_from_email(self, email_index, link_index=0):
urls = self.get_links_from_email(email_index)

if len(urls) > link_index:
resp = urllib2.urlopen(urls[link_index])
resp = urlopen(urls[link_index])
content_type = resp.headers.getheader('content-type')
if content_type:
enc = content_type.split('charset=')[-1]
return unicode(resp.read(), enc)
return ustr(resp.read(), enc)
else:
return resp.read()
else:
Expand Down Expand Up @@ -328,7 +332,7 @@ def walk_multipart_email(self, email_index):
"""
if not self._is_walking_multipart(email_index):
data = self._imap.fetch(email_index, '(RFC822)')[1][0][1]
msg = email.message_from_string(data)
msg = message_from_string(data)
self._start_multipart_walk(email_index, msg)
try:
self._part = next(self._mp_iter)
Expand Down
2 changes: 1 addition & 1 deletion src/ImapLibrary/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
IMAP Library - a IMAP email testing library.
"""

VERSION = '0.2.1'
VERSION = '0.2.2'


def get_version():
Expand Down
Loading

0 comments on commit 7a03064

Please sign in to comment.