Add implementation of reading writing on the Swift object store

This commit is contained in:
Thierry Ducrest
2017-08-30 09:01:00 +02:00
parent 017e1c7bd9
commit beea07d44f
4 changed files with 159 additions and 4 deletions
+33
View File
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import unittest
from odoo.addons.base.tests.test_ir_attachment import TestIrAttachment
from ..models import ir_attachment
from ..swift_uri import SwiftUri
from swiftclient.exceptions import ClientException
class TestAttachmentSwift(TestIrAttachment):
def setup(self):
super(TestAttachmentSwift, self).setUp()
self.env['ir.config_parameter'].set_param('ir_attachment.location', 'swift')
def test_connection(self):
""" Test the connection to the Swift object store """
conn = self.Attachment._get_swift_connection()
self.assertNotEquals(conn, False)
def test_store_file_on_swift(self):
a5 = self.Attachment.create({'name': 'a5', 'datas': self.blob1_b64})
a5bis = self.Attachment.browse(a5.id)[0]
def test_delete_file_on_swift(self):
self.env['ir.config_parameter'].set_param('ir_attachment.location', 'swift')
a5 = self.Attachment.create({'name': 'a5', 'datas': self.blob1_b64})
uri = SwiftUri(a5.store_fname)
con = self.Attachment._get_swift_connection()
data = con.get_object(uri.container(), uri.item())
a5.unlink()
with self.assertRaises(ClientException):
con.get_object(uri.container(), uri.item())