cope with empty search engines, correct property hangover and comment (bug #657992)

This commit is contained in:
Andy McKay 2011-05-18 12:15:53 -07:00
Родитель f66d2fa816
Коммит 640e781129
4 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@ -78,7 +78,10 @@ class FileViewer:
pass
if self.is_search_engine() and self.src.endswith('.xml'):
os.makedirs(self.dest)
try:
os.makedirs(self.dest)
except OSError, err:
pass
shutil.copyfile(self.src,
os.path.join(self.dest, self.file.filename))
else:
@ -165,7 +168,8 @@ class FileViewer:
def get_default(self, key=None):
"""Gets the default file and copes with search engines."""
if self.is_search_engine() and not key:
return self.get_files().keys()[0]
files = self.get_files()
return files.keys()[0] if files else None
return key if key else 'install.rdf'
def get_files(self):

Просмотреть файл

@ -200,6 +200,11 @@ class TestSearchEngineHelper(test_utils.TestCase):
self.viewer.extract()
eq_(self.viewer.get_default(None), 'a9.xml')
def test_default_no_files(self):
self.viewer.extract()
os.remove(os.path.join(self.viewer.dest, 'a9.xml'))
eq_(self.viewer.get_default(None), None)
class TestDiffSearchEngine(test_utils.TestCase):

Просмотреть файл

@ -61,6 +61,9 @@ class FilesBase:
shutil.copyfile(src, file_obj.file_path)
self.file_viewer = FileViewer(self.file)
# Setting this to True, so we are delaying the extraction of files,
# in the tests, the files won't be extracted.
# Most of these tests extract as needed to.
Switch.objects.create(name='delay-file-viewer', active=True)
def tearDown(self):
@ -171,9 +174,12 @@ class FilesBase:
@patch('waffle.switch_is_active')
def test_no_files_switch(self, switch_is_active):
switch_is_active.return_value = False
# By setting the switch to False, we are not delaying the file
# extraction. The files will be extracted and there will be
# files in context.
res = self.client.get(self.file_url())
eq_(res.status_code, 200)
assert 'files' not in res.context
assert 'files' in res.context
def test_files(self):
self.file_viewer.extract()

Просмотреть файл

@ -57,7 +57,7 @@ def browse(request, viewer, key=None):
data['poll_url'] = reverse('files.poll', args=[viewer.file.id])
if (not waffle.switch_is_active('delay-file-viewer') and
not viewer.is_extracted):
not viewer.is_extracted()):
extract_file(viewer)
if viewer.is_extracted():
@ -106,7 +106,7 @@ def compare(request, diff, key=None):
diff.right.file.id])
if (not waffle.switch_is_active('delay-file-viewer')
and not diff.is_extracted):
and not diff.is_extracted()):
extract_file(diff.left)
extract_file(diff.right)