def test_get_user(app, mock_users, request_headers): """Test the get_user function.""" header = request_headers['user'] with patch('invenio_stats.utils.current_user', mock_users['authenticated']), app.test_request_context( headers=header, environ_base={'REMOTE_ADDR': '142.0.0.1'}): user = get_user() assert user['user_id'] == mock_users['authenticated'].get_id() assert user['user_agent'] == header['USER_AGENT'] assert user['ip_address'] == '142.0.0.1'
def test_get_user(app, mock_users, request_headers): """Test the get_user function.""" header = request_headers['user'] with patch( 'invenio_stats.utils.current_user', mock_users['authenticated'] ), app.test_request_context( headers=header, environ_base={'REMOTE_ADDR': '142.0.0.1'} ): user = get_user() assert user['user_id'] == mock_users['authenticated'].get_id() assert user['user_agent'] == header['USER_AGENT'] assert user['ip_address'] == '142.0.0.1'
def test_record_view_event_builder(app, mock_user_ctx, record, pid): """Test the record view event builder.""" with app.test_request_context(headers=headers): event = {} with patch('datetime.datetime', NewDate): record_view_event_builder(event, app, pid, record) assert event == dict( # When: timestamp=NewDate.utcnow().isoformat(), # What: record_id=str(record.id), pid_type=pid.pid_type, pid_value=str(pid.pid_value), # Who: **get_user())
def test_file_download_event_builder(app, mock_user_ctx, sequential_ids, objects): """Test the file-download event builder.""" file_obj = objects[0] file_obj.bucket_id = sequential_ids[0] with app.test_request_context(headers=headers): event = {} with patch('datetime.datetime', NewDate): file_download_event_builder(event, app, file_obj) assert event == dict( # When: timestamp=NewDate.utcnow().isoformat(), # What: bucket_id=str(file_obj.bucket_id), file_id=str(file_obj.file_id), file_key=file_obj.key, # Who: **get_user())