Skip to content

Commit

Permalink
tests: Test response to missing executables
Browse files Browse the repository at this point in the history
  • Loading branch information
ljanyst committed Apr 13, 2019
1 parent 065008b commit c20c3cd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def chk_list(e):
# Test the error cases
#-----------------------------------------------------------------------
unzip = find_executable('unzip')
scrapy = find_executable('scrapy')
for params in error_params:
temp_test_dir = tempfile.mkdtemp()
temp_test_file = tempfile.mkstemp()
Expand Down Expand Up @@ -188,6 +189,23 @@ def chk_list(e):

yield controller.push_project(self.project_archive_data)

#-----------------------------------------------------------------------
# Test missing executables
#-----------------------------------------------------------------------
side_effects = [
([None, scrapy], 'Please install unzip'),
([unzip, None], 'Please install scrapy')
]
for se, msg in side_effects:
with patch('scrapy_do.controller.find_executable') as fe_mock:
fe_mock.side_effect = se
try:
yield controller.push_project(self.project_archive_data)
self.fail('Pusing projects without required executables'
' should have risen an EnvironmentError')
except EnvironmentError as e:
self.assertTrue(str(e).startswith(msg))

#---------------------------------------------------------------------------
@inlineCallbacks
def test_accessors_mutators(self):
Expand Down Expand Up @@ -318,6 +336,18 @@ def test_run_crawler(self):
log_file = os.path.join(controller.log_dir, 'foo.err')
self.assertTrue(os.path.exists(log_file))

#-----------------------------------------------------------------------
# Unzip not found
#-----------------------------------------------------------------------
with patch('scrapy_do.controller.find_executable') as fe_mock:
fe_mock.side_effect = [None]
try:
yield controller._run_crawler('foo', 'bar', 'foo')
self.fail('Unzipping a without unzip should have risen '
'an EnvironmentError')
except EnvironmentError as e:
self.assertTrue(str(e).startswith('Please install unzip'))

#-----------------------------------------------------------------------
# Test the unzipping failuer
#-----------------------------------------------------------------------
Expand Down

0 comments on commit c20c3cd

Please sign in to comment.