Browse Source

[MIG] auto_backup: Migrate to v9

* Add self.ensure_ones
* Add test coverage
pull/614/head
Dave Lasley 8 years ago
parent
commit
a385974fc8
No known key found for this signature in database GPG Key ID: 7DDBA4BA81B934CF
  1. 12
      auto_backup/README.rst
  2. 5
      auto_backup/__openerp__.py
  3. 4
      auto_backup/models/db_backup.py
  4. 53
      auto_backup/tests/test_auto_backup.py
  5. 7
      auto_backup/view/db_backup_view.xml
  6. 1
      requirements.txt

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
: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
===========
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
=======
@ -89,6 +90,7 @@ Contributors
* Yenthe Van Ginneken <yenthe.vanginneken@vanroey.be>
* Alessio Gerace <alessio.gerace@agilebg.com>
* Jairo Llopis <yajo.sk8@gmail.com>
* Dave Lasley <dave@laslabs.com>
Maintainer
----------

5
auto_backup/__openerp__.py

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

4
auto_backup/models/db_backup.py

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

53
auto_backup/tests/test_auto_backup.py

@ -2,27 +2,62 @@
# © 2015 Agile Business Group <http://www.agilebg.com>
# © 2015 Alessio Gerace <alesiso.gerace@agilebg.com>
# © 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).
import os
from datetime import datetime
from openerp.tests import common
from openerp import exceptions, tools
class TestsAutoBackup(common.TransactionCase):
def setUp(self):
super(TestsAutoBackup, self).setUp()
self.abk = self.env["db.backup"].create(
{
'name': u'Têst backup',
}
)
def new_record(self, method='sftp'):
vals = {
'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):
"""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]
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"?>
<openerp>
<data>
<odoo>
<record model="ir.ui.view" id="view_backup_conf_form">
<field name="name">Automated Backups</field>
@ -104,5 +103,5 @@
<field name="model">db.backup</field>
<field name="key2">client_action_multi</field>
</record>
</data>
</openerp>
</odoo>

1
requirements.txt

@ -3,3 +3,4 @@ unidecode
acme_tiny
IPy
validate_email
pysftp
Loading…
Cancel
Save