Test coverage for pecan.deploy.
This commit is contained in:
3
tests/test_config/sample_apps/sample_app/app.py
Normal file
3
tests/test_config/sample_apps/sample_app/app.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
def setup_app(config):
|
||||||
|
assert config.foo.sample_key == True
|
||||||
|
return 'DEPLOYED!'
|
||||||
9
tests/test_config/sample_apps/sample_app_config.py
Normal file
9
tests/test_config/sample_apps/sample_app_config.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import sample_app
|
||||||
|
|
||||||
|
app = {
|
||||||
|
'modules': [sample_app]
|
||||||
|
}
|
||||||
|
|
||||||
|
foo = {
|
||||||
|
'sample_key': True
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import sample_app_missing
|
||||||
|
|
||||||
|
app = {
|
||||||
|
'modules': [sample_app_missing]
|
||||||
|
}
|
||||||
|
|
||||||
|
foo = {
|
||||||
|
'sample_key': True
|
||||||
|
}
|
||||||
61
tests/test_deploy.py
Normal file
61
tests/test_deploy.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
from pecan.deploy import deploy
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class TestDeploy(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
test_config_d = os.path.join(os.path.dirname(__file__), 'test_config', 'sample_apps')
|
||||||
|
|
||||||
|
if test_config_d not in sys.path:
|
||||||
|
sys.path.append(test_config_d)
|
||||||
|
|
||||||
|
def test_module_lookup(self):
|
||||||
|
"""
|
||||||
|
1. A config file has:
|
||||||
|
app { 'modules': [valid_module] }
|
||||||
|
2. The module, `valid_module` has an app.py that defines a `def setup.py`
|
||||||
|
"""
|
||||||
|
test_config_file = os.path.join(os.path.dirname(__file__), 'test_config', 'sample_apps', 'sample_app_config.py')
|
||||||
|
assert deploy(test_config_file) == 'DEPLOYED!'
|
||||||
|
|
||||||
|
def test_module_lookup_find_best_match(self):
|
||||||
|
"""
|
||||||
|
1. A config file has:
|
||||||
|
app { 'modules': [invalid_module, valid_module] }
|
||||||
|
2. The module, `valid_module` has an app.py that defines a `def setup_app`
|
||||||
|
"""
|
||||||
|
test_config_file = os.path.join(os.path.dirname(__file__), 'test_config', 'sample_apps', 'sample_app_config.py')
|
||||||
|
assert deploy(test_config_file) == 'DEPLOYED!'
|
||||||
|
|
||||||
|
def test_missing_app_file_lookup(self):
|
||||||
|
"""
|
||||||
|
1. A config file has:
|
||||||
|
app { 'modules': [valid_module] }
|
||||||
|
2. The module has no `app.py` file.
|
||||||
|
"""
|
||||||
|
test_config_file = os.path.join(os.path.dirname(__file__), 'test_config', 'sample_apps', 'sample_app_config_missing.py')
|
||||||
|
self.assertRaisesRegexp(
|
||||||
|
Exception,
|
||||||
|
'No app.setup_app found in any of the configured app.modules',
|
||||||
|
deploy,
|
||||||
|
test_config_file
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_missing_setup_app(self):
|
||||||
|
"""
|
||||||
|
1. A config file has:
|
||||||
|
app { 'modules': [valid_module] }
|
||||||
|
2. The module, `valid_module` has an `app.py` that contains no `def setup_app`
|
||||||
|
"""
|
||||||
|
test_config_file = os.path.join(os.path.dirname(__file__), 'test_config', 'sample_apps', 'sample_app_config_missing_app.py')
|
||||||
|
self.assertRaisesRegexp(
|
||||||
|
Exception,
|
||||||
|
'No app.setup_app found in any of the configured app.modules',
|
||||||
|
deploy,
|
||||||
|
test_config_file
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user