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

Fixed missing categories when 'sending to college' in iA.Docs #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/imio/pm/wsclient/browser/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __call__(self, context):
# find categories for given meetingConfigId
for configInfo in configInfos:
if configInfo["id"] == meetingConfigId:
categories = hasattr(configInfo, 'categories') and configInfo.categories or ()
categories = configInfo.get('categories', ())
break
# if not categories is returned, it means that the meetingConfig does
# not use categories...
Expand Down
55 changes: 50 additions & 5 deletions src/imio/pm/wsclient/tests/testVocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from imio.pm.wsclient.browser import vocabularies
from imio.pm.wsclient.tests.WS4PMCLIENTTestCase import WS4PMCLIENTTestCase
from plone import api

from mock import patch
from plone import api
from WS4PMCLIENTTestCase import setCorrectSettingsConfig
from zope.component import getMultiAdapter


class testVocabularies(WS4PMCLIENTTestCase):
Expand All @@ -27,9 +28,7 @@ def test_pm_meeting_config_id_vocabulary(self, _rest_getConfigInfos):

@patch("imio.pm.wsclient.browser.settings.WS4PMClientSettings._rest_getConfigInfos")
@patch("imio.pm.wsclient.browser.settings.WS4PMClientSettings._rest_getMeetingsAcceptingItems") # noqa
def test_desired_meetingdates_vocabulary(
self, _rest_getMeetingsAcceptingItems, _rest_getConfigInfos
):
def test_desired_meetingdates_vocabulary(self, _rest_getMeetingsAcceptingItems, _rest_getConfigInfos):
"""Ensure that vocabularies values are the expected"""
_rest_getConfigInfos.return_value = [
{"id": u"plonegov-assembly", "title": u"PloneGov Assembly"},
Expand Down Expand Up @@ -68,3 +67,49 @@ def test_desired_meetingdates_vocabulary(

raw_voc = vocabularies.desired_meetingdates_vocabularyFactory(api.portal.get())
self.assertEqual(len(raw_voc), 2)

@patch("imio.pm.wsclient.browser.settings.WS4PMClientSettings._rest_getConfigInfos")
def test_categories_for_user_vocabulary(self, _rest_getConfigInfos):
chris-adam marked this conversation as resolved.
Show resolved Hide resolved
"""Ensure that vocabularies values are the expected"""

def set_config():
setCorrectSettingsConfig(self.portal, setConnectionParams=False, withValidation=False)
ws4pmsettings = getMultiAdapter((self.portal, self.portal.REQUEST), name="ws4pmclient-settings")
for i in range(len(ws4pmsettings.settings().field_mappings)):
if ws4pmsettings.settings().field_mappings[i]["field_name"] == "category":
del ws4pmsettings.settings().field_mappings[i]
break
raw_voc = vocabularies.categories_for_user_vocabulary()
titles = [v.title for v in raw_voc(self.portal)]
tokens = [v.token for v in raw_voc(self.portal)]
return titles, tokens

self.portal.REQUEST.set("meetingConfigId", u"plonegov-assembly")

_rest_getConfigInfos.return_value = [
{
"id": u"plonegov-assembly",
"title": u"PloneGov Assembly",
"categories": [
{
"id": "urbanisme",
"title": "Urbanisme",
"enabled": True,
},
{
"id": "finances",
"title": "Finances",
"enabled": True,
},
],
},
{"id": u"plonemeeting-assembly", "title": u"PloneMeeting Assembly"},
]
titles, tokens = set_config()
self.assertIn(u"Urbanisme", titles)
self.assertIn(u"urbanisme", tokens)

_rest_getConfigInfos.return_value = []
titles, tokens = set_config()
self.assertEqual(titles, [])
self.assertEqual(tokens, [])
Loading