|
3 | 3 | from imio.pm.wsclient.browser import vocabularies
|
4 | 4 | from imio.pm.wsclient.tests.WS4PMCLIENTTestCase import WS4PMCLIENTTestCase
|
5 | 5 | from mock import patch
|
6 |
| -from natsort import humansorted |
7 | 6 | from plone import api
|
8 | 7 | from WS4PMCLIENTTestCase import setCorrectSettingsConfig
|
9 | 8 | from zope.component import getMultiAdapter
|
| 9 | +from zope.globalrequest import getRequest |
| 10 | +from zope.globalrequest import setRequest |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class testVocabularies(WS4PMCLIENTTestCase):
|
@@ -35,6 +36,10 @@ def test_desired_meetingdates_vocabulary(self, _rest_getMeetingsAcceptingItems,
|
35 | 36 | {"id": u"plonegov-assembly", "title": u"PloneGov Assembly"},
|
36 | 37 | {"id": u"plonemeeting-assembly", "title": u"PloneMeeting Assembly"},
|
37 | 38 | ]
|
| 39 | + |
| 40 | + request = getRequest() |
| 41 | + request.set("meetingConfigId", u"plonemeeting-assembly") |
| 42 | + setRequest(request) |
38 | 43 | _rest_getMeetingsAcceptingItems.return_value = [
|
39 | 44 | {
|
40 | 45 | u"@extra_includes": [],
|
@@ -65,10 +70,40 @@ def test_desired_meetingdates_vocabulary(self, _rest_getMeetingsAcceptingItems,
|
65 | 70 | u"date": u"2013-03-03T00:00:00",
|
66 | 71 | },
|
67 | 72 | ]
|
| 73 | + raw_voc = vocabularies.desired_meetingdates_vocabularyFactory(api.portal.get()) |
| 74 | + self.assertEqual(len(raw_voc), 2) |
68 | 75 |
|
| 76 | + # Test that the cache is used if the request did not change |
| 77 | + # This example should not happen in real life, but it is a good test |
| 78 | + _rest_getMeetingsAcceptingItems.return_value = [ |
| 79 | + { |
| 80 | + u"@extra_includes": [], |
| 81 | + u"@id": u"http://localhost:63033/plone/Members/pmManager/mymeetings/plonegov-assembly/o1", # noqa |
| 82 | + u"@type": u"MeetingPma", |
| 83 | + u"UID": u"89ada78808d04a04b145518b2a469f2a", |
| 84 | + u"created": u"2022-08-13T11:47:33+00:00", |
| 85 | + u"description": u"", |
| 86 | + u"enabled": None, |
| 87 | + u"id": u"o1", |
| 88 | + u"modified": u"2022-08-13T11:47:34+00:00", |
| 89 | + u"review_state": u"created", |
| 90 | + u"title": u"03 march 2013", |
| 91 | + u"date": u"2013-08-03T00:00:00", |
| 92 | + }, |
| 93 | + ] |
69 | 94 | raw_voc = vocabularies.desired_meetingdates_vocabularyFactory(api.portal.get())
|
70 | 95 | self.assertEqual(len(raw_voc), 2)
|
71 | 96 |
|
| 97 | + # Test cache is not used if the request changed |
| 98 | + request = getRequest() |
| 99 | + request.set("meetingConfigId", u"plonegov-assembly") |
| 100 | + setRequest(request) |
| 101 | + raw_voc = vocabularies.desired_meetingdates_vocabularyFactory(api.portal.get()) |
| 102 | + self.assertEqual(len(raw_voc), 1) |
| 103 | + self.assertEqual(list(raw_voc)[0].title, u"03/08/2013 00:00") |
| 104 | + self.assertEqual(list(raw_voc)[0].value, "89ada78808d04a04b145518b2a469f2a") |
| 105 | + self.assertEqual(list(raw_voc)[0].token, "89ada78808d04a04b145518b2a469f2a") |
| 106 | + |
72 | 107 | @patch("imio.pm.wsclient.browser.settings.WS4PMClientSettings._rest_getConfigInfos")
|
73 | 108 | def test_categories_for_user_vocabulary(self, _rest_getConfigInfos):
|
74 | 109 | """Ensure that vocabularies values are the expected"""
|
|
0 commit comments