Skip to content

Commit

Permalink
Merge pull request #17 from damdam-s/uninstaller
Browse files Browse the repository at this point in the history
Add uninstalling capacity
  • Loading branch information
guewen authored Apr 18, 2017
2 parents 1e37d18 + 701f061 commit a670a46
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
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'])

0 comments on commit a670a46

Please sign in to comment.