def test_bintray_version_found(self):
        exists_mock = MagicMock(return_value=False)
        load_bintray_credentials_mock = MagicMock(return_value=('username', 'password'))
        parse_bundle_configuration_mock = MagicMock(return_value=('urn:x-bundle:', 'typesafe', 'bundle-configuration',
                                                                  'bundle-name', 'v1', 'digest'))
        bintray_resolve_version_mock = MagicMock(return_value={
            'org': 'typesafe',
            'repo': 'bundle-configuration',
            'package_name': 'bundle-name',
            'compatibility_version': 'v1',
            'digest': 'digest',
            'path': 'download.zip'
        })
        load_bundle_from_cache_mock = MagicMock(return_value=(True, 'bundle-name', 'mock bundle file'))

        with patch('os.path.exists', exists_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', load_bintray_credentials_mock), \
                patch('conductr_cli.bundle_shorthand.parse_bundle_configuration', parse_bundle_configuration_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.bintray_resolve_version', bintray_resolve_version_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.uri_resolver.load_bundle_from_cache',
                      load_bundle_from_cache_mock):
            is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_configuration_from_cache(
                '/cache-dir', 'bundle-name:v1')
            self.assertTrue(is_resolved)
            self.assertEqual('bundle-name', bundle_name)
            self.assertEqual('mock bundle file', bundle_file)

        exists_mock.assert_not_called()
        load_bintray_credentials_mock.assert_called_with()
        parse_bundle_configuration_mock.assert_called_with('bundle-name:v1')
        bintray_resolve_version_mock.assert_called_with('username', 'password', 'typesafe', 'bundle-configuration',
                                                        'bundle-name', 'v1', 'digest')
        load_bundle_from_cache_mock.assert_called_with('/cache-dir',
                                                       'https://dl.bintray.com/typesafe/bundle-configuration/download.zip')
    def test_file(self):
        exists_mock = MagicMock(return_value=True)
        parse_bundle_configuration_mock = MagicMock()

        with patch('os.path.exists', exists_mock), \
                patch('conductr_cli.bundle_shorthand.parse_bundle_configuration', parse_bundle_configuration_mock):
            is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_configuration_from_cache(
                '/cache-dir', '/tmp/bundle.zip')
            self.assertFalse(is_resolved)
            self.assertIsNone(bundle_name)
            self.assertIsNone(bundle_file)

        exists_mock.assert_called_with('/tmp/bundle.zip')
        parse_bundle_configuration_mock.assert_not_called()
    def test_failure_http_error(self):
        exists_mock = MagicMock(return_value=False)
        load_bintray_credentials_mock = MagicMock(return_value=('username', 'password'))
        parse_bundle_configuration_mock = MagicMock(return_value=('urn:x-bundle:', 'typesafe', 'bundle-configuration',
                                                    'bundle-name', 'v1', 'digest'))
        bintray_resolve_version_mock = MagicMock(side_effect=HTTPError('test only'))

        with patch('os.path.exists', exists_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', load_bintray_credentials_mock), \
                patch('conductr_cli.bundle_shorthand.parse_bundle_configuration', parse_bundle_configuration_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.bintray_resolve_version', bintray_resolve_version_mock):
            is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_configuration_from_cache(
                '/cache-dir', 'bundle-name:v1')
            self.assertFalse(is_resolved)
            self.assertIsNone(bundle_name)
            self.assertIsNone(bundle_file)

        exists_mock.assert_not_called()
        load_bintray_credentials_mock.assert_called_with()
        parse_bundle_configuration_mock.assert_called_with('bundle-name:v1')
        bintray_resolve_version_mock.assert_called_with('username', 'password', 'typesafe', 'bundle-configuration',
                                                        'bundle-name', 'v1', 'digest')