Commit fe837dbc authored by Michal Čihař's avatar Michal Čihař

Split validation tests to invidual cases

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 453afae1
...@@ -386,81 +386,93 @@ class SubProjectValidationTest(RepoTestCase): ...@@ -386,81 +386,93 @@ class SubProjectValidationTest(RepoTestCase):
""" """
SubProject object validation testing. SubProject object validation testing.
""" """
def test_validation(self): def setUp(self):
project = self.create_subproject() super(SubProjectValidationTest, self).setUp()
# Correct project self.component = self.create_subproject()
project.full_clean() # Ensure we have correct component
self.component.full_clean()
# Invalid commit message
project.commit_message = '%(foo)s' def test_commit_message(self):
"""Invalid commit message"""
self.component.commit_message = '%(foo)s'
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Bad format string', 'Bad format string',
project.full_clean self.component.full_clean
) )
# Invalid mask def test_filemask(self):
project.filemask = 'foo/x.po' """Invalid mask"""
self.component.filemask = 'foo/x.po'
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'File mask does not contain * as a language placeholder!', 'File mask does not contain * as a language placeholder!',
project.full_clean self.component.full_clean
) )
# Not matching mask
project.filemask = 'foo/*.po' def test_no_matches(self):
"""Not matching mask"""
self.component.filemask = 'foo/*.po'
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'The mask did not match any files!', 'The mask did not match any files!',
project.full_clean self.component.full_clean
) )
# Unknown file format
project.filemask = 'invalid/*.invalid' def test_fileformat(self):
"""Unknown file format"""
self.component.filemask = 'invalid/*.invalid'
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Format of 2 matched files could not be recognized.', 'Format of 2 matched files could not be recognized.',
project.full_clean self.component.full_clean
) )
# Repoweb def test_repoweb(self):
project.repoweb = 'http://%(foo)s/%(bar)s/%72' """Invalid repoweb format"""
self.component.repoweb = 'http://%(foo)s/%(bar)s/%72'
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
"Bad format string ('foo')", "Bad format string ('foo')",
project.full_clean self.component.full_clean
) )
project.repoweb = '' self.component.repoweb = ''
# Bad link def test_link_incomplete(self):
project.repo = 'weblate://foo' """Incomplete link"""
project.push = '' self.component.repo = 'weblate://foo'
self.component.push = ''
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Invalid link to a Weblate project, ' 'Invalid link to a Weblate project, '
'use weblate://project/component.', 'use weblate://project/component.',
project.full_clean self.component.full_clean
) )
# Bad link def test_link_nonexisting(self):
project.repo = 'weblate://foo/bar' """Link to non existing project"""
project.push = '' self.component.repo = 'weblate://foo/bar'
self.component.push = ''
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Invalid link to a Weblate project, ' 'Invalid link to a Weblate project, '
'use weblate://project/component.', 'use weblate://project/component.',
project.full_clean self.component.full_clean
) )
# Bad link def test_link_self(self):
project.repo = 'weblate://test/test' """Link pointing to self"""
project.push = '' self.component.repo = 'weblate://test/test'
self.component.push = ''
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Invalid link to a Weblate project, ' 'Invalid link to a Weblate project, '
'can not link to self!', 'can not link to self!',
project.full_clean self.component.full_clean
) )
def test_validation_mono(self): def test_validation_mono(self):
self.component.project.delete()
project = self.create_po_mono() project = self.create_po_mono()
# Correct project # Correct project
project.full_clean() project.full_clean()
...@@ -473,45 +485,43 @@ class SubProjectValidationTest(RepoTestCase): ...@@ -473,45 +485,43 @@ class SubProjectValidationTest(RepoTestCase):
) )
def test_validation_languge_re(self): def test_validation_languge_re(self):
subproject = self.create_subproject() self.component.language_regex = '[-'
subproject.language_regex = '[-'
self.assertRaises( self.assertRaises(
ValidationError, ValidationError,
subproject.full_clean self.component.full_clean
) )
def test_validation_newlang(self): def test_validation_newlang(self):
subproject = self.create_subproject() self.component.new_base = 'po/project.pot'
subproject.new_base = 'po/project.pot' self.component.save()
subproject.save()
# Check that it warns about unused pot # Check that it warns about unused pot
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Base file for new translations is not used ' 'Base file for new translations is not used '
'because of component settings.', 'because of component settings.',
subproject.full_clean self.component.full_clean
) )
subproject.new_lang = 'add' self.component.new_lang = 'add'
subproject.save() self.component.save()
# Check that it warns about not supported format # Check that it warns about not supported format
self.assertRaisesMessage( self.assertRaisesMessage(
ValidationError, ValidationError,
'Chosen file format does not support adding new ' 'Chosen file format does not support adding new '
'translations as chosen in project settings.', 'translations as chosen in project settings.',
subproject.full_clean self.component.full_clean
) )
subproject.file_format = 'po' self.component.file_format = 'po'
subproject.save() self.component.save()
# Clean class cache, pylint: disable=W0212 # Clean class cache, pylint: disable=W0212
subproject._file_format = None self.component._file_format = None
# With correct format it should validate # With correct format it should validate
subproject.full_clean() self.component.full_clean()
def test_lang_code(self): def test_lang_code(self):
subproject = SubProject() subproject = SubProject()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment