-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change tests from bespoke to the pytest framework (#8)
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
Showing
11 changed files
with
407 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,7 @@ pexpect>=4.6.0 | |
pylint>=1.8.4 | ||
pydocstyle==3.0.0 | ||
pyroma | ||
pytest | ||
pytest-ordering | ||
semver | ||
tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Oops, something went wrong.