7 |
7 |
import requests
|
8 |
8 |
import subprocess
|
9 |
9 |
import shutil
|
|
10 |
import sys
|
10 |
11 |
import tempfile
|
11 |
12 |
import time
|
12 |
13 |
import os
|
... | ... | |
31 |
32 |
|
32 |
33 |
pytestmark = pytest.mark.django_db
|
33 |
34 |
|
34 |
|
wcsctl_present = pytest.mark.skipif('WCSCTL' not in os.environ or not os.path.exists(os.environ['WCSCTL']),
|
35 |
|
reason='WCSCTL not defined in environment')
|
|
35 |
wcs_present = pytest.mark.skipif('WCS_MANAGE' not in os.environ or not os.path.exists(os.environ['WCS_MANAGE']),
|
|
36 |
reason='WCS_MANAGE not defined in environment')
|
36 |
37 |
|
37 |
|
WCSCTL = os.environ.get('WCSCTL')
|
|
38 |
WCS_MANAGE = os.environ.get('WCS_MANAGE')
|
38 |
39 |
|
39 |
40 |
WCS_SCRIPTS = {
|
40 |
41 |
'setup-auth': """
|
... | ... | |
184 |
185 |
fd = open(script_path, 'w')
|
185 |
186 |
fd.write(WCS_SCRIPTS[script])
|
186 |
187 |
fd.close()
|
187 |
|
subprocess.check_call([WCSCTL, 'runscript', '--app-dir', WCS_DIR,
|
188 |
|
'--vhost', hostname, script_path])
|
|
188 |
subprocess.check_call([sys.executable, WCS_MANAGE, 'runscript', '--app-dir', WCS_DIR,
|
|
189 |
'--vhost', hostname, script_path],
|
|
190 |
env={'DJANGO_SETTINGS_MODULE': 'wcs.settings'})
|
189 |
191 |
|
190 |
192 |
|
191 |
193 |
def setup_module(module):
|
192 |
194 |
global WCS_PID
|
193 |
195 |
|
194 |
|
if not WCSCTL:
|
|
196 |
if not WCS_MANAGE:
|
195 |
197 |
return
|
196 |
198 |
|
197 |
199 |
for hostname in ['127.0.0.1', '127.0.0.2']:
|
... | ... | |
220 |
222 |
|
221 |
223 |
WCS_PID = os.fork()
|
222 |
224 |
if not WCS_PID:
|
223 |
|
os.chdir(os.path.dirname(WCSCTL))
|
|
225 |
os.chdir(os.path.dirname(WCS_MANAGE))
|
224 |
226 |
os.environ['DJANGO_SETTINGS_MODULE'] = 'wcs.settings'
|
225 |
227 |
os.environ['WCS_SETTINGS_FILE'] = os.path.join(WCS_DIR, 'local_settings.py')
|
226 |
|
os.execvp('python', ['python', 'manage.py', 'runserver', '--noreload', '0.0.0.0:8999'])
|
|
228 |
os.execvp('python', [sys.executable, 'manage.py', 'runserver', '--noreload', '0.0.0.0:8999'])
|
227 |
229 |
sys.exit(0)
|
228 |
230 |
|
229 |
231 |
time.sleep(5)
|
... | ... | |
251 |
253 |
ctx['request'].session = {}
|
252 |
254 |
return ctx
|
253 |
255 |
|
254 |
|
@wcsctl_present
|
|
256 |
@wcs_present
|
255 |
257 |
def test_form_cell_setup():
|
256 |
258 |
cell = WcsFormCell()
|
257 |
259 |
form_class = cell.get_default_form_class()
|
... | ... | |
267 |
269 |
(u'other:third-form-title', u'test2 : third form title')]
|
268 |
270 |
|
269 |
271 |
|
270 |
|
@wcsctl_present
|
|
272 |
@wcs_present
|
271 |
273 |
def test_form_cell_save_cache():
|
272 |
274 |
page = Page(title='xxx', slug='test_form_cell_save_cache', template_name='standard')
|
273 |
275 |
page.save()
|
... | ... | |
295 |
297 |
appconfig.update_db_cache()
|
296 |
298 |
assert WcsFormCell.objects.get(id=cell.id).cached_title == 'form title'
|
297 |
299 |
|
298 |
|
@wcsctl_present
|
|
300 |
@wcs_present
|
299 |
301 |
def test_form_cell_load():
|
300 |
302 |
page = Page(title='xxx', slug='test_form_cell_save_cache', template_name='standard')
|
301 |
303 |
page.save()
|
... | ... | |
313 |
315 |
assert cell.cached_title == 'form title'
|
314 |
316 |
|
315 |
317 |
|
316 |
|
@wcsctl_present
|
|
318 |
@wcs_present
|
317 |
319 |
def test_category_cell_save_cache():
|
318 |
320 |
page = Page(title='xxx', slug='test_category_cell_save_cache', template_name='standard')
|
319 |
321 |
page.save()
|
... | ... | |
324 |
326 |
assert cell.cached_title == 'Test 3'
|
325 |
327 |
assert cell.get_additional_label() == 'Test 3'
|
326 |
328 |
|
327 |
|
@wcsctl_present
|
|
329 |
@wcs_present
|
328 |
330 |
def test_form_cell_render():
|
329 |
331 |
page = Page(title='xxx', slug='test_form_cell_render', template_name='standard')
|
330 |
332 |
page.save()
|
... | ... | |
335 |
337 |
assert 'http://127.0.0.1:8999/form-title/tryauth' in result
|
336 |
338 |
assert 'form title' in result
|
337 |
339 |
|
338 |
|
@wcsctl_present
|
|
340 |
@wcs_present
|
339 |
341 |
def test_current_forms_cell_setup():
|
340 |
342 |
cell = WcsCurrentFormsCell()
|
341 |
343 |
form_class = cell.get_default_form_class()
|
... | ... | |
356 |
358 |
cell.done_forms = True
|
357 |
359 |
assert cell.get_additional_label() == 'All Sites - Done Forms'
|
358 |
360 |
|
359 |
|
@wcsctl_present
|
|
361 |
@wcs_present
|
360 |
362 |
def test_current_forms_cell_render(context):
|
361 |
363 |
page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard')
|
362 |
364 |
page.save()
|
... | ... | |
418 |
420 |
extra_context = cell.get_cell_extra_context(context)
|
419 |
421 |
assert len(extra_context['forms']) == 0
|
420 |
422 |
|
421 |
|
@wcsctl_present
|
|
423 |
@wcs_present
|
422 |
424 |
def test_current_forms_cell_render_single_site(context):
|
423 |
425 |
page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard')
|
424 |
426 |
page.save()
|
... | ... | |
441 |
443 |
assert 'http://127.0.0.2:8999/form-title/1/' not in result
|
442 |
444 |
assert 'http://127.0.0.2:8999/form-title/22/' not in result
|
443 |
445 |
|
444 |
|
@wcsctl_present
|
|
446 |
@wcs_present
|
445 |
447 |
def test_current_forms_unknown_name_id(caplog, context):
|
446 |
448 |
page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard')
|
447 |
449 |
page.save()
|
... | ... | |
462 |
464 |
assert 'http://127.0.0.1:8999/' not in result
|
463 |
465 |
assert len(caplog.records) == 0
|
464 |
466 |
|
465 |
|
@wcsctl_present
|
|
467 |
@wcs_present
|
466 |
468 |
def test_forms_of_category_cell_setup():
|
467 |
469 |
cell = WcsFormsOfCategoryCell()
|
468 |
470 |
form_class = cell.get_default_form_class()
|
... | ... | |
473 |
475 |
(u'other:test-3', u'test2 : Test 3'),
|
474 |
476 |
(u'other:test-9', u'test2 : Test 9')]
|
475 |
477 |
|
476 |
|
@wcsctl_present
|
|
478 |
@wcs_present
|
477 |
479 |
def test_forms_of_category_cell_render(context):
|
478 |
480 |
page = Page(title='xxx', slug='test_forms_of_category_cell_render', template_name='standard')
|
479 |
481 |
page.save()
|
... | ... | |
519 |
521 |
assert cell.render_for_search() == ''
|
520 |
522 |
assert len(list(cell.get_external_links_data())) == 2
|
521 |
523 |
|
522 |
|
@wcsctl_present
|
|
524 |
@wcs_present
|
523 |
525 |
def test_current_drafts_cell_render_unlogged(context):
|
524 |
526 |
page = Page(title='xxx', slug='test_current_drafts_cell_render', template_name='standard')
|
525 |
527 |
page.save()
|
... | ... | |
529 |
531 |
result = cell.render(context)
|
530 |
532 |
assert not 'http://127.0.0.1:8999/third-form-title' in result # no form
|
531 |
533 |
|
532 |
|
@wcsctl_present
|
|
534 |
@wcs_present
|
533 |
535 |
def test_current_drafts_cell_render_logged_in(context):
|
534 |
536 |
page = Page(title='xxx', slug='test_current_drafts_cell_render', template_name='standard')
|
535 |
537 |
page.save()
|
... | ... | |
551 |
553 |
assert len([x for x in extra_context['drafts'] if x['site_slug'] == 'default']) == 1
|
552 |
554 |
assert len([x for x in extra_context['drafts'] if x['site_slug'] == 'other']) == 1
|
553 |
555 |
|
554 |
|
@wcsctl_present
|
|
556 |
@wcs_present
|
555 |
557 |
def test_manager_forms_of_category_cell(app, admin_user):
|
556 |
558 |
Page.objects.all().delete()
|
557 |
559 |
page = Page(title='One', slug='one', template_name='standard')
|
... | ... | |
571 |
573 |
resp = resp.forms[0].submit()
|
572 |
574 |
assert resp.status_int == 302
|
573 |
575 |
|
574 |
|
@wcsctl_present
|
|
576 |
@wcs_present
|
575 |
577 |
def test_manager_current_forms(app, admin_user):
|
576 |
578 |
Page.objects.all().delete()
|
577 |
579 |
page = Page(title='One', slug='one', template_name='standard')
|
... | ... | |
608 |
610 |
settings.KNOWN_SERVICES = temp_settings
|
609 |
611 |
|
610 |
612 |
|
611 |
|
@wcsctl_present
|
|
613 |
@wcs_present
|
612 |
614 |
def test_tracking_code_cell(app):
|
613 |
615 |
Page.objects.all().delete()
|
614 |
616 |
page = Page(title='One', slug='index', template_name='standard')
|
... | ... | |
678 |
680 |
|
679 |
681 |
resp = app.post(reverse('wcs-tracking-code'), params={'cell': cell.id}, status=400)
|
680 |
682 |
|
681 |
|
@wcsctl_present
|
|
683 |
@wcs_present
|
682 |
684 |
def test_cell_assets(app, admin_user):
|
683 |
685 |
page = Page(title='xxx', slug='test_cell_assets', template_name='standard')
|
684 |
686 |
page.save()
|
... | ... | |
710 |
712 |
assert u'>Logo — Test 9 (test)<' in resp.text
|
711 |
713 |
assert u'>Picture — form title (test)<' in resp.text
|
712 |
714 |
|
713 |
|
@wcsctl_present
|
|
715 |
@wcs_present
|
714 |
716 |
def test_tracking_code_search(app):
|
715 |
717 |
assert len(app.get('/api/search/tracking-code/').json.get('data')) == 0
|
716 |
718 |
assert len(app.get('/api/search/tracking-code/?q=123').json.get('data')) == 0
|
... | ... | |
720 |
722 |
assert len(app.get('/api/search/tracking-code/?q=BBCCDDFFG').json.get('data')) == 0
|
721 |
723 |
assert len(app.get('/api/search/tracking-code/?q= cnphntfb').json.get('data')) == 1
|
722 |
724 |
|
723 |
|
@wcsctl_present
|
|
725 |
@wcs_present
|
724 |
726 |
def test_wcs_search_engines(app):
|
725 |
727 |
search_engines = engines.get_engines()
|
726 |
728 |
assert 'tracking-code' in search_engines.keys()
|
727 |
729 |
assert len([x for x in search_engines.keys() if x.startswith('formdata:')]) == 2
|
728 |
730 |
|
729 |
|
@wcsctl_present
|
|
731 |
@wcs_present
|
730 |
732 |
def test_backoffice_submission_cell_render(context):
|
731 |
733 |
page = Page(title='xxx', slug='test_backoffice_submission_cell_render', template_name='standard')
|
732 |
734 |
page.save()
|