Skip to content

Commit

Permalink
Change tests from bespoke to the pytest framework (#8)
Browse files Browse the repository at this point in the history
This patch removes our previous custom tests, and introduces the
pytest framework as a replacement All functional tests were converted
over, and a variety of unit tests were created. This is not meant to be
a complete solution, but a starting point where additional tests can be
created.
  • Loading branch information
pcmxgti authored Oct 23, 2019
1 parent 90def93 commit 0e4a5e4
Show file tree
Hide file tree
Showing 11 changed files with 407 additions and 194 deletions.
12 changes: 5 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ jobs:
<<: *tox_shared_config
docker:
- image: circleci/python:3.7
functional:

py38:
<<: *tox_shared_config
docker:
- image: circleci/python:3.7
- image: circleci/python:3.8

workflows:
version: 2
Expand All @@ -70,9 +71,6 @@ workflows:
- py37:
requires:
- lint
- functional:
- py38:
requires:
- py27
- py35
- py36
- py37
- lint
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Generate temporary AWS credentials via Okta.
.. image:: https://circleci.com/gh/dowjones/tokendito/tree/master.svg?style=svg
:target: https://circleci.com/gh/dowjones/tokendito/tree/master

.. image:: https://img.shields.io/badge/python-2.7%2C%203.5%2C%203.6%2C%203.7-blueviolet
.. image:: https://img.shields.io/badge/python-2.7%2C%203.5%2C%203.6%2C%203.7%2C%203.8-blueviolet
:target: https://pypi.org/project/tokendito/

.. image:: https://img.shields.io/badge/license-Apache%202.0-ff69b4
Expand Down
2 changes: 1 addition & 1 deletion docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Or you can put your parameters into a single `profile <okta_auth.example>`_ in `
okta_aws_app_url = https://acme.oktapreview.com/home/amazon_aws/b07384d113edec49eaa6/123
okta_username = [email protected]
mfa_method = push
role-arn = arn:aws:iam::123456789000:role/dowjones-hammer-engineer
role_arn = arn:aws:iam::123456789000:role/dowjones-hammer-engineer
And execute:
Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ pexpect>=4.6.0
pylint>=1.8.4
pydocstyle==3.0.0
pyroma
pytest
pytest-ordering
semver
tox
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ configparser>=3.5.0
future>=0.16.0
pyOpenSSL>=18.0.0
beautifulsoup4>=4.6.0
lxml>=4.3.0
lxml>=4.3.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
'License :: OSI Approved :: Apache Software License',
'Development Status :: 5 - Production/Stable',
'Operating System :: OS Independent',
'Natural Language :: English',
'Environment :: Console',
'Programming Language :: Python',
'Intended Audience :: End Users/Desktop',
Expand All @@ -47,6 +46,7 @@
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords=['okta', 'aws', 'sts'],
packages=find_packages(exclude=['contrib', 'docs', 'tests', '.tox']),
Expand Down
50 changes: 50 additions & 0 deletions tests/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
=======
Testing
=======

To run basic tests, execute:

``py.test -v -rA -k 'not tests/functional' -s tests``. This will skip functional (end to end)
testing.

To run end to end tests, use ``py.test -v -rA -k 'tests/functional' -s tests`` instead. Several
other arguments can be provided so that the tool can run in non-interactive mode. Currently,
config file, arguments, and environment variables (mix and match) are supported. The syntax is
the same as for ``tokendito``.

If all of username, password, mfa method, app url, and role ARN are passed to ``py.test``, then
two other tests are kicked off. The first will execute ``tokendito`` and try to obtain STS
tokens the same way that a normal user would. The second will run ``sts get-caller-identity``
and validate the credentials.

Example 1
----------
.. code-block:: sh
py.test -v -rA -s tests --config-file=/tmp/my-tokendito-config.ini
Where the config file has valid configuration items for the tool.

Example 2
---------

.. code-block:: sh
py.test -v -rA -k 'tests/functional' -s tests \
--username=jane.doe \
--password=mysecretpass \
--mfa-method=push \
--okta-aws-app-url='https://acme.oktapreview.com/home/amazon_aws/b07384d113edec49eaa6/123' \
--role-arn=arn:aws:iam::123456789000:role/dowjones-hammer-engineer
This triggers the tests ``test_generate_credentials`` and ``test_aws_credentials`` that are
normally skipped.

Example 3
---------

.. code-block:: sh
MFA_METHOD=push py.test -v -rA -k 'tests/functional' -s tests --username=...
This shows how to mix environment variables with ``py.test`` and arguments.
30 changes: 30 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# vim: set filetype=python ts=4 sw=4
# -*- coding: utf-8 -*-
"""pytest configuration, hooks, and global fixtures."""
from __future__ import (absolute_import, division,
print_function, unicode_literals)

from future import standard_library

standard_library.install_aliases()


def pytest_addoption(parser):
"""Add command-line option for running functional tests."""
parser.addoption("--run-functional", action="store_true",
default=False, help="run functional tests")
parser.addoption('--username',
help='username to login to Okta')
parser.addoption('--password',
help='password to login to Okta.')
parser.addoption('--okta-aws-app-url',
help='Okta App URL to use.')
parser.addoption('--mfa-method',
help='Sets the MFA method')
parser.addoption('--mfa-response',
help='Sets the MFA response to a challenge')
parser.addoption('--role-arn',
help='Sets the IAM role')
parser.addoption('--config-file',
default='/dev/null',
help='Sets an optional config file to read from')
Loading

0 comments on commit 0e4a5e4

Please sign in to comment.