Skip to content

Commit

Permalink
[MIG] website_require_login: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NICO-SOLUTIONS committed Nov 27, 2023
1 parent 9fd4572 commit 3629c6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion website_require_login/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Website Login Required",
"category": "Website",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"author": "Advitus MB, Ooops, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/website",
"license": "LGPL-3",
Expand Down
1 change: 1 addition & 0 deletions website_require_login/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Ooops404 <https://ooops404.com>
* Nils Coenen <nils.coenen@nico.solutions.de>
29 changes: 15 additions & 14 deletions website_require_login/tests/test_ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@


class TestIrHttp(HttpCase):
def setUp(self):
super().setUp()
self.website = self.env["website"].sudo().get_current_website()
self.auth_url = self.env["website.auth.url"].create(
{"website_id": self.website.id, "path": "/contactus"}
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.website = cls.env["website"].sudo().get_current_website()
cls.auth_url = cls.env["website.auth.url"].create(
{"website_id": cls.website.id, "path": "/contactus"}
)
self.user = self.env["res.users"].create(
cls.user = cls.env["res.users"].create(
{"name": "Test User", "login": "test_user", "password": "12345"}
)
self.path = "/contactus"
self.expected_path = "/web/login?redirect=%s" % self.path
cls.path = "/contactus"
cls.expected_path = "/web/login?redirect=%s" % cls.path

def test_dispatch_unauthorized(self):
# Test that an unauthorized user cannot access "/auth_path
# Test that a public user cannot access "/auth_path
self.authenticate(None, None)
response = self.url_open(self.path, allow_redirects=False)
response = self.url_open(self.__class__.path, allow_redirects=False)
self.assertEqual(
response.status_code,
302,
"Expected the response status code to be 302 indicating a redirect",
303,
"Expected the response status code to be 303 indicating a redirect",
)

self.assertIn(self.expected_path, response.headers["Location"])
self.assertIn(self.__class__.expected_path, response.headers["Location"])

def test_dispatch_authorized(self):
# Test that an authorized user can access "/auth_path
self.authenticate(user="test_user", password="12345")
response = self.url_open(self.path)
response = self.url_open(self.__class__.path)
self.assertEqual(
response.status_code,
200,
Expand Down
2 changes: 1 addition & 1 deletion website_require_login/views/website_auth_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="name">website.auth.url</field>
<field name="model">website.auth.url</field>
<field name="arch" type="xml">
<tree string="Authorization required URLs" editable="bottom">
<tree editable="bottom">
<field name="website_id" />
<field name="path" />
</tree>
Expand Down

0 comments on commit 3629c6e

Please sign in to comment.