# -*- 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())