Merge develop into master by jjjordanmsft · Pull Request #53 · microsoft/ApplicationInsights-Python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applicationinsights/channel/SenderBase.py
2 changes: 1 addition & 1 deletion applicationinsights/channel/TelemetryChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# set up internal context
internal_context = contracts.Internal()
internal_context.sdk_version = platform_moniker + ':0.11.0'
internal_context.sdk_version = platform_moniker + ':0.11.1'

class TelemetryChannel(object):
"""The telemetry channel is responsible for constructing a :class:`contracts.Envelope` object from the passed in
Expand Down
2 changes: 1 addition & 1 deletion applicationinsights/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def process_template_response(self, request, response):
data = request.appinsights.request
data.properties['template_name'] = response.template_name

return None
return response

class RequestAddon(object):
def __init__(self, client):
Expand Down
6 changes: 3 additions & 3 deletions django_tests/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ BASEDIR=$(pwd)
# Django/python compatibility matrix...
if $PYTHON -c "import sys; sys.exit(0 if sys.version_info < (3, 0) else 1)"; then
# Django2.0 won't support Python2
DJANGO_VERSIONS='1.7.11 1.8.18 1.9.13 1.10.7 1.11'
DJANGO_VERSIONS='1.7.11 1.8.18 1.9.13 1.10.7 1.11.4'
elif $PYTHON -c "import sys; sys.exit(0 if sys.version_info < (3, 5) else 1)"; then
DJANGO_VERSIONS='1.7.11 1.8.18 1.9.13 1.10.7 1.11'
DJANGO_VERSIONS='1.7.11 1.8.18 1.9.13 1.10.7 1.11.4'
else
# python3.5 dropped html.parser.HtmlParserError versions older than Django1.8 won't work
DJANGO_VERSIONS='1.8.18 1.9.13 1.10.7 1.11'
DJANGO_VERSIONS='1.8.18 1.9.13 1.10.7 1.11.4'
fi

# For each Django version...
Expand Down
1 change: 1 addition & 0 deletions django_tests/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cd aitest
cp $SRCDIR/views.py aitest/views.py
cp $SRCDIR/tests.py aitest/tests.py
cp $SRCDIR/urls.py aitest/urls.py
cp $SRCDIR/template.html aitest/template.html

./manage.py test
exit $?
1 change: 1 addition & 0 deletions django_tests/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test django template: {{ context }}
22 changes: 21 additions & 1 deletion django_tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import logging

import django
Expand All @@ -15,6 +16,7 @@
TEST_IKEY = '12345678-1234-5678-9012-123456789abc'
TEST_ENDPOINT = 'https://test.endpoint/v2/track'
DEFAULT_ENDPOINT = AsynchronousSender().service_endpoint_uri
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

class AITestCase(TestCase):
def plug_sender(self):
Expand All @@ -37,7 +39,13 @@ def get_events(self, count):
return self.events

@modify_settings(**{MIDDLEWARE_NAME: {'append': 'applicationinsights.django.ApplicationInsightsMiddleware'}})
@override_settings(APPLICATION_INSIGHTS={'ikey': TEST_IKEY})
@override_settings(
APPLICATION_INSIGHTS={'ikey': TEST_IKEY},
# Templates for 1.7
TEMPLATE_DIRS=(PROJECT_ROOT,),
TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader',),
# Templates for 1.8 and up
TEMPLATES=[{'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [PROJECT_ROOT]}])
class MiddlewareTests(AITestCase):
def setUp(self):
self.plug_sender()
Expand Down Expand Up @@ -133,6 +141,18 @@ def test_error(self):
self.assertEqual(data['success'], False, "Success value")
self.assertEqual(data['url'], 'http://testserver/errorer', "Request url")

def test_template(self):
"""Tests that views using templates operate correctly and that template data is logged"""
response = self.client.get("/templater/ctx")
self.assertEqual(response.status_code, 200)

event = self.get_events(1)
data = event['data']['baseData']
self.assertEqual(event['name'], 'Microsoft.ApplicationInsights.Request', "Event type")
self.assertEqual(data['success'], True, "Success value")
self.assertEqual(data['responseCode'], 200, "Status code")
self.assertEqual(data['properties']['template_name'], 'template.html', "Template name")

def test_no_view_arguments(self):
"""Tests that view id logging is off by default"""
self.plug_sender()
Expand Down
1 change: 1 addition & 0 deletions django_tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
url(r'^errorer$', views.errorer, name='errorer'),
url(r'^getid/([0-9]+)$', views.getid, name='getid'),
url(r'^returncode/([0-9]+)$', views.returncode, name='returncode'),
url(r'^templater/([^/]*)$', views.templater, name='templater'),
]
4 changes: 4 additions & 0 deletions django_tests/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.http import HttpResponse, Http404
from django.template.response import TemplateResponse

def home(request):
return HttpResponse("Welcome home")
Expand All @@ -21,3 +22,6 @@ def getid(request, id):

def returncode(request, id):
return HttpResponse("Status code set to %s" % id, status=int(id))

def templater(request, data):
return TemplateResponse(request, 'template.html', {'context': data})
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
# built documents.
#
# The short X.Y version.
version = '0.11.0'
version = '0.11.1'
# The full version, including alpha/beta/rc tags.
release = '0.11.0'
release = '0.11.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py