summaryrefslogtreecommitdiff
path: root/addons/website/tests/test_attachment.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website/tests/test_attachment.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website/tests/test_attachment.py')
-rw-r--r--addons/website/tests/test_attachment.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/addons/website/tests/test_attachment.py b/addons/website/tests/test_attachment.py
new file mode 100644
index 00000000..17359eb7
--- /dev/null
+++ b/addons/website/tests/test_attachment.py
@@ -0,0 +1,51 @@
+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)