def test_import_bundle_dependencies(self, m):
        """Asserts bundle import calls packages create once for each pkg,
        including dependencies.
        """
        pkg1 = make_pkg(
            {'FullName': 'first_app', 'Require': {'second_app': '1.0'}, })
        pkg2 = make_pkg({'FullName': 'second_app'})

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip', body=pkg1)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)

        s = six.StringIO()
        # bundle only contains 1st package
        bundle_contents = {'Packages': [
            {'Name': 'first_app'},
        ]}
        json.dump(bundle_contents, s)
        s = six.BytesIO(s.getvalue().encode('ascii'))

        m.get(TestArgs.murano_repo_url + '/bundles/test_bundle.bundle',
              body=s)

        args = TestArgs()
        args.filename = ["test_bundle"]

        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
    def test_import_bundle_by_url(self, m):
        """Asserts bundle import calls packages create once for each pkg."""
        pkg1 = make_pkg({'FullName': 'first_app'})
        pkg2 = make_pkg({'FullName': 'second_app'})

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip', body=pkg1)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)
        s = six.StringIO()
        bundle_contents = {'Packages': [
            {'Name': 'first_app'},
            {'Name': 'second_app', 'Version': '1.0'}
        ]}
        json.dump(bundle_contents, s)
        s = six.BytesIO(s.getvalue().encode('ascii'))

        url = 'http://127.0.0.2/test_bundle.bundle'
        m.get(url, body=s)

        args = TestArgs()
        args.filename = [url]

        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
Beispiel #3
0
    def test_import_bundle_by_url(self, m):
        """Asserts bundle import calls packages create once for each pkg."""
        pkg1 = make_pkg({'FullName': 'first_app'})
        pkg2 = make_pkg({'FullName': 'second_app'})

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip', body=pkg1)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)
        s = six.StringIO()
        bundle_contents = {'Packages': [
            {'Name': 'first_app'},
            {'Name': 'second_app', 'Version': '1.0'}
        ]}
        json.dump(bundle_contents, s)
        s = six.BytesIO(s.getvalue().encode('ascii'))

        url = 'http://127.0.0.2/test_bundle.bundle'
        m.get(url, body=s)

        args = TestArgs()
        args.filename = [url]

        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
Beispiel #4
0
    def test_import_bundle_dependencies(self, m):
        """Asserts bundle import calls packages create once for each pkg,
        including dependencies.
        """
        pkg1 = make_pkg(
            {'FullName': 'first_app', 'Require': {'second_app': '1.0'}, })
        pkg2 = make_pkg({'FullName': 'second_app'})

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip', body=pkg1)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)

        s = six.StringIO()
        # bundle only contains 1st package
        bundle_contents = {'Packages': [
            {'Name': 'first_app'},
        ]}
        json.dump(bundle_contents, s)
        s = six.BytesIO(s.getvalue().encode('ascii'))

        m.get(TestArgs.murano_repo_url + '/bundles/test_bundle.bundle',
              body=s)

        args = TestArgs()
        args.filename = ["test_bundle"]

        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
Beispiel #5
0
    def test_import_bundle_by_name(self, m):
        """Asserts bundle import calls packages create once for each pkg."""
        pkg1 = make_pkg({'FullName': 'first_app'})
        pkg2 = make_pkg({'FullName': 'second_app'})

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip', body=pkg1)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)
        s = StringIO.StringIO()
        bundle_contents = {'Packages': [
            {'Name': 'first_app'},
            {'Name': 'second_app', 'Version': '1.0'}
        ]}
        json.dump(bundle_contents, s)
        s.seek(0)

        m.get(TestArgs.murano_repo_url + '/bundles/test_bundle.bundle',
              body=s)

        args = TestArgs()
        args.filename = ["test_bundle"]

        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
    def test_import_bundle_no_bundle(self, m):
        url = 'http://127.0.0.1/bundles/test_bundle.bundle'
        m.get(url, status_code=404)

        args = TestArgs()
        args.filename = ["test_bundle"]

        v1_shell.do_bundle_import(self.client, args)
        self.assertFalse(self.client.packages.create.called)
Beispiel #7
0
    def test_import_bundle_no_bundle(self, m):
        url = 'http://127.0.0.1/bundles/test_bundle.bundle'
        m.get(url, status_code=404)

        args = TestArgs()
        args.filename = ["test_bundle"]

        v1_shell.do_bundle_import(self.client, args)
        self.assertFalse(self.client.packages.create.called)
    def test_import_local_bundle(self, m):
        """Asserts local bundles are first searched locally."""
        tmp_dir = tempfile.mkdtemp()
        bundle_file = os.path.join(tmp_dir, 'bundle.bundle')
        with open(os.path.join(tmp_dir, 'bundle.bundle'), 'w') as f:

            bundle_contents = {'Packages': [
                {'Name': 'first_app'},
                {'Name': 'second_app', 'Version': '1.0'}
            ]}
            json.dump(bundle_contents, f)

        pkg1 = make_pkg({'FullName': 'first_app',
                         'Require': {'third_app': None}})
        pkg2 = make_pkg({'FullName': 'second_app'})
        pkg3 = make_pkg({'FullName': 'third_app'})
        with open(os.path.join(tmp_dir, 'first_app'), 'wb') as f:
            f.write(pkg1.read())
        with open(os.path.join(tmp_dir, 'third_app'), 'wb') as f:
            f.write(pkg3.read())

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip',
              status_code=404)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)
        m.get(TestArgs.murano_repo_url + '/apps/third_app.zip',
              status_code=404)

        args = TestArgs()
        args.filename = [bundle_file]
        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
                mock.call({'is_public': False}, {'third_app': mock.ANY}),
            ], any_order=True,
        )
        shutil.rmtree(tmp_dir)
Beispiel #9
0
    def test_import_local_bundle(self, m):
        """Asserts local bundles are first searched locally."""
        tmp_dir = tempfile.mkdtemp()
        bundle_file = os.path.join(tmp_dir, 'bundle.bundle')
        with open(os.path.join(tmp_dir, 'bundle.bundle'), 'w') as f:

            bundle_contents = {'Packages': [
                {'Name': 'first_app'},
                {'Name': 'second_app', 'Version': '1.0'}
            ]}
            json.dump(bundle_contents, f)

        pkg1 = make_pkg({'FullName': 'first_app',
                         'Require': {'third_app': None}})
        pkg2 = make_pkg({'FullName': 'second_app'})
        pkg3 = make_pkg({'FullName': 'third_app'})
        with open(os.path.join(tmp_dir, 'first_app'), 'wb') as f:
            f.write(pkg1.read())
        with open(os.path.join(tmp_dir, 'third_app'), 'wb') as f:
            f.write(pkg3.read())

        m.get(TestArgs.murano_repo_url + '/apps/first_app.zip',
              status_code=404)
        m.get(TestArgs.murano_repo_url + '/apps/second_app.1.0.zip',
              body=pkg2)
        m.get(TestArgs.murano_repo_url + '/apps/third_app.zip',
              status_code=404)

        args = TestArgs()
        args.filename = [bundle_file]
        v1_shell.do_bundle_import(self.client, args)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
                mock.call({'is_public': False}, {'third_app': mock.ANY}),
            ], any_order=True,
        )
        shutil.rmtree(tmp_dir)