def test_release_no_drive(self, mock_cepath, mock_move, mock_make_archive, mock_copy, mock_makedirs, mock_getpass, mock_session, mock_upload, mock_rmtree, mock_isdir): ''' Test that release() correctly prepares a release that does not upload files to Google Drive. ''' # Mock functions called by release() to simulate an actual call args = copy.deepcopy(standard_args) args['DriveReleaseFiles'] = [] release_data = helpers.mock_release_data(args) mock_session.return_value.get.return_value.content = release_data # Test without DriveReleaseFiles tools.release(**args) # Check that no file operations occur when no files are specified for release # to Google Drive. mock_copy.assert_not_called() mock_makedirs.assert_not_called() mock_rmtree.assert_not_called() mock_make_archive.assert_not_called() mock_move.assert_not_called() mock_upload.assert_not_called()
def test_release_standard(self, mock_cepath, mock_move, mock_make_archive, mock_copy, mock_makedirs, mock_getpass, mock_session, mock_upload, mock_rmtree, mock_isdir): ''' Test that release() correctly prepares a release that uploads zipped files to Google Drive. ''' # Mock functions called by release() to simulate an actual call mock_getpass.return_value = 'test_token' mock_session.return_value = mock.MagicMock(post=mock.MagicMock(), get=mock.MagicMock()) args = copy.deepcopy(standard_args) release_data = helpers.mock_release_data(args) mock_session.return_value.get.return_value.content = release_data # When org/repo refers to a nonexistent GitHub repository, # make the release request fail. mock_session.return_value.post.side_effect = fx.post_side_effect # Give mock_upload a side effect preserving release assets listing mock_upload.side_effect = fx.upload_asset_side_effect args['zip_release'] = True self.check_release(args, mock_session, mock_upload, mock_copy, mock_make_archive, mock_move) # Test release() when DriveReleaseFiles is a string args['DriveReleaseFiles'] = 'plot.pdf' self.check_release(args, mock_session, mock_upload, mock_copy, mock_make_archive, mock_move) # Test release() when required directories don't exist local_release = args['local_release'] mock_isdir.return_value = False self.check_release(args, mock_session, mock_upload, mock_copy, mock_make_archive, mock_move) # Did release() create the local_release subdirectory? mock_makedirs.assert_any_call(local_release) # Did it create the temporary directory for to-be-zipped release files? mock_makedirs.assert_any_call('release_content')
def test_release_unintended_inputs(self, mock_move, mock_make_archive, mock_copy, mock_makedirs, mock_getpass, mock_session, mock_upload, mock_rmtree, mock_isdir): ''' Test that release() responds as expected to unintended inputs. ''' # Mock functions called by release() to simulate an actual call mock_getpass.return_value = 'test_token' args = copy.deepcopy(standard_args) release_data = helpers.mock_release_data(args) mock_session.return_value.get.return_value.content = release_data mock_session.return_value.post.side_effect = fx.post_side_effect args = copy.deepcopy(standard_args) # Inappropriate local_release argument and DriveReleaseFiles is empty. test_args = copy.deepcopy(args) test_args['DriveReleaseFiles'] = [] test_args['local_release'] = 1 try: tools.release(**test_args) except: self.fail("Running release() with an invalid local_release " "argument and without files to be released to Google " "Drive shouldn't raise an error!") # local_release is of an inappropriate type self.check_failure({'local_release': 1}, AttributeError) # local_release doesn't contain a /release/ subdirectory. Caps matter! self.check_failure({'local_release': 'root/Release/folder'}, ReleaseError) # org/repo referss to a nonexistent GitHub repository self.check_failure({'org': 'orgg'}, requests.exceptions.HTTPError) self.check_failure({'repo': 1}, requests.exceptions.HTTPError) # Some error-inducing DriveReleaseFiles arguments self.check_failure({'DriveReleaseFiles': True}, TypeError) self.check_failure({'DriveReleaseFiles': [1, 2, 3]}, AttributeError)
def test_release_nozip(self, mock_cepath, mock_move, mock_make_archive, mock_copy, mock_makedirs, mock_getpass, mock_session, mock_upload, mock_rmtree, mock_isdir): ''' Test that release() correctly prepares a release that uploads unzipped files to Google Drive. ''' # Mock functions called by release() to simulate an actual call mock_getpass.return_value = 'test_token' args = copy.deepcopy(standard_args) args['zip_release'] = False release_data = helpers.mock_release_data(args) mock_session.return_value.get.return_value.content = release_data # Give mock_upload a side effect preserving release assets listing mock_upload.side_effect = fx.upload_asset_side_effect self.check_release(args, mock_session, mock_upload, mock_copy, mock_make_archive, mock_move)