Files
odoo_source/addons/website/tests/test_attachment.py
T
Xavier Morel 80896a0bf3 [FIX] core: chrome doesn't abide by --http-port anymore
An http-port provided on the command line (may also have been an issue
for config files, didn't check) would not be taken in account anymore,
because `odoo.tests.common` would be imported during the import of
`odoo` itself (when loading odoo.service.server), itself importing
`odoo.tools.config` leading to a default configuration being set up.

* remove `odoo.tests.common.PORT`, `config['http_port']` should be
  used always
* defer the import of odoo.tests.common by moving it inside
  load_test_file
* stop generating default configs

closes odoo/odoo#43283

X-original-commit: 45871f498ea4cf3ada719692e69cd413883ab442
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-01-14 13:15:04 +00:00

52 lines
1.6 KiB
Python

import odoo.tests
from odoo.tests.common import HOST
from odoo.tools import config
@odoo.tests.common.tagged('post_install', '-at_install')
class TestWebsiteAttachment(odoo.tests.HttpCase):
def test_01_type_url_301_image(self):
IMD = self.env['ir.model.data']
IrAttachment = self.env['ir.attachment']
img1 = IrAttachment.create({
'public': True,
'name': 's_banner_default_image.jpg',
'type': 'url',
'url': '/website/static/src/img/snippets_demo/s_banner.jpg'
})
img2 = IrAttachment.create({
'public': True,
'name': 's_banner_default_image.jpg',
'type': 'url',
'url': '/web/image/test.an_image_url'
})
IMD.create({
'name': 'an_image_url',
'module': 'test',
'model': img1._name,
'res_id': img1.id,
})
IMD.create({
'name': 'an_image_redirect_301',
'module': 'test',
'model': img2._name,
'res_id': img2.id,
})
req = self.url_open('/web/image/test.an_image_url')
self.assertEqual(req.status_code, 200)
base = "http://%s:%s" % (HOST, config['http_port'])
req = self.opener.get(base + '/web/image/test.an_image_redirect_301', allow_redirects=False)
self.assertEqual(req.status_code, 301)
self.assertEqual(req.headers['Location'], base + '/web/image/test.an_image_url')
req = self.opener.get(base + '/web/image/test.an_image_redirect_301', allow_redirects=True)
self.assertEqual(req.status_code, 200)