161 |
161 |
<no_result_tag/>
|
162 |
162 |
"""
|
163 |
163 |
|
|
164 |
PING_SUCCESS = '{"status":"success","tracked":1,"invalid":0}'
|
|
165 |
PING_ERROR = 'somethings else'
|
|
166 |
|
164 |
167 |
def requests_post_mocked_replies(contents):
|
165 |
168 |
"""buid an iterator for mock's side_effect parameter"""
|
166 |
169 |
responses = []
|
... | ... | |
499 |
502 |
assert False
|
500 |
503 |
|
501 |
504 |
@mock.patch('requests.post')
|
|
505 |
def test_ping(mocked_post):
|
|
506 |
"""webservice to simulate a first tracking call"""
|
|
507 |
with override_settings(MATOMO_SERVER=CONFIG):
|
|
508 |
matomo = MatomoWS()
|
|
509 |
|
|
510 |
# success
|
|
511 |
content = PING_SUCCESS
|
|
512 |
mocked_post.return_value.content = content
|
|
513 |
matomo.ping('42')
|
|
514 |
assert True
|
|
515 |
|
|
516 |
# error
|
|
517 |
content = PING_ERROR
|
|
518 |
mocked_post.return_value.content = content
|
|
519 |
with pytest.raises(MatomoException) as exc:
|
|
520 |
matomo.ping('42')
|
|
521 |
assert 'ping fails' in str(exc)
|
|
522 |
|
|
523 |
@mock.patch('requests.post')
|
502 |
524 |
def test_upgrade_site(mocked_post):
|
503 |
525 |
"""function to test if the site is already regisered"""
|
504 |
526 |
urls = ['https://combo.dev.publik.love',
|
... | ... | |
627 |
649 |
value1 = get_variable_value('cnil_compliant_visits_tracking_js', 'undefined')
|
628 |
650 |
value2 = get_variable_value('visits_tracking_js', 'undefined')
|
629 |
651 |
assert value1 == 'undefined'
|
630 |
|
assert value2 == 'undefined'
|
|
652 |
assert value2 == 'undefined'
|
631 |
653 |
|
632 |
654 |
@mock.patch('requests.post')
|
633 |
655 |
def test_upgrade_javascript_tag(mocked_post):
|
... | ... | |
658 |
680 |
with override_settings(MATOMO_SERVER=CONFIG):
|
659 |
681 |
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS,
|
660 |
682 |
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
661 |
|
JAVASCRIPT_TAG]
|
|
683 |
JAVASCRIPT_TAG, PING_SUCCESS]
|
662 |
684 |
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
663 |
685 |
assert auto_configure_matomo() is True
|
664 |
686 |
logme_url_var = get_variable('matomo_logme_url')
|
... | ... | |
670 |
692 |
|
671 |
693 |
@mock.patch('requests.post')
|
672 |
694 |
def test_auto_configure_matomo_no_url(mocked_post):
|
673 |
|
# no Wc url so as to raise
|
|
695 |
# no Combo url so as to raise
|
674 |
696 |
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
675 |
697 |
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
676 |
698 |
|
... | ... | |
696 |
718 |
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
697 |
719 |
JAVASCRIPT_TAG_BAD_RESPONSE]
|
698 |
720 |
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
699 |
|
try:
|
|
721 |
with pytest.raises(MatomoException) as exc:
|
700 |
722 |
auto_configure_matomo()
|
701 |
|
except MatomoException as exc:
|
702 |
|
assert str(exc) == "get_javascript_tag fails"
|
703 |
|
else:
|
704 |
|
assert False
|
|
723 |
assert "get_javascript_tag fails" in str(exc)
|
|
724 |
tracking_js_var = get_variable('visits_tracking_js')
|
|
725 |
assert tracking_js_var.value == 'js_code'
|
|
726 |
|
|
727 |
with override_settings(MATOMO_SERVER=CONFIG):
|
|
728 |
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS,
|
|
729 |
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
|
730 |
JAVASCRIPT_TAG, PING_ERROR]
|
|
731 |
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
|
732 |
with pytest.raises(MatomoException) as exc:
|
|
733 |
auto_configure_matomo()
|
|
734 |
assert 'ping fails' in str(exc)
|
705 |
735 |
tracking_js_var = get_variable('visits_tracking_js')
|
706 |
736 |
assert tracking_js_var.value == 'js_code'
|