Esempio n. 1
0
    def test__deploy_zapp(self):
        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('x/a', 'b', None), ('x/c', 'd', None)])
            zpm._deploy_zapp(self.conn, self.target, self.zapp_path,
                             self.auth_opts)

            put_object = self.conn.put_object
            assert put_object.call_count == 2
            assert put_object.call_args_list == [
                mock.call('x', 'a', 'b', content_type=None),
                mock.call('x', 'c', 'd', content_type=None)]
Esempio n. 2
0
    def test__deploy_zapp(self):
        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('x/a', 'b', None), ('x/c', 'd', None)])
            zpm._deploy_zapp(self.conn, self.target, self.zapp_path,
                             self.auth_opts)

            put_object = self.conn.put_object
            assert put_object.call_count == 2
            assert put_object.call_args_list == [
                mock.call('x', 'a', 'b', content_type=None),
                mock.call('x', 'c', 'd', content_type=None)
            ]
Esempio n. 3
0
    def test__deploy_zapp_container_not_empty_force(self):
        self.conn.get_container.return_value = ({}, ['file1'])

        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('x/a', 'b', None), ('x/c', 'd', None)])
            zpm._deploy_zapp(self.conn, self.target, self.zapp_path,
                             self.auth_opts, force=True)

            put_object = self.conn.put_object
            assert put_object.call_count == 2
            assert put_object.call_args_list == [
                mock.call('x', 'a', 'b', content_type=None),
                mock.call('x', 'c', 'd', content_type=None)]
Esempio n. 4
0
    def test__deploy_zapp_container_not_empty(self):
        self.conn.get_container.return_value = (
            {},  # response headers
            # The actual files list response from Swift is a list of
            # dictionaries. For these tests, we don't actually check the
            # content; just length of the file list.
            ['file1'],
        )

        with pytest.raises(zpmlib.ZPMException) as exc:
            zpm._deploy_zapp(self.conn, 'target/dir1/dir2', None, None)

        assert str(exc.value) == (
            "Target container ('target') must be empty to deploy this zapp"
        )
        assert self.conn.get_container.call_args_list == [mock.call('target')]
Esempio n. 5
0
    def test__deploy_zapp_container_not_empty_force(self):
        self.conn.get_container.return_value = ({}, ['file1'])

        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('x/a', 'b', None), ('x/c', 'd', None)])
            zpm._deploy_zapp(self.conn,
                             self.target,
                             self.zapp_path,
                             self.auth_opts,
                             force=True)

            put_object = self.conn.put_object
            assert put_object.call_count == 2
            assert put_object.call_args_list == [
                mock.call('x', 'a', 'b', content_type=None),
                mock.call('x', 'c', 'd', content_type=None)
            ]
Esempio n. 6
0
    def test__deploy_zapp_container_doesnt_exist(self):
        self.conn.get_container.side_effect = (
            swiftclient.exceptions.ClientException(None))

        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('target/dir/foo.py', 'data', None)])
            zpm._deploy_zapp(self.conn, 'target/dir', None, None)

            # check that the container is created
            assert self.conn.put_container.call_count == 1
            assert self.conn.put_container.call_args_list == [
                mock.call('target')
            ]
            # check that files are uploaded correctly
            assert self.conn.put_object.call_count == 1
            assert self.conn.put_object.call_args_list == [
                mock.call('target', 'dir/foo.py', 'data', content_type=None)
            ]
Esempio n. 7
0
    def test__deploy_zapp_container_not_empty(self):
        self.conn.get_container.return_value = (
            {},  # response headers
            # The actual files list response from Swift is a list of
            # dictionaries. For these tests, we don't actually check the
            # content; just length of the file list.
            ['file1'],
        )

        with pytest.raises(zpmlib.ZPMException) as exc:
            zpm._deploy_zapp(self.conn, 'target/dir1/dir2', None, None)

        assert str(exc.value) == (
            "Target container ('target') is not empty.\n"
            "Deploying to a non-empty container can cause consistency "
            "problems with overwritten objects.\n"
            "Specify the flag `--force/-f` to overwrite anyway.")
        assert self.conn.get_container.call_args_list == [mock.call('target')]
Esempio n. 8
0
    def test__deploy_zapp_container_doesnt_exist(self):
        self.conn.get_container.side_effect = (
            swiftclient.exceptions.ClientException(None)
        )

        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('target/dir/foo.py', 'data', None)])
            zpm._deploy_zapp(self.conn, 'target/dir', None, None)

            # check that the container is created
            assert self.conn.put_container.call_count == 1
            assert self.conn.put_container.call_args_list == [
                mock.call('target')
            ]
            # check that files are uploaded correctly
            assert self.conn.put_object.call_count == 1
            assert self.conn.put_object.call_args_list == [
                mock.call('target', 'dir/foo.py', 'data', content_type=None)
            ]
Esempio n. 9
0
    def test__deploy_zapp_container_not_empty(self):
        self.conn.get_container.return_value = (
            {},  # response headers
            # The actual files list response from Swift is a list of
            # dictionaries. For these tests, we don't actually check the
            # content; just length of the file list.
            ['file1'],
        )

        with pytest.raises(zpmlib.ZPMException) as exc:
            zpm._deploy_zapp(self.conn, 'target/dir1/dir2', None, None)

        assert str(exc.value) == (
            "Target container ('target') is not empty.\n"
            "Deploying to a non-empty container can cause consistency "
            "problems with overwritten objects.\n"
            "Specify the flag `--force/-f` to overwrite anyway."
        )
        assert self.conn.get_container.call_args_list == [mock.call('target')]
Esempio n. 10
0
    def test__deploy_zapp_without_index_html(self):
        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('cont/foo.html', 'data', 'text/html')])
            index = zpm._deploy_zapp(self.conn, 'cont', None, None)
            assert index == 'cont/'

            put_object = self.conn.put_object
            assert put_object.call_count == 1
            assert put_object.call_args_list == [
                mock.call('cont', 'foo.html', 'data', content_type='text/html')
            ]
Esempio n. 11
0
    def test__deploy_zapp_without_index_html(self):
        with mock.patch('zpmlib.zpm._generate_uploads') as gu:
            gu.return_value = iter([('cont/foo.html', 'data', 'text/html')])
            index = zpm._deploy_zapp(self.conn, 'cont', None, None)
            assert index == 'cont/'

            put_object = self.conn.put_object
            assert put_object.call_count == 1
            assert put_object.call_args_list == [
                mock.call('cont', 'foo.html', 'data',
                          content_type='text/html')
            ]