Description_string now only allows strings

pull/16/head
Dan Puttick 2017-07-14 16:41:44 -04:00
parent a2989cfbd3
commit b77451ae7a
2 changed files with 53 additions and 24 deletions

View File

@ -88,6 +88,21 @@ class FileBase(object):
else: else:
return True return True
@property
def description_string(self):
return self.__description_string
@description_string.setter
def description_string(self, value):
if hasattr(self, 'description_string'):
if isinstance(value, str):
if value not in self.__description_string:
self.__description_string.append(value)
else:
raise TypeError("Description_string can only include strings")
else:
self.__description_string = value
def set_property(self, prop_string, value): def set_property(self, prop_string, value):
""" """
Take a property and a value and add them to the file's stored props. Take a property and a value and add them to the file's stored props.
@ -98,10 +113,6 @@ class FileBase(object):
""" """
if hasattr(self, prop_string): if hasattr(self, prop_string):
setattr(self, prop_string, value) setattr(self, prop_string, value)
else:
if prop_string is 'description_string':
if value not in self.description_string:
self.description_string.append(value)
else: else:
self._user_defined[prop_string] = value self._user_defined[prop_string] = value

View File

@ -44,8 +44,15 @@ class TestFileBase:
return FileBase(file_path, dst_dir_path) return FileBase(file_path, dst_dir_path)
@fixture @fixture
def file_marked_dangerous(self): def text_file(self):
pass with mock.patch(
'kittengroomer.helpers.magic.from_file',
return_value='text/plain'
):
src_path = 'src/test.txt'
dst_path = 'dst/test.txt'
file = FileBase(src_path, dst_path)
return file
# Constructor behavior # Constructor behavior
@ -133,44 +140,55 @@ class TestFileBase:
with mock.patch('kittengroomer.helpers.magic.from_file', with mock.patch('kittengroomer.helpers.magic.from_file',
return_value='data'): return_value='data'):
file = FileBase('', '') file = FileBase('', '')
assert file.has_mimetype == False assert file.has_mimetype is False
# File properties # File properties
def get_property_doesnt_exist(self): def get_property_doesnt_exist(self, text_file):
"""Trying to get a property that doesn't exist should return None.""" """Trying to get a property that doesn't exist should return None."""
pass assert text_file.get_property('thing') is None
def get_property_builtin(self): def get_property_builtin(self, text_file):
"""Getting a default property that's been set should return that property.""" """Getting a property that's been set should return that property."""
pass assert text_file.get_property('is_dangerous') is False
def get_property_user_defined(self): def get_property_user_defined(self, text_file):
"""Getting a user defined property should return that propety.""" """Getting a user defined property should return that property."""
pass text_file._user_defined = {'thing': True}
assert text_file.get_property('thing') is True
def set_property_user_defined(self): def set_property_user_defined(self, text_file):
"""Setting a non-default property should make it available for """Setting a non-default property should make it available for
get_property.""" get_property."""
pass text_file.set_property('thing', True)
assert text_file.get_property('thing') is True
def set_property_builtin(self): def set_property_builtin(self, text_file):
"""Setting a builtin property should assign that property.""" """Setting a builtin property should assign that property."""
pass text_file.set_property('is_dangerous', True)
assert text_file.get_property('is_dangerous') is True
def test_add_new_description(self): def test_add_new_description(self, text_file):
pass """Adding a new description should add it to the list of description strings."""
text_file.add_description('thing')
assert text_file.get_property('description_string') == ['thing']
def test_add_description_exists(self): def test_add_description_exists(self, text_file):
pass """Adding a description that already exists shouldn't duplicate it."""
text_file.add_description('thing')
text_file.add_description('thing')
assert text_file.get_property('description_string') == ['thing']
def test_add_new_error(self): def test_add_new_error(self):
"""Adding a new error should add it to the dict of errors."""
pass pass
def test_add_error_exists(self): def test_add_error_exists(self):
"""Adding an error that already exists shouldn't duplicate it."""
pass pass
def test_normal_file_mark_dangerous(self): def test_normal_file_mark_dangerous(self):
"""Marking a normal file dangerous shouldn't make it """
pass pass
def test_normal_file_mark_dangerous_filename_change(self): def test_normal_file_mark_dangerous_filename_change(self):