Beispiel #1
0
def test_piwik_track_new_follow(track, app):
    path = '/path/to/dataset'
    user = UserFactory()
    with app.test_request_context(path, base_url=PREFIX):
        tracking.send_signal(on_new_follow, request, user)

    track.assert_called_with(PREFIX + path, uid=user.id, user_ip=None, idgoal=GOAL_NEW_FOLLOW)
Beispiel #2
0
def collect_stats(response):
    action_name = extract_name_from_path(request.full_path)
    blacklist = current_app.config.get("TRACKING_BLACKLIST", [])
    if not current_app.config["TESTING"] and request.endpoint not in blacklist:
        extras = {"action_name": urllib.quote(action_name)}
        tracking.send_signal(on_api_call, request, current_user, **extras)
    return response
Beispiel #3
0
 def post(self, id):
     '''Follow an object given its ID'''
     follow, created = self.model.objects.get_or_create(
         follower=current_user.id, following=id, until=None)
     count = self.model.objects.followers(id).count()
     if not current_app.config['TESTING']:
         tracking.send_signal(on_new_follow, request, current_user)
     return {'followers': count}, 201 if created else 200
Beispiel #4
0
 def post(self, id):
     '''Follow an object given its ID'''
     follow, created = self.model.objects.get_or_create(
         follower=current_user.id, following=id, until=None)
     count = self.model.objects.followers(id).count()
     if not current_app.config['TESTING']:
         tracking.send_signal(on_new_follow, request, current_user)
     return {'followers': count}, 201 if created else 200
Beispiel #5
0
def collect_stats(response):
    action_name = extract_name_from_path(request.full_path)
    blacklist = current_app.config.get('TRACKING_BLACKLIST', [])
    if (not current_app.config['TESTING']
            and request.endpoint not in blacklist):
        extras = {
            'action_name': urllib.quote(action_name),
        }
        tracking.send_signal(on_api_call, request, current_user, **extras)
    return response
Beispiel #6
0
def test_piwik_track_api_without_bulk(track, app, clean_db):
    path = '/api/1/some/api'
    user = UserFactory()
    ip = faker.ipv4()
    with app.test_request_context(path, base_url=PREFIX,
                                  environ_base={'REMOTE_ADDR': ip}):
        tracking.send_signal(on_api_call, request, user)

    track.assert_called_with(PREFIX + path, uid=user.id, cip=ip)
    assert PiwikTracking.objects.count() == 0
Beispiel #7
0
def test_piwik_track_new_follow(track, app):
    path = '/path/to/dataset'
    user = UserFactory()
    with app.test_request_context(path, base_url=PREFIX):
        tracking.send_signal(on_new_follow, request, user)

    track.assert_called_with(PREFIX + path,
                             uid=user.id,
                             user_ip=None,
                             idgoal=GOAL_NEW_FOLLOW)
Beispiel #8
0
def test_piwik_track_api_without_bulk(track, app, clean_db):
    path = '/api/1/some/api'
    user = UserFactory()
    ip = faker.ipv4()
    with app.test_request_context(path,
                                  base_url=PREFIX,
                                  environ_base={'REMOTE_ADDR': ip}):
        tracking.send_signal(on_api_call, request, user)

    track.assert_called_with(PREFIX + path, uid=user.id, cip=ip)
    assert PiwikTracking.objects.count() == 0
Beispiel #9
0
def test_piwik_track_api_with_bulk_and_spaces_in_url(track, app, clean_db):
    path = '/api/1/some/api?q=query with spaces&other=with space'
    encoded_path = path.replace(' ', '%20')
    user = UserFactory()
    with app.test_request_context(path, base_url=PREFIX):
        tracking.send_signal(on_api_call, request, user)

    assert not track.called
    assert PiwikTracking.objects.count() == 1

    pt = PiwikTracking.objects.first()
    assert pt.url in (PREFIX + path, PREFIX + encoded_path)
Beispiel #10
0
def test_piwik_track_api_with_bulk_and_spaces_in_url(track, app, clean_db):
    path = '/api/1/some/api?q=query with spaces&other=with space'
    encoded_path = path.replace(' ', '%20')
    user = UserFactory()
    with app.test_request_context(path, base_url=PREFIX):
        tracking.send_signal(on_api_call, request, user)

    assert not track.called
    assert PiwikTracking.objects.count() == 1

    pt = PiwikTracking.objects.first()
    assert pt.url in (PREFIX + path, PREFIX + encoded_path)
Beispiel #11
0
def test_piwik_track_api_with_bulk(track, app, clean_db):
    path = '/api/1/some/api'
    user = UserFactory()
    ip = faker.ipv4()
    with app.test_request_context(path, base_url=PREFIX,
                                  environ_base={'REMOTE_ADDR': ip}):
        tracking.send_signal(on_api_call, request, user)

    assert not track.called
    assert PiwikTracking.objects.count() == 1

    pt = PiwikTracking.objects.first()
    assert pt.url == PREFIX + path
    assert pt.date is not None
    assert pt.kwargs == {
        'uid': user.id,
        'cip': ip,
    }
Beispiel #12
0
def test_piwik_track_api_with_bulk(track, app, clean_db):
    path = '/api/1/some/api'
    user = UserFactory()
    ip = faker.ipv4()
    with app.test_request_context(path,
                                  base_url=PREFIX,
                                  environ_base={'REMOTE_ADDR': ip}):
        tracking.send_signal(on_api_call, request, user)

    assert not track.called
    assert PiwikTracking.objects.count() == 1

    pt = PiwikTracking.objects.first()
    assert pt.url == PREFIX + path
    assert pt.date is not None
    assert pt.kwargs == {
        'uid': user.id,
        'cip': ip,
    }
Beispiel #13
0
 def on_form_valid(self, form):
     response = super(DatasetCreateView, self).on_form_valid(form)
     if not current_app.config['TESTING']:
         tracking.send_signal(on_dataset_published, request, current_user)
     return response
Beispiel #14
0
 def on_form_valid(self, form):
     response = super(ReuseCreateView, self).on_form_valid(form)
     notify_new_reuse.delay(self.object)
     if not current_app.config['TESTING']:
         tracking.send_signal(on_reuse_published, request, current_user)
     return response
Beispiel #15
0
 def on_form_valid(self, form):
     response = super(DatasetCreateView, self).on_form_valid(form)
     if not current_app.config['TESTING']:
         tracking.send_signal(on_dataset_published, request, current_user)
     return response