forked from camptocamp/odoo-cloud-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import tests | ||
from . import test_mock_swift_api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
import os | ||
|
||
from mock import patch | ||
from odoo.addons.base.tests.test_ir_attachment import TestIrAttachment | ||
from ..swift_uri import SwiftUri | ||
|
||
|
||
class TestAttachmentSwift(TestIrAttachment): | ||
|
||
def setup(self): | ||
super(TestAttachmentSwift, self).setUp() | ||
self.env['ir.config_parameter'].set_param('ir_attachment.location', | ||
'swift') | ||
|
||
@patch('swiftclient.client') | ||
def test_connection(self, mock_swift_client): | ||
""" Test the connection to the store""" | ||
os.environ['SWIFT_AUTH_URL'] = 'auth_url' | ||
os.environ['SWIFT_ACCOUNT'] = 'account' | ||
os.environ['SWIFT_PASSWORD'] = 'password' | ||
os.environ['SWIFT_TENANT_NAME'] = 'tenant_name' | ||
attachment = self.Attachment | ||
attachment._get_swift_connection() | ||
mock_swift_client.Connection.assert_called_once_with( | ||
authurl=os.environ.get('SWIFT_AUTH_URL'), | ||
user=os.environ.get('SWIFT_ACCOUNT'), | ||
key=os.environ.get('SWIFT_PASSWORD'), | ||
tenant_name=os.environ.get('SWIFT_TENANT_NAME'), | ||
auth_version='2.0' | ||
) | ||
|
||
def test_store_file_on_swift(self): | ||
""" | ||
Test writing a file | ||
""" | ||
(self.env['ir.config_parameter']. | ||
set_param('ir_attachment.location', 'swift')) | ||
os.environ['SWIFT_AUTH_URL'] = 'auth_url' | ||
os.environ['SWIFT_ACCOUNT'] = 'account' | ||
os.environ['SWIFT_PASSWORD'] = 'password' | ||
os.environ['SWIFT_TENANT_NAME'] = 'tenant_name' | ||
container = os.environ.get('SWIFT_WRITE_CONTAINER') | ||
attachment = self.Attachment | ||
bin_data = self.blob1_b64.decode('base64') | ||
with patch('swiftclient.client.Connection') as MockConnection: | ||
conn = MockConnection.return_value | ||
attachment.create({'name': 'a5', 'datas': self.blob1_b64}) | ||
conn.put_object.assert_called_with( | ||
container, | ||
attachment._compute_checksum(bin_data), | ||
bin_data) | ||
|
||
def test_delete_file_on_swift(self): | ||
""" | ||
Test deleting a file | ||
""" | ||
(self.env['ir.config_parameter']. | ||
set_param('ir_attachment.location', 'swift')) | ||
os.environ['SWIFT_AUTH_URL'] = 'auth_url' | ||
os.environ['SWIFT_ACCOUNT'] = 'account' | ||
os.environ['SWIFT_PASSWORD'] = 'password' | ||
os.environ['SWIFT_TENANT_NAME'] = 'tenant_name' | ||
attachment = self.Attachment | ||
container = os.environ.get('SWIFT_WRITE_CONTAINER') | ||
with patch('swiftclient.client.Connection') as MockConnection: | ||
conn = MockConnection.return_value | ||
a5 = attachment.create({'name': 'a5', 'datas': self.blob1_b64}) | ||
uri = SwiftUri(a5.store_fname) | ||
a5.unlink() | ||
conn.delete_object.assert_called_with(container, uri.item()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters