Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uninstalling capacity #17

Merged
merged 7 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unreleased

- create_or_update lyrics accepts now a model so we can change its env (user,
context, ...)
- capacity to uninstall module

**Documentation**

Expand Down
1 change: 1 addition & 0 deletions anthem/lyrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
* load a csv, xml or yaml file
* add a xmlid on a record
* upsert a record
* uninstall a module

"""
18 changes: 18 additions & 0 deletions anthem/lyrics/uninstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from ..exceptions import AnthemError


def uninstall(ctx, module_list):
""" uninstall module """
if not module_list:
raise AnthemError(u"You have to provide a list of "
"module's name to uninstall")

mods = ctx.env['ir.module.module'].search([('name', 'in', module_list)])
try:
mods.button_immediate_uninstall()
except:
raise AnthemError(u'Cannot uninstall modules. See the logs')
22 changes: 22 additions & 0 deletions tests/test_lyrics_uninstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html)

import pytest
import anthem.cli
from anthem.lyrics.uninstaller import uninstall
from anthem.exceptions import AnthemError


def test_uninstall_1():
with anthem.cli.Context(None, anthem.cli.Options(test_mode=True)) as ctx:
with pytest.raises(AnthemError) as excinfo:
uninstall(ctx, [])
excinfo.match(r'You have to provide a list of module.*')


def test_uninstall_2():
with anthem.cli.Context(None, anthem.cli.Options(test_mode=True)) as ctx:
ctx.env['ir.module.module'].search(
[('name', '=', 'lunch')]).button_immediate_install()
uninstall(ctx, ['lunch'])