mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Template-based tests of combinations of valid elements
This commit is contained in:
parent
ad07eec3e1
commit
8afdcabca8
@ -91,3 +91,63 @@ class TestAttachment(TestCase):
|
||||
"Τιτλε",
|
||||
self.TAGS
|
||||
)
|
||||
|
||||
|
||||
class Permutations(TestCase):
|
||||
valid_correspondents = ['timmy', 'Dr. McWheelie',
|
||||
'Dash Gor-don', 'ο Θερμαστής']
|
||||
valid_titles = ['title', 'Title w Spaces', 'Title a-dash', 'Τίτλος', '']
|
||||
valid_tags = ['tag', 'tig,tag', '-', '0,1,2', '']
|
||||
valid_suffixes = ['pdf', 'png', 'jpg', 'jpeg', 'gif']
|
||||
|
||||
def _test_guessed_attributes(
|
||||
self, filename, title, suffix, correspondent=None, tags=None):
|
||||
file_info = FileInfo.from_path(filename)
|
||||
|
||||
# Required
|
||||
self.assertEqual(file_info.title, title, filename)
|
||||
if suffix == 'jpeg':
|
||||
suffix = 'jpg'
|
||||
self.assertEqual(file_info.suffix, suffix, filename)
|
||||
# Optional
|
||||
if correspondent is None:
|
||||
self.assertEqual(file_info.correspondent,
|
||||
correspondent, filename)
|
||||
else:
|
||||
self.assertEqual(file_info.correspondent.name,
|
||||
correspondent, filename)
|
||||
if tags is None:
|
||||
self.assertEqual(file_info.tags, (), filename)
|
||||
else:
|
||||
self.assertEqual([t.slug for t in file_info.tags],
|
||||
tags.split(','),
|
||||
filename)
|
||||
|
||||
def test_just_title(self):
|
||||
template = '/path/to/{title}.{suffix}'
|
||||
for title in self.valid_titles:
|
||||
for suffix in self.valid_suffixes:
|
||||
spec = dict(title=title, suffix=suffix)
|
||||
filename = template.format(**spec)
|
||||
self._test_guessed_attributes(filename, **spec)
|
||||
|
||||
def test_title_and_correspondent(self):
|
||||
template = '/path/to/{correspondent} - {title}.{suffix}'
|
||||
for correspondent in self.valid_correspondents:
|
||||
for title in self.valid_titles:
|
||||
for suffix in self.valid_suffixes:
|
||||
spec = dict(correspondent=correspondent, title=title,
|
||||
suffix=suffix)
|
||||
filename = template.format(**spec)
|
||||
self._test_guessed_attributes(filename, **spec)
|
||||
|
||||
def test_title_and_correspondent_and_tags(self):
|
||||
template = '/path/to/{correspondent} - {title} - {tags}.{suffix}'
|
||||
for correspondent in self.valid_correspondents:
|
||||
for title in self.valid_titles:
|
||||
for tags in self.valid_tags:
|
||||
for suffix in self.valid_suffixes:
|
||||
spec = dict(correspondent=correspondent, title=title,
|
||||
tags=tags, suffix=suffix)
|
||||
filename = template.format(**spec)
|
||||
self._test_guessed_attributes(filename, **spec)
|
||||
|
Loading…
x
Reference in New Issue
Block a user