Last active
July 17, 2020 21:47
-
-
Save StephenWeber/e931b51788826964fc604a52ef66a85f to your computer and use it in GitHub Desktop.
Example test file demonstrating stackstorm-vault ca_cert logic, expected to be placed in ${PROJECT_BASE}/actions/lib/ next to actions.py
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
#!/bin/bash | |
# to run this test, copy the test_action.py file to ${PROJECT_ROOT}/actions/lib/test_action.py and then: | |
python3 -m venv venv | |
source venv/bin/activate | |
pip install -r requirements.txt | |
pip install 'git+https://github.com/StackStorm/st2.git@v3.2.0#egg=st2common&subdirectory=st2common' | |
pip install pytest | |
# finally run the test: | |
pytest |
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
from .action import VaultBaseAction | |
class MockAction(VaultBaseAction): | |
def __init__(self, config): | |
super(MockAction, self).__init__(config) | |
self.run_call_count = 0 | |
def run(self): | |
self.run_call_count += 1 | |
def test_get_verify_false(): | |
config = { | |
"url": "", | |
"cert": "/path/to/pem", | |
"token": "", | |
"verify": False, | |
} | |
action = MockAction(config) | |
actual = action._get_verify() | |
expected = False | |
assert expected == actual | |
def test_get_verify_true_no_cert(): | |
config = { | |
"url": "", | |
"cert": "", | |
"token": "", | |
"verify": True, | |
} | |
action = MockAction(config) | |
actual = action._get_verify() | |
expected = True | |
assert expected == actual | |
def test_get_verify_true_with_cert(): | |
config = { | |
"url": "", | |
"cert": "/path/to/pem", | |
"token": "", | |
"verify": True, | |
} | |
action = MockAction(config) | |
actual = action._get_verify() | |
expected = "/path/to/pem" | |
assert expected == actual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment