Skip to content

Commit

Permalink
Merge pull request #902 from sphinx-contrib/adding-config-coverage
Browse files Browse the repository at this point in the history
Adding config coverage
  • Loading branch information
jdknight authored Mar 3, 2024
2 parents 2f2a094 + 92a3946 commit 0d293f1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
28 changes: 0 additions & 28 deletions sphinxcontrib/confluencebuilder/config/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,34 +405,6 @@ def string(self):

return self

def string_or_strings(self):
"""
checks if a configuration is a string or collection of strings
After an instance has been set a configuration key (via `conf`), this
method can be used to check if the value (if any) configured with this
key is a string or collection of strings. If not, an
`ConfluenceConfigError` exception will be thrown.
In the event that the configuration is not set (e.g. a value of `None`)
or is an empty collection, this method will have no effect.
Returns:
the validator instance
"""
value = self._value()

if value is not None:
if isinstance(value, (list, set, tuple)):
if not all(isinstance(entry, str) for entry in value):
msg = f'{self.key} is not a collection of strings'
raise ConfluenceConfigError(msg)
elif not isinstance(value, str):
msg = f'{self.key} is not a string or collection of strings'
raise ConfluenceConfigError(msg)

return self

def strings(self, no_space=False):
"""
checks if a configuration is a collection of strings
Expand Down
48 changes: 48 additions & 0 deletions tests/unit-tests/test_config_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from sphinx.errors import SphinxWarning
from sphinxcontrib.confluencebuilder.builder import ConfluenceBuilder
from sphinxcontrib.confluencebuilder.config.exceptions import ConfluenceConfigError
from sphinxcontrib.confluencebuilder.config.exceptions import ConfluencePermitRawHtmlConfigError
from sphinxcontrib.confluencebuilder.config.exceptions import ConfluencePublishCleanupConflictConfigError
from sphinxcontrib.confluencebuilder.config.exceptions import ConfluenceSourcelinkTypeConfigError
from tests.lib import EXT_NAME
from tests.lib import mock_getpass
from tests.lib import mock_input
Expand Down Expand Up @@ -212,6 +215,15 @@ def test_config_check_ca_cert(self):
with self.assertRaises(ConfluenceConfigError):
self._try_config()

def test_config_check_cleanup_conflict(self):
# enable publishing enabled checks
self._prepare_valid_publish()

self.config['confluence_cleanup_archive'] = True
self.config['confluence_cleanup_purge'] = True
with self.assertRaises(ConfluencePublishCleanupConflictConfigError):
self._try_config()

def test_config_check_client_cert(self):
valid_cert = self.dummy_exists
missing_cert = self.dummy_missing
Expand Down Expand Up @@ -610,6 +622,23 @@ def test_config_check_parent_page_id_check(self):
with self.assertRaises(ConfluenceConfigError):
self._try_config()

def test_config_check_permit_raw_html(self):
self.config['confluence_permit_raw_html'] = True
self._try_config()

self.config['confluence_permit_raw_html'] = False
self._try_config()

self.config['confluence_permit_raw_html'] = ''
self._try_config()

self.config['confluence_permit_raw_html'] = 'sample-macro'
self._try_config()

self.config['confluence_permit_raw_html'] = [1, 2, 3]
with self.assertRaises(ConfluencePermitRawHtmlConfigError):
self._try_config()

def test_config_check_prev_next_buttons_location(self):
self.config['confluence_prev_next_buttons_location'] = 'bottom'
self._try_config()
Expand Down Expand Up @@ -663,6 +692,10 @@ def test_config_check_publish_delay(self):
with self.assertRaises(ConfluenceConfigError):
self._try_config()

self.config['confluence_publish_delay'] = 'one-hour'
with self.assertRaises(ConfluenceConfigError):
self._try_config()

def test_config_check_publish_headers(self):
self.config['confluence_publish_headers'] = {}
self._try_config()
Expand Down Expand Up @@ -830,6 +863,10 @@ def test_config_check_publish_root(self):
with self.assertRaises(ConfluenceConfigError):
self._try_config()

self.config['confluence_publish_root'] = 'MyPage'
with self.assertRaises(ConfluenceConfigError):
self._try_config()

def test_config_check_publish_target_conflicts(self):
# enable publishing enabled checks
self._prepare_valid_publish()
Expand Down Expand Up @@ -996,6 +1033,7 @@ def test_config_check_sourcelink(self):
# templates
supported_templates = [
'bitbucket',
'codeberg',
'github',
'gitlab',
]
Expand Down Expand Up @@ -1028,6 +1066,16 @@ def test_config_check_sourcelink(self):
with self.assertRaises(ConfluenceConfigError):
self._try_config()

invalid_template = {
'type': 'invalid',
'owner': 'test',
'repo': 'test',
'version': 'test',
}
self.config['confluence_sourcelink'] = dict(invalid_template)
with self.assertRaises(ConfluenceSourcelinkTypeConfigError):
self._try_config()

def test_config_check_title_overrides(self):
self.config['confluence_title_overrides'] = {}
self._try_config()
Expand Down

0 comments on commit 0d293f1

Please sign in to comment.