# encoding: utf-8

import time

from web.core.context import Context
from web.ext.analytics import AnalyticsExtension


def test_analytics_extension():
	ctx = Context(response=Context(headers=dict()))
	ext = AnalyticsExtension()
	
	assert not hasattr(ctx, '_start_time')
	ext.prepare(ctx)
	
	assert hasattr(ctx, '_start_time')
	ext.before(ctx)
	time.sleep(0.1)
	
	ext.after(ctx)
	assert 0.1 <= float(ctx.response.headers['X-Generation-Time']) <= 0.2


@@ -24,16 +24,89 @@
 rt time%0A
+import pytest%0A%0Afrom webob import Request%0Afrom web.core import Application
 %0Afrom we
@@ -186,16 +186,140 @@
 nsion%0A%0A%0A
+def endpoint(context):%0A%09time.sleep(0.1)%0A%09return %22Hi.%22%0A%0A%0Asample = Application(endpoint, extensions=%5BAnalyticsExtension()%5D)%0A%0A%0A
 def test
@@ -641,8 +641,280 @@
 %3C= 0.2%0A%0A
+%0Adef test_analytics_extension_in_context():%0A%09try:%0A%09%09__import__('web.dispatch.object')%0A%09except ImportError:%0A%09%09pytest.skip(%22web.dispatch.object not installed%22)%0A%09%0A%09resp = Request.blank('/').get_response(sample)%0A%09assert 0.1 %3C= float(resp.headers%5B'X-Generation-Time'%5D) %3C= 0.2%0A%0A

Add test for full processing pipeline.