Browse Source

[MIG] auto_backup: Migrate to v9

* Add self.ensure_ones
* Add test coverage
pull/1158/head
Dave Lasley 8 years ago
committed by Andrea
parent
commit
907c689f1f
  1. 12
      auto_backup/README.rst
  2. 5
      auto_backup/__openerp__.py
  3. 4
      auto_backup/models/db_backup.py
  4. 49
      auto_backup/tests/test_auto_backup.py
  5. 7
      auto_backup/view/db_backup_view.xml

12
auto_backup/README.rst

@ -70,15 +70,16 @@ manually execute the selected processes.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/8.0
:target: https://runbot.odoo-community.org/runbot/149/9.0
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/server-tools/issues/new?body=module:%20auto_backup%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits Credits
======= =======
@ -89,6 +90,7 @@ Contributors
* Yenthe Van Ginneken <yenthe.vanginneken@vanroey.be> * Yenthe Van Ginneken <yenthe.vanginneken@vanroey.be>
* Alessio Gerace <alessio.gerace@agilebg.com> * Alessio Gerace <alessio.gerace@agilebg.com>
* Jairo Llopis <yajo.sk8@gmail.com> * Jairo Llopis <yajo.sk8@gmail.com>
* Dave Lasley <dave@laslabs.com>
Maintainer Maintainer
---------- ----------

5
auto_backup/__openerp__.py

@ -7,7 +7,7 @@
{ {
"name": "Database Auto-Backup", "name": "Database Auto-Backup",
"summary": "Backups database", "summary": "Backups database",
"version": "8.0.1.0.1",
"version": "9.0.1.0.0",
"author": ( "author": (
"VanRoey.be - Yenthe Van Ginneken, Agile Business Group," "VanRoey.be - Yenthe Van Ginneken, Agile Business Group,"
" Grupo ESOC Ingeniería de Servicios," " Grupo ESOC Ingeniería de Servicios,"
@ -16,8 +16,7 @@
'license': "AGPL-3", 'license': "AGPL-3",
"website": "http://www.vanroey.be/applications/bedrijfsbeheer/odoo", "website": "http://www.vanroey.be/applications/bedrijfsbeheer/odoo",
"category": "Tools", "category": "Tools",
"depends": ['email_template'],
"demo": [],
"depends": ['mail'],
"data": [ "data": [
"data/backup_data.yml", "data/backup_data.yml",
"security/ir.model.access.csv", "security/ir.model.access.csv",

4
auto_backup/models/db_backup.py

@ -16,7 +16,7 @@ import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
import pysftp import pysftp
except ImportError:
except ImportError: # pragma: no cover
_logger.debug('Cannot import pysftp') _logger.debug('Cannot import pysftp')
@ -235,6 +235,7 @@ class DbBackup(models.Model):
@contextmanager @contextmanager
def cleanup_log(self): def cleanup_log(self):
"""Log a possible cleanup failure.""" """Log a possible cleanup failure."""
self.ensure_one()
try: try:
_logger.info("Starting cleanup process after database backup: %s", _logger.info("Starting cleanup process after database backup: %s",
self.name) self.name)
@ -263,6 +264,7 @@ class DbBackup(models.Model):
@api.multi @api.multi
def sftp_connection(self): def sftp_connection(self):
"""Return a new SFTP connection with found parameters.""" """Return a new SFTP connection with found parameters."""
self.ensure_one()
params = { params = {
"host": self.sftp_host, "host": self.sftp_host,
"username": self.sftp_user, "username": self.sftp_user,

49
auto_backup/tests/test_auto_backup.py

@ -2,27 +2,62 @@
# © 2015 Agile Business Group <http://www.agilebg.com> # © 2015 Agile Business Group <http://www.agilebg.com>
# © 2015 Alessio Gerace <alesiso.gerace@agilebg.com> # © 2015 Alessio Gerace <alesiso.gerace@agilebg.com>
# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os import os
from datetime import datetime from datetime import datetime
from openerp.tests import common from openerp.tests import common
from openerp import exceptions, tools
class TestsAutoBackup(common.TransactionCase): class TestsAutoBackup(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestsAutoBackup, self).setUp() super(TestsAutoBackup, self).setUp()
self.abk = self.env["db.backup"].create(
{
def new_record(self, method='sftp'):
vals = {
'name': u'Têst backup', 'name': u'Têst backup',
'method': method,
} }
)
if method == 'sftp':
vals.update({
'sftp_host': 'test_host',
'sftp_port': '222',
'sftp_user': 'tuser',
})
self.vals = vals
self.env["db.backup"].create(vals)
def test_local(self): def test_local(self):
"""A local database is backed up.""" """A local database is backed up."""
filename = self.abk.filename(datetime.now())
self.abk.action_backup()
generated_backup = [f for f in os.listdir(self.abk.folder)
rec_id = self.new_record('local')
filename = rec_id.filename(datetime.now())
rec_id.action_backup()
generated_backup = [f for f in os.listdir(rec_id.folder)
if f >= filename] if f >= filename]
self.assertEqual(len(generated_backup), 1)
self.assertEqual(1, len(generated_backup))
def test_compute_name_sftp(self):
""" It should create proper SFTP URI """
rec_id = self.new_record()
self.assertEqual(
'sftp://%(user)@%(host):%(port)%(folder)' % {
'user': self.vals['sftp_user'],
'host': self.vals['sftp_host'],
'port': self.vals['sftp_port'],
'folder': self.vals['folder'],
},
rec_id.name,
)
def test_check_folder(self):
""" It should not allow recursive backups """
rec_id = self.new_record()
with self.assertRaises(exceptions.ValidationError):
rec_id.write({
'folder': '%s/another/path' % tools.config.filestore(
self.env.cr.dbname
),
})

7
auto_backup/view/db_backup_view.xml

@ -1,6 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<openerp>
<data>
<odoo>
<record model="ir.ui.view" id="view_backup_conf_form"> <record model="ir.ui.view" id="view_backup_conf_form">
<field name="name">Automated Backups</field> <field name="name">Automated Backups</field>
@ -104,5 +103,5 @@
<field name="model">db.backup</field> <field name="model">db.backup</field>
<field name="key2">client_action_multi</field> <field name="key2">client_action_multi</field>
</record> </record>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save