mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
config: Convert tests to pytest style
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
1644b30605
commit
377a50e213
@ -14,66 +14,76 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tests for config module.
|
Tests for config module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
|
||||||
|
|
||||||
from plinth import __main__ as plinth_main
|
from plinth import __main__ as plinth_main
|
||||||
|
|
||||||
from ..forms import ConfigurationForm
|
from ..forms import ConfigurationForm
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(unittest.TestCase):
|
def test_hostname_field():
|
||||||
"""Test cases for testing the config module."""
|
"""Test that hostname field accepts only valid hostnames."""
|
||||||
def test_hostname_field(self):
|
valid_hostnames = [
|
||||||
"""Test that hostname field accepts only valid hostnames."""
|
'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname', 'example',
|
||||||
valid_hostnames = [
|
'012345678901234567890123456789012345678901234567890123456789012'
|
||||||
'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname', 'example',
|
]
|
||||||
'012345678901234567890123456789012345678901234567890123456789012']
|
invalid_hostnames = [
|
||||||
invalid_hostnames = [
|
'', '-', '-a', 'a-', '.a', 'a.', 'a.a', '?', 'a?a',
|
||||||
'', '-', '-a', 'a-', '.a', 'a.', 'a.a', '?', 'a?a',
|
'0123456789012345678901234567890123456789012345678901234567890123'
|
||||||
'0123456789012345678901234567890123456789012345678901234567890123']
|
]
|
||||||
|
|
||||||
for hostname in valid_hostnames:
|
for hostname in valid_hostnames:
|
||||||
form = ConfigurationForm({'hostname': hostname,
|
form = ConfigurationForm({
|
||||||
'domainname': 'example.com'})
|
'hostname': hostname,
|
||||||
self.assertTrue(form.is_valid())
|
'domainname': 'example.com'
|
||||||
|
})
|
||||||
|
assert form.is_valid()
|
||||||
|
|
||||||
for hostname in invalid_hostnames:
|
for hostname in invalid_hostnames:
|
||||||
form = ConfigurationForm({'hostname': hostname,
|
form = ConfigurationForm({
|
||||||
'domainname': 'example.com'})
|
'hostname': hostname,
|
||||||
self.assertFalse(form.is_valid())
|
'domainname': 'example.com'
|
||||||
|
})
|
||||||
|
assert not form.is_valid()
|
||||||
|
|
||||||
def test_domainname_field(self):
|
|
||||||
"""Test that domainname field accepts only valid domainnames."""
|
|
||||||
valid_domainnames = [
|
|
||||||
'', 'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname',
|
|
||||||
'example', 'example.org', 'a.b.c.d', 'a-0.b-0.c-0',
|
|
||||||
'012345678901234567890123456789012345678901234567890123456789012',
|
|
||||||
((('x' * 63) + '.') * 3) + 'x' * 61]
|
|
||||||
invalid_domainnames = [
|
|
||||||
'-', '-a', 'a-', '.a', 'a.', '?', 'a?a', 'a..a', 'a.-a', '.',
|
|
||||||
((('x' * 63) + '.') * 3) + 'x' * 62, 'x' * 64]
|
|
||||||
|
|
||||||
for domainname in valid_domainnames:
|
def test_domainname_field():
|
||||||
form = ConfigurationForm({'hostname': 'example',
|
"""Test that domainname field accepts only valid domainnames."""
|
||||||
'domainname': domainname})
|
valid_domainnames = [
|
||||||
self.assertTrue(form.is_valid())
|
'', 'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname', 'example',
|
||||||
|
'example.org', 'a.b.c.d', 'a-0.b-0.c-0',
|
||||||
|
'012345678901234567890123456789012345678901234567890123456789012',
|
||||||
|
((('x' * 63) + '.') * 3) + 'x' * 61
|
||||||
|
]
|
||||||
|
invalid_domainnames = [
|
||||||
|
'-', '-a', 'a-', '.a', 'a.', '?', 'a?a', 'a..a', 'a.-a', '.',
|
||||||
|
((('x' * 63) + '.') * 3) + 'x' * 62, 'x' * 64
|
||||||
|
]
|
||||||
|
|
||||||
for domainname in invalid_domainnames:
|
for domainname in valid_domainnames:
|
||||||
form = ConfigurationForm({'hostname': 'example',
|
form = ConfigurationForm({
|
||||||
'domainname': domainname})
|
'hostname': 'example',
|
||||||
self.assertFalse(form.is_valid())
|
'domainname': domainname
|
||||||
|
})
|
||||||
|
assert form.is_valid()
|
||||||
|
|
||||||
def test_locale_path(self):
|
for domainname in invalid_domainnames:
|
||||||
"""
|
form = ConfigurationForm({
|
||||||
Test that the 'locale' directory is in the same folder as __main__.py.
|
'hostname': 'example',
|
||||||
This is required for detecting translated languages.
|
'domainname': domainname
|
||||||
"""
|
})
|
||||||
plinth_dir = os.path.dirname(plinth_main.__file__)
|
assert not form.is_valid()
|
||||||
locale_dir = os.path.join(plinth_dir, 'locale')
|
|
||||||
self.assertTrue(os.path.isdir(locale_dir))
|
|
||||||
|
def test_locale_path():
|
||||||
|
"""
|
||||||
|
Test that the 'locale' directory is in the same folder as __main__.py.
|
||||||
|
This is required for detecting translated languages.
|
||||||
|
"""
|
||||||
|
plinth_dir = os.path.dirname(plinth_main.__file__)
|
||||||
|
locale_dir = os.path.join(plinth_dir, 'locale')
|
||||||
|
assert os.path.isdir(locale_dir)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user