Skip to content

Commit

Permalink
[IMP] moved setUp to setUpClass in TestIrHttp
Browse files Browse the repository at this point in the history
To avoid creation and re-creation of records for each test run
  • Loading branch information
NICO-SOLUTIONS committed Nov 27, 2023
1 parent 9e2174f commit b7936ee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion website_require_login/data/ir_actions.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="action_website_auth_url" model="ir.actions.act_window">
Expand Down
1 change: 0 additions & 1 deletion website_require_login/data/ir_ui_menu.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<menuitem
Expand Down
23 changes: 12 additions & 11 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 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",
)

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
1 change: 0 additions & 1 deletion website_require_login/views/website_auth_url.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="website_auth_url_tree_view" model="ir.ui.view">
Expand Down

0 comments on commit b7936ee

Please sign in to comment.