Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_current_account: catch exception when portal cannot be found. #757

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions src/euphorie/client/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from AccessControl.PermissionRole import _what_not_even_god_should_do
from AccessControl.users import nobody
from AccessControl.users import SimpleUser
from datetime import timedelta
from euphorie.client import config
from euphorie.client import model
Expand Down Expand Up @@ -291,7 +293,12 @@ def testHasSurveyViewPermission(self):
self.assertEqual(user.has_permission("Euphorie: View a Survey", None), True)

def testAccountType(self):
(self.session, self.survey) = createSurvey()
# We know of a third-party package that has an event handler for when
# a survey is created. This calls euphorie.client.model.get_current,
# which cannot get the current user because there is no portal in this
# unit test. Use a mock to prevent an error.
with mock.patch("plone.api.user.get_current", return_value=nobody):
(self.session, self.survey) = createSurvey()
account = self.survey.account
self.assertEqual(account.account_type, config.FULL_ACCOUNT)
account.account_type = config.GUEST_ACCOUNT
Expand Down Expand Up @@ -385,16 +392,19 @@ def testSessions(self):
session.add(account1)
account1.group = group1
group2.parent = group1
session.flush()
from functools import partial

add_survey = partial(model.SurveySession, account=account1)
survey1 = add_survey(zodb_path="1")
session.add(survey1)
survey2 = add_survey(zodb_path="2", group=group1)
session.add(survey2)
survey3 = add_survey(zodb_path="3", group=group2)
session.add(survey3)
session.flush()
user1 = SimpleUser(str(account1.id), "", ("Member",), [])
with mock.patch("plone.api.user.get_current", return_value=user1):
add_survey = partial(model.SurveySession, account=account1)
survey1 = add_survey(zodb_path="1")
session.add(survey1)
survey2 = add_survey(zodb_path="2", group=group1)
session.add(survey2)
survey3 = add_survey(zodb_path="3", group=group2)
session.add(survey3)
session.flush()
self.assertListEqual(account1.sessions, [survey1, survey2, survey3])
self.assertListEqual(group1.sessions, [survey2])
self.assertListEqual(group2.sessions, [survey3])
Expand All @@ -414,18 +424,21 @@ def testSessionAcquisition(self):
account2 = model.Account(loginname="account2")
session.add(account2)
account2.group = group2
survey1 = model.SurveySession(
account=account1,
group=group1,
zodb_path="1",
)
session.add(survey1)
survey2 = model.SurveySession(
account=account2,
group=group2,
zodb_path="2",
)
session.add(survey2)
session.flush()
user1 = SimpleUser(str(account1.id), "", ("Member",), [])
with mock.patch("plone.api.user.get_current", return_value=user1):
survey1 = model.SurveySession(
account=account1,
group=group1,
zodb_path="1",
)
session.add(survey1)
survey2 = model.SurveySession(
account=account2,
group=group2,
zodb_path="2",
)
session.add(survey2)
session.flush()
self.assertListEqual(account1.sessions, [survey1])
self.assertListEqual(account2.sessions, [survey2])
Expand Down
Loading