summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Mihai <smihai@entrouvert.com>2018-05-14 16:46:01 (GMT)
committerSerghei Mihai <smihai@entrouvert.com>2019-02-04 20:25:43 (GMT)
commitb007d69d8ed0bec09b098a40d3006788dbde2176 (patch)
treede246c3ce8e1335398c5e8f1e592020419e1377d
parent5776fe1fa7d45d84612b9b4f7404487d344ba7ff (diff)
downloadcombo-wip/23717-external-user-demands-retrieval.zip
combo-wip/23717-external-user-demands-retrieval.tar.gz
combo-wip/23717-external-user-demands-retrieval.tar.bz2
misc: enable user demands retrieval from external services (#23717)wip/23717-external-user-demands-retrieval
-rw-r--r--combo/apps/wcs/utils.py8
-rw-r--r--combo/settings.py3
-rw-r--r--tests/test_external_demands_services.py105
3 files changed, 113 insertions, 3 deletions
diff --git a/combo/apps/wcs/utils.py b/combo/apps/wcs/utils.py
index d38b054..de35fc4 100644
--- a/combo/apps/wcs/utils.py
+++ b/combo/apps/wcs/utils.py
@@ -22,9 +22,11 @@ def is_wcs_enabled(cls):
return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('wcs')
def get_wcs_services():
- if not is_wcs_enabled(None):
- return {}
- return settings.KNOWN_SERVICES.get('wcs')
+ # initialize with external demands services
+ services = settings.EXTERNAL_DEMANDS_SERVICES.copy()
+ if is_wcs_enabled(None):
+ services.update(settings.KNOWN_SERVICES.get('wcs'))
+ return services
def get_wcs_json(wcs_site, path):
response = requests.get(path, remote_service=wcs_site, without_user=True,
diff --git a/combo/settings.py b/combo/settings.py
index 8823a42..6adf39c 100644
--- a/combo/settings.py
+++ b/combo/settings.py
@@ -333,6 +333,9 @@ BOOKING_CALENDAR_CELL_ENABLED = False
NEWSLETTERS_CELL_ENABLED = False
USERSEARCH_CELL_ENABLED = False
+# external services with user demands
+EXTERNAL_DEMANDS_SERVICES = {}
+
local_settings_file = os.environ.get('COMBO_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
if os.path.exists(local_settings_file):
diff --git a/tests/test_external_demands_services.py b/tests/test_external_demands_services.py
new file mode 100644
index 0000000..2231efa
--- /dev/null
+++ b/tests/test_external_demands_services.py
@@ -0,0 +1,105 @@
+# -*- coding: utf-8 -*-
+
+import mock
+import pytest
+import re
+
+from django.test import override_settings
+
+from combo.data.models import Page
+from combo.apps.wcs.models import WcsCurrentFormsCell
+
+from .test_manager import login
+
+pytestmark = pytest.mark.django_db
+
+ARPEGE_WS = {
+ "title": "Portal Arpege",
+ "url": "https://example.com/arpege-ecp/arpege"
+}
+
+@override_settings(EXTERNAL_DEMANDS_SERVICES={'arpege': ARPEGE_WS})
+@mock.patch('combo.utils.requests.get')
+def test_manager_external_services(mock_get, app, admin_user):
+ page = Page(title='External demands', slug='external-demands', template_name='standard')
+ page.save()
+ app = login(app)
+ mock_response = mock.Mock(status_code=200, content="{}")
+ mock_get.return_value = mock_response
+ resp = app.get('/manage/pages/%s/' % page.id)
+
+ resp = app.get(resp.html.find('option',
+ **{'data-add-url': re.compile('wcscurrentformscell')})['data-add-url'])
+
+ cells = Page.objects.get(id=page.id).get_cells()
+ assert len(cells) == 1
+ assert isinstance(cells[0], WcsCurrentFormsCell)
+
+ categories_response = mock.Mock(status_code=200)
+ categories_response.json.return_value = {'data': []}
+ mock_get.return_value = categories_response
+
+ resp = app.get('/manage/pages/%s/' % page.id)
+ assert ('data-cell-reference="%s"' % cells[0].get_reference()) in resp.text
+ field_name = "c%s-wcs_site" % cells[0].get_reference()
+ assert len(resp.form.fields[field_name][0].options) == 4
+ # external service is second and not selected
+ assert resp.form.fields[field_name][0].options[1] == ('arpege', False, 'Portal Arpege')
+
+
+@override_settings(EXTERNAL_DEMANDS_SERVICES={'arpege': ARPEGE_WS})
+@mock.patch('combo.utils.requests.get')
+def test_external_demands(mock_get, app, admin_user):
+ Page.objects.all().delete()
+ page = Page(title='One', slug='one', template_name='standard')
+ page.save()
+ app = login(app)
+ resp = app.get('/manage/pages/%s/' % page.id)
+ resp = app.get(resp.html.find('option',
+ **{'data-add-url': re.compile('wcscurrentformscell')})['data-add-url'])
+ resp = app.get('/manage/pages/%s/' % page.id)
+ cells = Page.objects.get(id=page.id).get_cells()
+ field_name = "c%s-wcs_site" % cells[0].get_reference()
+ resp.form[field_name].value = 'arpege'
+ resp = resp.form.submit().follow()
+ assert resp.form.fields[field_name][0].options[1] == ('arpege', True, 'Portal Arpege')
+ demands_response = mock.Mock(status_code=200)
+ demands_response.json.return_value = {'data': [
+ {'url': 'https://example.com/demand/1',
+ 'name': 'First Demand',
+ 'title': 'First Demand',
+ 'status': 'In progress',
+ 'form_receipt_time': '10:00',
+ 'readable': True,
+ 'form_receipt_datetime': '2019-02-04T10:00',
+ 'form_status_is_endpoint': False},
+ {'url': 'https://example.com/demand/2',
+ 'name': 'Second Demand',
+ 'title': 'Second Demand',
+ 'status': 'Finished',
+ 'readable': True,
+ 'form_receipt_time': '09:00',
+ 'form_receipt_datetime': '2019-02-04T09:00',
+ 'form_status_is_endpoint': True}
+ ]}
+ mock_get.return_value = demands_response
+ resp = app.get(page.get_online_url())
+ cell_url = re.findall(r'/ajax/cell/.*/wcs_wcscurrentformscell-.*/', resp.text)[0]
+ resp = app.get(cell_url)
+ assert "First Demand" in resp.text
+ assert "In progress" in resp.text
+ assert "https://example.com/demand/1" in resp.text
+
+ assert "Second Demand" not in resp.text
+ assert "Finished" not in resp.text
+ assert "https://example.com/demand/2" not in resp.text
+
+ # also show done demands
+ resp = app.get('/manage/pages/%s/' % page.id)
+ resp.form['c%s-done_forms' % cells[0].get_reference()].value = True
+ resp = resp.form.submit().follow()
+ resp = app.get(cell_url)
+
+ assert "Second Demand" in resp.text
+ assert "Finished" in resp.text
+ assert "https://example.com/demand/2" in resp.text