Esempio n. 1
0
    def test_bundle(self):
        exists_mock = MagicMock(return_value=False)
        bintray_download_det_mock = MagicMock(return_value=(None, None))

        with patch('os.path.exists', exists_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.bintray_download_details', bintray_download_det_mock):
            bintray_resolver.load_bundle_from_cache(
                '/cache-dir', '/tmp/bundle')

        exists_mock.assert_not_called()
Esempio n. 2
0
    def test_bintray_version_found(self):
        exists_mock = MagicMock(return_value=False)
        load_bintray_credentials_mock = MagicMock(return_value=('username', 'password'))
        parse_bundle_mock = MagicMock(return_value=('urn:x-bundle:', 'typesafe', 'bundle', 'bundle-name', 'v1', 'digest'))
        bintray_resolve_version_mock = MagicMock(return_value={
            'org': 'typesafe',
            'repo': 'bundle',
            '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', parse_bundle_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_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_mock.assert_called_with('bundle-name:v1')
        bintray_resolve_version_mock.assert_called_with('username', 'password', 'typesafe', 'bundle', 'bundle-name',
                                                        'v1', 'digest')
        load_bundle_from_cache_mock.assert_called_with('/cache-dir',
                                                       'https://dl.bintray.com/typesafe/bundle/download.zip')
Esempio n. 3
0
    def test_failure_malformed_bundle_uri(self):
        exists_mock = MagicMock(return_value=False)
        parse_bundle_mock = MagicMock(side_effect=MalformedBundleUriError('test only'))

        with patch('os.path.exists', exists_mock), \
                patch('conductr_cli.bundle_shorthand.parse_bundle', parse_bundle_mock):
            is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_from_cache('/cache-dir',
                                                                                            'bundle-name:v1')
            self.assertFalse(is_resolved)
            self.assertIsNone(bundle_name)
            self.assertIsNone(bundle_file)

        exists_mock.assert_not_called()
        parse_bundle_mock.assert_called_with('bundle-name:v1')
Esempio n. 4
0
    def test_file(self):
        exists_mock = MagicMock(return_value=True)
        parse_bundle_mock = MagicMock()

        with patch('os.path.exists', exists_mock), \
                patch('conductr_cli.bundle_shorthand.parse_bundle', parse_bundle_mock):
            is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_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_mock.assert_not_called()
Esempio n. 5
0
    def test_failure_http_error(self):
        exists_mock = MagicMock(return_value=False)
        load_bintray_credentials_mock = MagicMock(return_value=('username', 'password'))
        parse_bundle_mock = MagicMock(return_value=('urn:x-bundle:', 'typesafe', 'bundle', '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', parse_bundle_mock), \
                patch('conductr_cli.resolvers.bintray_resolver.bintray_resolve_version', bintray_resolve_version_mock):
            is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_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_mock.assert_called_with('bundle-name:v1')
        bintray_resolve_version_mock.assert_called_with('username', 'password', 'typesafe', 'bundle', 'bundle-name',
                                                        'v1', 'digest')