| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
import base64 |
| 4 |
import os |
| 5 |
import socket |
| 6 |
|
| 7 |
from odoorpc.tests import LoginTestCase |
| 8 |
|
| 9 |
|
| 10 |
class TestTimeout(LoginTestCase): |
| 11 |
@classmethod |
| 12 |
def setUpClass(cls): |
| 13 |
LoginTestCase.setUpClass() |
| 14 |
dummy_file = os.urandom(1024 ** 2 * 50) # 50 MB |
| 15 |
b64_data = str(base64.b64encode(dummy_file)) |
| 16 |
cls.attachment_values = {"name": "TEST", "datas": b64_data} |
| 17 |
|
| 18 |
def test_increased_timeout(self): |
| 19 |
# Set the timeout |
| 20 |
self.odoo.config['timeout'] = 120 |
| 21 |
# Execute a time consuming query: no exception |
| 22 |
self.odoo.env["ir.attachment"].create(self.attachment_values) |
| 23 |
|
| 24 |
def test_reduced_timeout(self): |
| 25 |
# partner_model = self.odoo.env["res.partner"] |
| 26 |
attachment_model = self.odoo.env["ir.attachment"] |
| 27 |
# Set the timeout |
| 28 |
self.odoo.config['timeout'] = 0.5 |
| 29 |
# Execute a time consuming query: handle exception |
| 30 |
self.assertRaises( |
| 31 |
socket.timeout, attachment_model.create, self.attachment_values |
| 32 |
) |
| 33 |
|
| 34 |
def tearDown(self): |
| 35 |
self.odoo.config["timetout"] = 120 |