def test_publish(galaxy_context, mocker): mocker.patch('ansible_galaxy.actions.publish.GalaxyAPI.publish_file', return_value={"task": "/api/v2/collection-imports/123456789"}) res = publish.publish(galaxy_context, "/dev/null", display_callback) log.debug('res: %s', res) assert res == 0
def test_publish(galaxy_context, mocker): publish_api_key = "doesnt_matter_not_used" mocker.patch('ansible_galaxy.actions.publish.GalaxyAPI.publish_file', return_value=b'{"task": "/api/v2/collection-imports/123456789"}') res = publish.publish(galaxy_context, "/dev/null", publish_api_key, display_callback) log.debug('res: %s', res) assert res == 0
def execute_publish(self): """ Publish a collection artifact to Galaxy. """ galaxy_context = self._get_galaxy_context(self.options, self.config) if not len(self.args) or not os.path.isfile(self.args[0]): raise cli_exceptions.CliOptionsError("- you must specify a path to a collection archive") return publish.publish(galaxy_context, self.args[0], display_callback=self.display)
def test_publish_api_errors(mocker): error_msg = 'Error publishing ns-n-1.0.0 to http://notreal.invalid:8000/api/v2/collections/ - Collection "ns-n-1.0.0" already exists.' mocker.patch('ansible_galaxy.actions.publish._publish', return_value={ 'errors': [error_msg], 'success': False }) mock_display_callback = mocker.Mock() context = None res = publish.publish(context, "/dev/null", mock_display_callback) log.debug('res: %s', res) assert res == os.EX_SOFTWARE # 70 assert mock_display_callback.called is True