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)
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
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
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
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
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)
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, }
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
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