Updated contracts to support new endpoint schema

Other changes in this version:
 - Changed serialization mechanism to be json.dumps() based (instead of manual)
 - Removed instance_version
 - Type mapping moved to fields on the object to send instead of global mapping dictionary
 - Removed uses of isinstance()
 - Renamed methods, properties and fields to follow python guidelines:
    - single leading _ for privates
    - property and method names use _ separated names instead of camel case
 - Changed track_exception() signature to be sys.exc_info() compatible (see .md file to sample usage)
 - Properly serializing required fields
This commit is contained in:
Bogdan Berce 2014-11-25 15:33:37 -08:00
Родитель 206520da39
Коммит 4e7073228b
91 изменённых файлов: 4275 добавлений и 3927 удалений

Просмотреть файл

@ -44,114 +44,91 @@ Once installed, you can send telemetry to Application Insights. Here are
a few samples.
**Note**: before you can send data to you will need an
instrumentation key. Please see the **Getting an Application
Insights Instrumentation Key** section for more information.
instrumentation key. Please see the `Getting an Application Insights
Instrumentation
Key <https://github.com/Microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key>`__
section for more information.
#. **Sending a simple event telemetry item**
**Sending a simple event telemetry item**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackEvent("Test event")
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_event("Test event")
#. **Sending an event telemetry item with custom properties and
measurements**
**Sending an event telemetry item with custom properties and
measurements**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackEvent("Test event", { "foo": "bar" }, { "baz": 42 })
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_event('Test event', { 'foo': 'bar' }, { 'baz': 42 })
#. **Sending a trace telemetry item with custom properties**
**Sending a trace telemetry item with custom properties**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackTrace("Test trace", { "foo": "bar" })
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_trace('Test trace', { 'foo': 'bar' })
#. **Sending a metric telemetry item**
**Sending a metric telemetry item**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackMetric("My Metric", 42)
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_metric('My Metric', 42)
#. **Sending an exception telemetry item with custom properties and
measurements**
**Sending an exception telemetry item with custom properties and
measurements**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
try:
import sys
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
try:
raise Exception('blah')
except:
tc.track_exception()
try:
raise Exception("blah")
except Exception as e:
tc.trackException(e, { "foo": "bar" }, { "x": 42 })
except:
tc.track_exception(*sys.exc_info(), properties={ 'foo': 'bar' }, measurements={ 'x': 42 })
#. **Configuring context for a telemetry client instance**
**Configuring context for a telemetry client instance**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.context.application.id = "My application"
tc.context.application.ver = "1.2.3"
tc.context.device.id = "My current device"
tc.context.device.oemName = "Asus"
tc.context.device.model = "X31A"
tc.context.device.type = "Other"
tc.context.user.id = "santa@northpole.net"
tc.trackTrace("My trace with context")
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.context.application.id = 'My application'
tc.context.application.ver = '1.2.3'
tc.context.device.id = 'My current device'
tc.context.device.oemName = 'Asus'
tc.context.device.model = 'X31A'
tc.context.device.type = "Other"
tc.context.user.id = 'santa@northpole.net'
tc.track_trace('My trace with context')
#. **Configuring channel related properties**
**Configuring channel related properties**
.. code:: python
.. code:: python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
# flush telemetry every 30 seconds (assuming we don't hit maxQueueItemCount first)
tc.channel.sender.sendIntervalInMilliseconds = 30 * 1000
# flush telemetry if we have 10 or more telemetry items in our queue
tc.channel.sender.maxQueueItemCount = 10
Getting an Application Insights Instrumentation Key
---------------------------------------------------
To successfully send data to the Application Insights service, you will
need an Application Insights resource's instrumentation key. Here is how
you get a new one.
#. Log into the `Microsoft Azure portal <https://portal.azure.com/>`__
#. Create a new Application Insights resource in the by clicking
``New -> Application Insights``.
.. raw:: html
<center><img src="http://i.imgur.com/jieq59h.png" width="300" /></center>
#. Enter a name for your new Application Insights resource and click
create. A new tile will appear on your dashboard.
.. raw:: html
<center><img src="http://i.imgur.com/XIMABul.png" width="600" /></center>
#. Expand your resource by clicking on the tile on your dashboard, then
click on the Properties tile to open your resource's properties
blade. You can copy the instrumentation key from here.
.. raw:: html
<center><img src="http://i.imgur.com/i1OzJVP.png" width="700" /></center>
from applicationinsights import TelemetryClient
tc = TelemetryClient()
# flush telemetry every 30 seconds (assuming we don't hit max_queue_item_count first)
tc.channel.sender.send_interval_in_milliseconds = 30 * 1000
# flush telemetry if we have 10 or more telemetry items in our queue
tc.channel.sender.max_queue_item_count = 10

Просмотреть файл

@ -24,25 +24,32 @@
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="applicationinsights\channel\contracts\ApplicationContext.py" />
<Compile Include="applicationinsights\channel\contracts\DeviceContext.py" />
<Compile Include="applicationinsights\channel\contracts\EventTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\ExceptionTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\ExceptionTelemetryDetails.py" />
<Compile Include="applicationinsights\channel\contracts\ExceptionTelemetryStackFrame.py" />
<Compile Include="applicationinsights\channel\contracts\LocationContext.py" />
<Compile Include="applicationinsights\channel\contracts\MessageTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\MetricTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\MetricTelemetryDataPoint.py" />
<Compile Include="applicationinsights\channel\contracts\OperationContext.py" />
<Compile Include="applicationinsights\channel\contracts\PageViewTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\PageViewTelemetryPerf.py" />
<Compile Include="applicationinsights\channel\contracts\RemoteDependencyTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\RequestTelemetry.py" />
<Compile Include="applicationinsights\channel\contracts\SessionContext.py" />
<Compile Include="applicationinsights\channel\contracts\TelemetryEnvelope.py" />
<Compile Include="applicationinsights\channel\contracts\TelemetryEnvelopeData.py" />
<Compile Include="applicationinsights\channel\contracts\UserContext.py" />
<Compile Include="applicationinsights\channel\contracts\Application.py" />
<Compile Include="applicationinsights\channel\contracts\Data.py" />
<Compile Include="applicationinsights\channel\contracts\DataPoint.py" />
<Compile Include="applicationinsights\channel\contracts\DataPointType.py" />
<Compile Include="applicationinsights\channel\contracts\DependencyKind.py" />
<Compile Include="applicationinsights\channel\contracts\DependencySourceType.py" />
<Compile Include="applicationinsights\channel\contracts\Device.py" />
<Compile Include="applicationinsights\channel\contracts\Envelope.py" />
<Compile Include="applicationinsights\channel\contracts\EventData.py" />
<Compile Include="applicationinsights\channel\contracts\ExceptionData.py" />
<Compile Include="applicationinsights\channel\contracts\ExceptionDetails.py" />
<Compile Include="applicationinsights\channel\contracts\Internal.py" />
<Compile Include="applicationinsights\channel\contracts\Location.py" />
<Compile Include="applicationinsights\channel\contracts\MessageData.py" />
<Compile Include="applicationinsights\channel\contracts\MetricData.py" />
<Compile Include="applicationinsights\channel\contracts\Operation.py" />
<Compile Include="applicationinsights\channel\contracts\PageViewData.py" />
<Compile Include="applicationinsights\channel\contracts\RemoteDependencyData.py" />
<Compile Include="applicationinsights\channel\contracts\RequestData.py" />
<Compile Include="applicationinsights\channel\contracts\Session.py" />
<Compile Include="applicationinsights\channel\contracts\SeverityLevel.py" />
<Compile Include="applicationinsights\channel\contracts\StackFrame.py" />
<Compile Include="applicationinsights\channel\contracts\User.py" />
<Compile Include="applicationinsights\channel\contracts\Utils.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="applicationinsights\channel\contracts\__init__.py" />
<Compile Include="applicationinsights\channel\TelemetryChannel.py" />
<Compile Include="applicationinsights\channel\TelemetryContext.py" />
@ -52,25 +59,25 @@
<Compile Include="setup.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestApplicationContext.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestDeviceContext.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestEventTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestExceptionTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestExceptionTelemetryDetails.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestExceptionTelemetryStackFrame.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestLocationContext.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestMessageTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestMetricTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestMetricTelemetryDataPoint.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestOperationContext.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestPageViewTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestPageViewTelemetryPerf.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestRemoteDependencyTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestRequestTelemetry.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestSessionContext.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestTelemetryEnvelope.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestTelemetryEnvelopeData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestUserContext.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestApplication.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestDataPoint.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestDevice.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestEnvelope.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestEventData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestExceptionData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestExceptionDetails.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestInternal.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestLocation.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestMessageData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestMetricData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestOperation.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestPageViewData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestRemoteDependencyData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestRequestData.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestSession.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestStackFrame.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\TestUser.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\contracts_tests\__init__.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\TestTelemetryChannel.py" />
<Compile Include="tests\applicationinsights_tests\channel_tests\TestTelemetryContext.py" />

Просмотреть файл

@ -31,68 +31,74 @@ Once installed, you can send telemetry to Application Insights. Here are a few s
```python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackEvent("Test event")
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_event('Test event')
```
**Sending an event telemetry item with custom properties and measurements**
```python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackEvent("Test event", { "foo": "bar" }, { "baz": 42 })
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_event('Test event', { 'foo': 'bar' }, { 'baz': 42 })
```
**Sending a trace telemetry item with custom properties**
```python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackTrace("Test trace", { "foo": "bar" })
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_trace('Test trace', { 'foo': 'bar' })
```
**Sending a metric telemetry item**
```python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.trackMetric("My Metric", 42)
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_metric('My Metric', 42)
```
**Sending an exception telemetry item with custom properties and measurements**
```python
import sys
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
try:
raise Exception('blah')
except:
tc.track_exception()
try:
raise Exception("blah")
except Exception as e:
tc.trackException(e, { "foo": "bar" }, { "x": 42 })
except:
tc.track_exception(*sys.exc_info(), properties={ 'foo': 'bar' }, measurements={ 'x': 42 })
```
**Configuring context for a telemetry client instance**
```python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentationKey = "<YOUR INSTRUMENTATION KEY GOES HERE>"
tc.context.application.id = "My application"
tc.context.application.ver = "1.2.3"
tc.context.device.id = "My current device"
tc.context.device.oemName = "Asus"
tc.context.device.model = "X31A"
tc.context.device.type = "Other"
tc.context.user.id = "santa@northpole.net"
tc.trackTrace("My trace with context")
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.context.application.id = 'My application'
tc.context.application.ver = '1.2.3'
tc.context.device.id = 'My current device'
tc.context.device.oemName = 'Asus'
tc.context.device.model = 'X31A'
tc.context.device.type = "Other"
tc.context.user.id = 'santa@northpole.net'
tc.track_trace('My trace with context')
```
**Configuring channel related properties**
```python
from applicationinsights import TelemetryClient
tc = TelemetryClient()
# flush telemetry every 30 seconds (assuming we don't hit maxQueueItemCount first)
tc.channel.sender.sendIntervalInMilliseconds = 30 * 1000
# flush telemetry every 30 seconds (assuming we don't hit max_queue_item_count first)
tc.channel.sender.send_interval_in_milliseconds = 30 * 1000
# flush telemetry if we have 10 or more telemetry items in our queue
tc.channel.sender.maxQueueItemCount = 10
tc.channel.sender.max_queue_item_count = 10
```

Просмотреть файл

@ -1,117 +1,111 @@
import traceback
import sys
from applicationinsights import channel
NULL_CONSTANT_STRING = "Null"
NULL_CONSTANT_STRING = 'Null'
class TelemetryClient(object):
def __init__(self, telemetryChannel=None):
def __init__(self, telemetry_channel=None):
"""Initializes a new instance of the TelemetryClient class."""
self.__context = channel.TelemetryContext()
self.__channel = telemetryChannel
if not self.__channel or not isinstance(self.__channel, channel.TelemetryChannel):
self.__channel = channel.TelemetryChannel()
self._context = channel.TelemetryContext()
self._channel = telemetry_channel or channel.TelemetryChannel()
@property
def context(self):
"""Gets the context associated with this telemetry client."""
return self.__context
return self._context
@property
def channel(self):
"""Gets the channel associated with this telemetry client."""
return self.__channel
return self._channel
def trackPageView(self, name, url, duration=0, properties=None, measurements=None):
def track_pageview(self, name, url, duration=0, properties=None, measurements=None):
"""Send information about the page viewed in the application."""
pageViewData = channel.contracts.PageViewTelemetry()
if not name:
name = NULL_CONSTANT_STRING
pageViewData.name = name
pageViewData.url = url
pageViewData.duration = duration
pageViewData.properties = properties
pageViewData.measurements = measurements
data = channel.contracts.PageViewData()
data.name = name or NULL_CONSTANT_STRING
data.url = url
data.duration = duration
if properties:
data.properties = properties
if measurements:
data.measurements = measurements
self.__channel.write(pageViewData, self.__context)
self._channel.write(data, self._context)
def trackException(self, exception, properties=None, measurements=None):
def track_exception(self, type=None, value=None, tb=None, properties=None, measurements=None):
"""Send an ExceptionTelemetry object for display in Diagnostic Search."""
exceptionData = channel.contracts.ExceptionTelemetry()
if not exception or not isinstance(exception, Exception):
if not type or not value or not tb:
type, value, tb = sys.exc_info()
if not type or not value or not tb:
try:
Exception(NULL_CONSTANT_STRING)
except Exception as e:
exception = e
exceptionDataDetail = channel.contracts.ExceptionTelemetryDetails()
exceptionDataDetail.id = 1
exceptionDataDetail.outerId = 0
exceptionDataDetail.typeName = exception.__class__.__name__
exceptionDataDetail.message = "".join(exception.args)
exceptionDataDetail.hasFullStack = False
if "__traceback__" in dir(exception):
exceptionDataDetail.hasFullStack = True
traceback = exception.__traceback__
counter = 0
while traceback:
frame = channel.contracts.ExceptionTelemetryStackFrame()
frame.assembly = "<module>"
frame.fileName = traceback.tb_frame.f_code.co_filename
frame.level = counter
frame.line = traceback.tb_lineno
frame.method = traceback.tb_frame.f_code.co_name + "(" + ', '.join(traceback.tb_frame.f_code.co_varnames[:traceback.tb_frame.f_code.co_argcount]) + ")"
exceptionDataDetail.parsedStack.append(frame)
traceback = traceback.tb_next
counter += 1
exceptionDataDetail.parsedStack.reverse()
raise Exception(NULL_CONSTANT_STRING)
except:
type, value, tb = sys.exc_info()
exceptionData.exceptions.append(exceptionDataDetail)
exceptionData.properties = properties
exceptionData.measurements = measurements
details = channel.contracts.ExceptionDetails()
details.id = 1
details.outer_id = 0
details.type_name = type.__name__
details.message = ''.join(value.args)
details.has_full_stack = True
counter = 0
for tb_frame_file, tb_frame_line, tb_frame_function, tb_frame_text in traceback.extract_tb(tb):
frame = channel.contracts.StackFrame()
frame.assembly = 'Unknown'
frame.file_name = tb_frame_file
frame.level = counter
frame.line = tb_frame_line
frame.method = tb_frame_function
details.parsed_stack.append(frame)
counter += 1
details.parsed_stack.reverse()
self.__channel.write(exceptionData, self.__context)
data = channel.contracts.ExceptionData()
data.handled_at = 'UserCode'
data.exceptions.append(details)
if properties:
data.properties = properties
if measurements:
data.measurements = measurements
def trackEvent(self, name, properties=None, measurements=None):
self._channel.write(data, self._context)
def track_event(self, name, properties=None, measurements=None):
"""Send an EventTelemetry object for display in Diagnostic Search and aggregation in Metrics Explorer."""
eventData = channel.contracts.EventTelemetry()
if not name:
name = NULL_CONSTANT_STRING
eventData.name = name
eventData.properties = properties
eventData.measurements = measurements
data = channel.contracts.EventData()
data.name = name or NULL_CONSTANT_STRING
if properties:
data.properties = properties
if measurements:
data.measurements = measurements
self.__channel.write(eventData, self.__context)
self._channel.write(data, self._context)
def trackMetric(self, name, value, type=None, count=None, min=None, max=None, properties=None):
def track_metric(self, name, value, type=None, count=None, min=None, max=None, std_dev=None, properties=None):
"""Send a MetricTelemetry object for aggregation in Metric Explorer."""
metricDataPoint = channel.contracts.MetricTelemetryDataPoint()
if not name:
name = NULL_CONSTANT_STRING
if not value:
value = 0
if not type:
type = "Aggregation"
metricDataPoint.name = name
metricDataPoint.value = value
metricDataPoint.kind = type
metricDataPoint.count = count
metricDataPoint.min = min
metricDataPoint.max = max
dataPoint = channel.contracts.DataPoint()
dataPoint.name = name or NULL_CONSTANT_STRING
dataPoint.value = value or 0
dataPoint.kind = type or channel.contracts.DataPointType.aggregation
dataPoint.count = count
dataPoint.min = min
dataPoint.max = max
dataPoint.std_dev = std_dev
metricData = channel.contracts.MetricTelemetry()
metricData.metrics.append(metricDataPoint)
metricData.properties = properties
data = channel.contracts.MetricData()
data.metrics.append(dataPoint)
if properties:
data.properties = properties
self.__channel.write(metricData, self.__context)
self._channel.write(data, self._context)
def trackTrace(self, name, properties=None, measurements=None):
def track_trace(self, name, properties=None):
"""Send a trace message for display in Diagnostic Search."""
traceData = channel.contracts.MessageTelemetry()
if not name:
name = NULL_CONSTANT_STRING
traceData.message = name
traceData.properties = properties
traceData.measurements = measurements
data = channel.contracts.MessageData()
data.message = name or NULL_CONSTANT_STRING
if properties:
data.properties = properties
self.__channel.write(traceData, self.__context)
self._channel.write(data, self._context)

Просмотреть файл

@ -1,110 +1,109 @@
import datetime
import json
import locale
import platform
import threading
try:
import urllib2
import urllib2 as HTTPClient
from urllib2 import HTTPError
platform_moniker = 'py2'
except ImportError:
import urllib.request as urllib2
import urllib.request as HTTPClient
from urllib.error import HTTPError
platform_moniker = 'py3'
from applicationinsights.channel import contracts
# set up internal context
internal_context = contracts.Internal()
internal_context.sdk_version = platform_moniker + ':0.2.0'
class TelemetrySender(object):
"""The TelemetrySender is responsible for sending buffered telemetry to the server on a timer"""
def __init__(self, serviceEndpointUri="http://dc.services.visualstudio.com/v2/track"):
def __init__(self, service_endpoint_uri = 'http://dc.services.visualstudio.com/v2/track'):
"""Initializes a new instance of the TelemetrySender class."""
if serviceEndpointUri == None:
raise Exception("Service endpoint URI was required but not provided")
if not service_endpoint_uri:
raise Exception('Service endpoint URI was required but not provided')
self.__serviceEndpointUri = serviceEndpointUri
self.__sendIntervalInMilliseconds = 6000
self.__maxQueueItemCount = 100
self.__sendQueue = []
self.__timers = []
self._service_endpoint_uri = service_endpoint_uri
self._send_interval_in_milliseconds = 6000
self._max_queue_item_count = 100
self._queue = []
self._timers = []
@property
def serviceEndpointUri(self):
def service_endpoint_uri(self):
"""Gets the serivce endpoint URI property. This is where we send data to."""
return self.__serviceEndpointUri
return self._service_endpoint_uri
@property
def sendIntervalInMilliseconds(self):
def send_interval_in_milliseconds(self):
"""Gets or sets the send interval after which we will send data to the server. This value is expressed in milliseconds."""
return self.__sendIntervalInMilliseconds
return self._send_interval_in_milliseconds
@sendIntervalInMilliseconds.setter
def sendIntervalInMilliseconds(self, value):
@send_interval_in_milliseconds.setter
def send_interval_in_milliseconds(self, value):
"""Gets or sets the send interval after which we will send data to the server. This value is expressed in milliseconds."""
if value < 1000:
value = 1000
self.__sendIntervalInMilliseconds = value
self._send_interval_in_milliseconds = value
@property
def maxQueueItemCount(self):
def max_queue_item_count(self):
"""Gets or sets the maximum number of items that will be held by the queue before we force a send."""
return self.__maxQueueItemCount
return self._max_queue_item_count
@maxQueueItemCount.setter
def maxQueueItemCount(self, value):
@max_queue_item_count.setter
def max_queue_item_count(self, value):
"""Gets or sets the maximum number of items that will be held by the queue before we force a send."""
if value < 1:
value = 1
self.__maxQueueItemCount = value
self._max_queue_item_count = value
def send(self, envelope):
"""Enqueues the specified envelope into our queue. If the queue is full, this function will also trigger a send."""
self.__sendQueue.append(envelope)
self.__maybeCreateTimer()
self._queue.append(envelope)
self._maybe_create_timer()
def __maybeCreateTimer(self):
if len(self.__timers) == 0 or len(self.__sendQueue) >= self.maxQueueItemCount:
dueTime = self.__sendIntervalInMilliseconds / 1000.0
if len(self.__sendQueue) >= self.maxQueueItemCount:
dueTime = 1 / 1000.0
def _maybe_create_timer(self):
if len(self._timers) == 0 or len(self._queue) >= self.max_queue_item_count:
due_time = self._send_interval_in_milliseconds / 1000.0
if len(self._queue) >= self.max_queue_item_count:
due_time = 1 / 1000.0
timer = threading.Timer(self.__sendIntervalInMilliseconds / 1000.0, self.__scheduleSend)
timer = threading.Timer(self._send_interval_in_milliseconds / 1000.0, self._schedule_send)
timer.args.append(timer)
self.__timers.append(timer)
self._timers.append(timer)
timer.start()
def __scheduleSend(self, timer):
self.__send()
self.__timers.remove(timer)
if len(self.__sendQueue) > 0:
self.__maybeCreateTimer()
def _schedule_send(self, timer):
self._send()
self._timers.remove(timer)
if len(self._queue) > 0:
self._maybe_create_timer()
def __send(self):
dataToSend = []
for i in range(len(self.__sendQueue)):
def _send(self):
data_to_send = []
for i in range(len(self._queue)):
try:
dataToSend.append(self.__sendQueue.pop())
data_to_send.append(self._queue.pop())
except IndexError:
break
if len(dataToSend) == 0:
if len(data_to_send) == 0:
return
dataToSend.reverse()
first = True
payload = "["
for data in dataToSend:
if not first:
payload += ","
first = False
payload += data.serialize()
payload += "]"
data_to_send.reverse()
data_to_send = [ a.write() for a in data_to_send ]
request_payload = json.dumps(data_to_send)
request = urllib2.Request(self.__serviceEndpointUri, bytearray(payload, "utf-8"), { "Accept": "application/json", "Content-Type" : "application/json; charset=utf-8" })
request = HTTPClient.Request(self._service_endpoint_uri, bytearray(request_payload, 'utf-8'), { 'Accept': 'application/json', 'Content-Type' : 'application/json; charset=utf-8' })
try:
response = urllib2.urlopen(request)
statusCode = response.getcode()
responsePayload = response.read()
if statusCode >= 200 and statusCode < 300:
response = HTTPClient.urlopen(request)
status_code = response.getcode()
response_payload = response.read()
if 200 <= status_code < 300:
return
except HTTPError as e:
if e.getcode() == 400:
@ -112,80 +111,67 @@ class TelemetrySender(object):
except Exception as e:
pass
if len(dataToSend) + len(self.__sendQueue) < self.__maxQueueItemCount:
if len(data_to_send) + len(self._queue) < self._max_queue_item_count:
# If the unsent amount will put us over the top of the max queue length, drop the data to prevent infinate loops
# Otherwise, add our unsent data back on to the queue
for data in dataToSend:
self.__sendQueue.append(data)
for data in data_to_send:
self._queue.append(data)
class TelemetryChannel(object):
# The type moniker map. This will map a type of telemetry to metadata needed to construct the envelope.
__typeMonikerMap = { "EventTelemetry": ("Microsoft.ApplicationInsights.Event", "Microsoft.ApplicationInsights.EventData"),
"MetricTelemetry": ("Microsoft.ApplicationInsights.Metric", "Microsoft.ApplicationInsights.MetricData"),
"MessageTelemetry": ("Microsoft.ApplicationInsights.Message", "Microsoft.ApplicationInsights.MessageData"),
"PageViewTelemetry": ("Microsoft.ApplicationInsights.Pageview", "Microsoft.ApplicationInsights.PageviewData"),
"ExceptionTelemetry": ("Microsoft.ApplicationInsights.Exception", "Microsoft.ApplicationInsights.ExceptionData")}
"""The telemetry channel is responsible for constructing an envelope an sending it."""
def __init__(self, context=None, sender=None):
"""Initializes a new instance of the telemetry channel class."""
self.__context = context
self.__sender = sender
if not sender or not isinstance(sender, TelemetrySender):
self.__sender = TelemetrySender()
self._context = context
self._sender = sender or TelemetrySender()
@property
def context(self):
"""Gets the global TelemetryContext associated with this client."""
return self.__context
return self._context
@property
def sender(self):
"""Gets the TelemetrySender associated with this client."""
return self.__sender
return self._sender
def write(self, data, context=None):
"""writes the passed in data to the sending queue."""
localContext = context
if not localContext:
localContext = self.__context
if not localContext:
raise Exception("Context was required but not provided")
local_context = context or self._context
if not local_context:
raise Exception('Context was required but not provided')
if not data:
raise Exception("Data was required but not provided")
raise Exception('Data was required but not provided')
dataType = ""
if "__class__" in dir(data):
dataType = data.__class__.__name__
else:
raise Exception("Data must be a class")
envelope = contracts.Envelope()
envelope.name = data.ENVELOPE_TYPE_NAME
envelope.time = datetime.datetime.utcnow().isoformat() + 'Z'
envelope.ikey = local_context.instrumentation_key
tags = envelope.tags
for key, value in self._write_tags(local_context):
tags[key] = value
envelope.data = contracts.Data()
envelope.data.base_type = data.DATA_TYPE_NAME
if hasattr(data, 'properties') and local_context.properties:
properties = data.properties
if not properties:
properties = {}
data.properties = properties
for key, value in local_context.properties:
if key not in properties:
properties[key] = value
envelope.data.base_data = data
typeMonikers = None
if dataType in self.__typeMonikerMap:
typeMonikers = self.__typeMonikerMap[dataType]
else:
raise Exception("Data is out or range")
self._sender.send(envelope)
def _write_tags(self, context):
for item in [ internal_context, context.device, context.application, context.user, context.session, context.location, context.operation ]:
if not item:
continue
for pair in item.write().items():
yield pair
envelope = contracts.TelemetryEnvelope()
envelope.name = typeMonikers[0]
envelope.time = datetime.datetime.utcnow().isoformat() + "Z"
envelope.iKey = localContext.instrumentationKey
envelope.device = localContext.device
envelope.application = localContext.application
envelope.user = localContext.user
envelope.session = localContext.session
envelope.location = localContext.location
envelope.operation = localContext.operation
envelope.data = contracts.TelemetryEnvelopeData()
envelope.data.type = typeMonikers[1]
envelope.data.item = data
envelope.data.item.properties["SDKVersion"] = "Python;0.1";
self.__sender.send(envelope)

Просмотреть файл

@ -5,99 +5,33 @@ import uuid
from applicationinsights.channel import contracts
def deviceInitializer(self):
# save off whatever is currently there
existing_device_initialize = contracts.Device._initialize
def device_initialize(self):
""" The device initializer used to assign special properties to all device context objects"""
self.type = "Other"
existing_device_initialize(self)
self.type = 'Other'
self.id = platform.node()
self.osVersion = platform.version()
self.os_version = platform.version()
self.locale = locale.getdefaultlocale()[0]
# assign the device context initializer
contracts.DeviceContext.initialize = deviceInitializer
contracts.Device._initialize = device_initialize
class TelemetryContext(object):
"""Represents a context for sending telemetry to the Application Insights service."""
def __init__(self):
"""Initializes a new instance of the TelemetryContext class."""
self.__instrumentationKey = None
self.__device = contracts.DeviceContext()
self.__application = contracts.ApplicationContext()
self.__user = contracts.UserContext()
self.__session = contracts.SessionContext()
self.__operation = contracts.OperationContext()
self.__location = contracts.LocationContext()
self.__properties = {}
@property
def instrumentationKey(self):
"""Gets or sets the instrumentation key for this TelemetryContext."""
return self.__instrumentationKey
@instrumentationKey.setter
def instrumentationKey(self, value):
self.__instrumentationKey = value
@property
def device(self):
"""Gets or sets the object describing the device tracked by this TelemetryContext."""
return self.__device
@device.setter
def device(self, value):
if isinstance(value, contracts.DeviceContext) or not value:
self.__device = value
@property
def application(self):
"""Gets or sets the object describing the component tracked by this TelemetryContext."""
return self.__application
@application.setter
def application(self, value):
if isinstance(value, contracts.ApplicationContext) or not value:
self.__application = value
@property
def user(self):
"""Gets or sets the object describing a user tracked by this TelemetryContext."""
return self.__user
@user.setter
def user(self, value):
if isinstance(value, contracts.UserContext) or not value:
self.__user = value
@property
def session(self):
"""Gets or sets the object describing a user session tracked by this TelemetryContext."""
return self.__session
@session.setter
def session(self, value):
if isinstance(value, contracts.SessionContext) or not value:
self.__session = value
@property
def location(self):
"""Gets or sets the object describing a location tracked by this TelemetryContext."""
return self.__location
@location.setter
def location(self, value):
if isinstance(value, contracts.LocationContext) or not value:
self.__location = value
@property
def operation(self):
"""Gets or sets the object describing a operation tracked by this TelemetryContext."""
return self.__operation
@operation.setter
def operation(self, value):
if isinstance(value, contracts.OperationContext) or not value:
self.__operation = value
self.instrumentation_key = None
self.device = contracts.Device()
self.application = contracts.Application()
self.user = contracts.User()
self.session = contracts.Session()
self.operation = contracts.Operation()
self.location = contracts.Location()
self._properties = {}
@property
def properties(self):
"""Gets a dictionary of application-defined property values.."""
return self.__properties
return self._properties

Просмотреть файл

@ -0,0 +1,38 @@
import collections
import copy
from .Utils import _write_complex_object
class Application(object):
"""Data contract class for type Application."""
_defaults = collections.OrderedDict([
('ai.application.ver', None)
])
def __init__(self):
"""Initializes a new instance of the Application class."""
self._values = {
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
if 'ai.application.ver' in self._values:
return self._values['ai.application.ver']
return self._defaults['ai.application.ver']
@ver.setter
def ver(self, value):
if value == self._defaults['ai.application.ver'] and 'ai.application.ver' in self._values:
del self._values['ai.application.ver']
else:
self._values['ai.application.ver'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,50 +0,0 @@
import json
class ApplicationContext(object):
"""Data contract class for type ApplicationContext."""
def __init__(self):
"""Initializes a new instance of the ApplicationContext class."""
self.__instanceVersion = 0
self.__id = "Unknown"
self.__ver = "Unknown"
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
if self.__id != None:
output += prefix + "\"id\":"
output += json.dumps(self.__id)
prefix = ","
if self.__ver != None:
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,49 @@
import collections
import copy
from .Utils import _write_complex_object
class Data(object):
"""Data contract class for type Data."""
_defaults = collections.OrderedDict([
('baseType', None),
('baseData', None)
])
def __init__(self):
"""Initializes a new instance of the Data class."""
self._values = {
'baseData': None
}
self._initialize()
@property
def base_type(self):
"""Gets or sets the base_type property."""
if 'baseType' in self._values:
return self._values['baseType']
return self._defaults['baseType']
@base_type.setter
def base_type(self, value):
if value == self._defaults['baseType'] and 'baseType' in self._values:
del self._values['baseType']
else:
self._values['baseType'] = value
@property
def base_data(self):
"""Gets or sets the base_data property."""
return self._values['baseData']
@base_data.setter
def base_data(self, value):
self._values['baseData'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -0,0 +1,122 @@
import collections
import copy
from .Utils import _write_complex_object
from .DataPointType import DataPointType
class DataPoint(object):
"""Data contract class for type DataPoint."""
_defaults = collections.OrderedDict([
('name', None),
('kind', DataPointType.measurement),
('value', None),
('count', None),
('min', None),
('max', None),
('stdDev', None)
])
def __init__(self):
"""Initializes a new instance of the DataPoint class."""
self._values = {
'name': None,
'kind': DataPointType.measurement,
'value': None,
}
self._initialize()
@property
def name(self):
"""Gets or sets the name property."""
return self._values['name']
@name.setter
def name(self, value):
self._values['name'] = value
@property
def kind(self):
"""Gets or sets the kind property."""
if 'kind' in self._values:
return self._values['kind']
return self._defaults['kind']
@kind.setter
def kind(self, value):
if value == self._defaults['kind'] and 'kind' in self._values:
del self._values['kind']
else:
self._values['kind'] = value
@property
def value(self):
"""Gets or sets the value property."""
return self._values['value']
@value.setter
def value(self, value):
self._values['value'] = value
@property
def count(self):
"""Gets or sets the count property."""
if 'count' in self._values:
return self._values['count']
return self._defaults['count']
@count.setter
def count(self, value):
if value == self._defaults['count'] and 'count' in self._values:
del self._values['count']
else:
self._values['count'] = value
@property
def min(self):
"""Gets or sets the min property."""
if 'min' in self._values:
return self._values['min']
return self._defaults['min']
@min.setter
def min(self, value):
if value == self._defaults['min'] and 'min' in self._values:
del self._values['min']
else:
self._values['min'] = value
@property
def max(self):
"""Gets or sets the max property."""
if 'max' in self._values:
return self._values['max']
return self._defaults['max']
@max.setter
def max(self, value):
if value == self._defaults['max'] and 'max' in self._values:
del self._values['max']
else:
self._values['max'] = value
@property
def std_dev(self):
"""Gets or sets the std_dev property."""
if 'stdDev' in self._values:
return self._values['stdDev']
return self._defaults['stdDev']
@std_dev.setter
def std_dev(self, value):
if value == self._defaults['stdDev'] and 'stdDev' in self._values:
del self._values['stdDev']
else:
self._values['stdDev'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -0,0 +1,9 @@
class DataPointType(object):
"""Data contract class for type DataPointType."""
# Enumeration value measurement
measurement = 0
# Enumeration value aggregation
aggregation = 1

Просмотреть файл

@ -0,0 +1,15 @@
class DependencyKind(object):
"""Data contract class for type DependencyKind."""
# Enumeration value undefined
undefined = 0
# Enumeration value http_only
http_only = 1
# Enumeration value http_any
http_any = 2
# Enumeration value sql
sql = 3

Просмотреть файл

@ -0,0 +1,12 @@
class DependencySourceType(object):
"""Data contract class for type DependencySourceType."""
# Enumeration value undefined
undefined = 0
# Enumeration value aic
aic = 1
# Enumeration value apmc
apmc = 2

Просмотреть файл

@ -0,0 +1,233 @@
import collections
import copy
from .Utils import _write_complex_object
class Device(object):
"""Data contract class for type Device."""
_defaults = collections.OrderedDict([
('ai.device.id', None),
('ai.device.ip', None),
('ai.device.language', None),
('ai.device.locale', None),
('ai.device.model', None),
('ai.device.network', None),
('ai.device.oemName', None),
('ai.device.os', None),
('ai.device.osVersion', None),
('ai.device.roleInstance', None),
('ai.device.roleName', None),
('ai.device.screenResolution', None),
('ai.device.type', None),
('ai.device.vmName', None)
])
def __init__(self):
"""Initializes a new instance of the Device class."""
self._values = {
}
self._initialize()
@property
def id(self):
"""Gets or sets the id property."""
if 'ai.device.id' in self._values:
return self._values['ai.device.id']
return self._defaults['ai.device.id']
@id.setter
def id(self, value):
if value == self._defaults['ai.device.id'] and 'ai.device.id' in self._values:
del self._values['ai.device.id']
else:
self._values['ai.device.id'] = value
@property
def ip(self):
"""Gets or sets the ip property."""
if 'ai.device.ip' in self._values:
return self._values['ai.device.ip']
return self._defaults['ai.device.ip']
@ip.setter
def ip(self, value):
if value == self._defaults['ai.device.ip'] and 'ai.device.ip' in self._values:
del self._values['ai.device.ip']
else:
self._values['ai.device.ip'] = value
@property
def language(self):
"""Gets or sets the language property."""
if 'ai.device.language' in self._values:
return self._values['ai.device.language']
return self._defaults['ai.device.language']
@language.setter
def language(self, value):
if value == self._defaults['ai.device.language'] and 'ai.device.language' in self._values:
del self._values['ai.device.language']
else:
self._values['ai.device.language'] = value
@property
def locale(self):
"""Gets or sets the locale property."""
if 'ai.device.locale' in self._values:
return self._values['ai.device.locale']
return self._defaults['ai.device.locale']
@locale.setter
def locale(self, value):
if value == self._defaults['ai.device.locale'] and 'ai.device.locale' in self._values:
del self._values['ai.device.locale']
else:
self._values['ai.device.locale'] = value
@property
def model(self):
"""Gets or sets the model property."""
if 'ai.device.model' in self._values:
return self._values['ai.device.model']
return self._defaults['ai.device.model']
@model.setter
def model(self, value):
if value == self._defaults['ai.device.model'] and 'ai.device.model' in self._values:
del self._values['ai.device.model']
else:
self._values['ai.device.model'] = value
@property
def network(self):
"""Gets or sets the network property."""
if 'ai.device.network' in self._values:
return self._values['ai.device.network']
return self._defaults['ai.device.network']
@network.setter
def network(self, value):
if value == self._defaults['ai.device.network'] and 'ai.device.network' in self._values:
del self._values['ai.device.network']
else:
self._values['ai.device.network'] = value
@property
def oem_name(self):
"""Gets or sets the oem_name property."""
if 'ai.device.oemName' in self._values:
return self._values['ai.device.oemName']
return self._defaults['ai.device.oemName']
@oem_name.setter
def oem_name(self, value):
if value == self._defaults['ai.device.oemName'] and 'ai.device.oemName' in self._values:
del self._values['ai.device.oemName']
else:
self._values['ai.device.oemName'] = value
@property
def os(self):
"""Gets or sets the os property."""
if 'ai.device.os' in self._values:
return self._values['ai.device.os']
return self._defaults['ai.device.os']
@os.setter
def os(self, value):
if value == self._defaults['ai.device.os'] and 'ai.device.os' in self._values:
del self._values['ai.device.os']
else:
self._values['ai.device.os'] = value
@property
def os_version(self):
"""Gets or sets the os_version property."""
if 'ai.device.osVersion' in self._values:
return self._values['ai.device.osVersion']
return self._defaults['ai.device.osVersion']
@os_version.setter
def os_version(self, value):
if value == self._defaults['ai.device.osVersion'] and 'ai.device.osVersion' in self._values:
del self._values['ai.device.osVersion']
else:
self._values['ai.device.osVersion'] = value
@property
def role_instance(self):
"""Gets or sets the role_instance property."""
if 'ai.device.roleInstance' in self._values:
return self._values['ai.device.roleInstance']
return self._defaults['ai.device.roleInstance']
@role_instance.setter
def role_instance(self, value):
if value == self._defaults['ai.device.roleInstance'] and 'ai.device.roleInstance' in self._values:
del self._values['ai.device.roleInstance']
else:
self._values['ai.device.roleInstance'] = value
@property
def role_name(self):
"""Gets or sets the role_name property."""
if 'ai.device.roleName' in self._values:
return self._values['ai.device.roleName']
return self._defaults['ai.device.roleName']
@role_name.setter
def role_name(self, value):
if value == self._defaults['ai.device.roleName'] and 'ai.device.roleName' in self._values:
del self._values['ai.device.roleName']
else:
self._values['ai.device.roleName'] = value
@property
def screen_resolution(self):
"""Gets or sets the screen_resolution property."""
if 'ai.device.screenResolution' in self._values:
return self._values['ai.device.screenResolution']
return self._defaults['ai.device.screenResolution']
@screen_resolution.setter
def screen_resolution(self, value):
if value == self._defaults['ai.device.screenResolution'] and 'ai.device.screenResolution' in self._values:
del self._values['ai.device.screenResolution']
else:
self._values['ai.device.screenResolution'] = value
@property
def type(self):
"""Gets or sets the type property."""
if 'ai.device.type' in self._values:
return self._values['ai.device.type']
return self._defaults['ai.device.type']
@type.setter
def type(self, value):
if value == self._defaults['ai.device.type'] and 'ai.device.type' in self._values:
del self._values['ai.device.type']
else:
self._values['ai.device.type'] = value
@property
def vm_name(self):
"""Gets or sets the vm_name property."""
if 'ai.device.vmName' in self._values:
return self._values['ai.device.vmName']
return self._defaults['ai.device.vmName']
@vm_name.setter
def vm_name(self, value):
if value == self._defaults['ai.device.vmName'] and 'ai.device.vmName' in self._values:
del self._values['ai.device.vmName']
else:
self._values['ai.device.vmName'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,143 +0,0 @@
import json
class DeviceContext(object):
"""Data contract class for type DeviceContext."""
def __init__(self):
"""Initializes a new instance of the DeviceContext class."""
self.__instanceVersion = 0
self.__type = "Other"
self.__id = "Unknown"
self.__os = "Unknown OS"
self.__osVersion = "Unknown"
self.__oemName = None
self.__model = None
self.__network = None
self.__resolution = None
self.__locale = "Unknown"
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def type(self):
"""Gets or sets the 'type' property."""
return self.__type
@type.setter
def type(self, value):
self.__type = value
self.__instanceVersion += 1
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
@property
def os(self):
"""Gets or sets the 'os' property."""
return self.__os
@os.setter
def os(self, value):
self.__os = value
self.__instanceVersion += 1
@property
def osVersion(self):
"""Gets or sets the 'osVersion' property."""
return self.__osVersion
@osVersion.setter
def osVersion(self, value):
self.__osVersion = value
self.__instanceVersion += 1
@property
def oemName(self):
"""Gets or sets the 'oemName' property."""
return self.__oemName
@oemName.setter
def oemName(self, value):
self.__oemName = value
self.__instanceVersion += 1
@property
def model(self):
"""Gets or sets the 'model' property."""
return self.__model
@model.setter
def model(self, value):
self.__model = value
self.__instanceVersion += 1
@property
def network(self):
"""Gets or sets the 'network' property."""
return self.__network
@network.setter
def network(self, value):
self.__network = value
self.__instanceVersion += 1
@property
def resolution(self):
"""Gets or sets the 'resolution' property."""
return self.__resolution
@resolution.setter
def resolution(self, value):
self.__resolution = value
self.__instanceVersion += 1
@property
def locale(self):
"""Gets or sets the 'locale' property."""
return self.__locale
@locale.setter
def locale(self, value):
self.__locale = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"type\":"
output += json.dumps(self.__type)
prefix = ","
output += prefix + "\"id\":"
output += json.dumps(self.__id)
output += prefix + "\"os\":"
output += json.dumps(self.__os)
output += prefix + "\"osVersion\":"
output += json.dumps(self.__osVersion)
if self.__oemName != None:
output += prefix + "\"oemName\":"
output += json.dumps(self.__oemName)
if self.__model != None:
output += prefix + "\"model\":"
output += json.dumps(self.__model)
if self.__network != None:
output += prefix + "\"network\":"
output += json.dumps(self.__network)
if self.__resolution != None:
output += prefix + "\"resolution\":"
output += json.dumps(self.__resolution)
output += prefix + "\"locale\":"
output += json.dumps(self.__locale)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,243 @@
import collections
import copy
from .Utils import _write_complex_object
class Envelope(object):
"""Data contract class for type Envelope."""
_defaults = collections.OrderedDict([
('ver', 1),
('name', None),
('time', None),
('sampleRate', 100.0),
('seq', None),
('iKey', None),
('flags', None),
('deviceId', None),
('os', None),
('osVer', None),
('appId', None),
('appVer', None),
('userId', None),
('tags', {}),
('data', None)
])
def __init__(self):
"""Initializes a new instance of the Envelope class."""
self._values = {
'ver': 1,
'name': None,
'time': None,
'sampleRate': 100.0,
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
if 'ver' in self._values:
return self._values['ver']
return self._defaults['ver']
@ver.setter
def ver(self, value):
if value == self._defaults['ver'] and 'ver' in self._values:
del self._values['ver']
else:
self._values['ver'] = value
@property
def name(self):
"""Gets or sets the name property."""
return self._values['name']
@name.setter
def name(self, value):
self._values['name'] = value
@property
def time(self):
"""Gets or sets the time property."""
return self._values['time']
@time.setter
def time(self, value):
self._values['time'] = value
@property
def sample_rate(self):
"""Gets or sets the sample_rate property."""
if 'sampleRate' in self._values:
return self._values['sampleRate']
return self._defaults['sampleRate']
@sample_rate.setter
def sample_rate(self, value):
if value == self._defaults['sampleRate'] and 'sampleRate' in self._values:
del self._values['sampleRate']
else:
self._values['sampleRate'] = value
@property
def seq(self):
"""Gets or sets the seq property."""
if 'seq' in self._values:
return self._values['seq']
return self._defaults['seq']
@seq.setter
def seq(self, value):
if value == self._defaults['seq'] and 'seq' in self._values:
del self._values['seq']
else:
self._values['seq'] = value
@property
def ikey(self):
"""Gets or sets the ikey property."""
if 'iKey' in self._values:
return self._values['iKey']
return self._defaults['iKey']
@ikey.setter
def ikey(self, value):
if value == self._defaults['iKey'] and 'iKey' in self._values:
del self._values['iKey']
else:
self._values['iKey'] = value
@property
def flags(self):
"""Gets or sets the flags property."""
if 'flags' in self._values:
return self._values['flags']
return self._defaults['flags']
@flags.setter
def flags(self, value):
if value == self._defaults['flags'] and 'flags' in self._values:
del self._values['flags']
else:
self._values['flags'] = value
@property
def device_id(self):
"""Gets or sets the device_id property."""
if 'deviceId' in self._values:
return self._values['deviceId']
return self._defaults['deviceId']
@device_id.setter
def device_id(self, value):
if value == self._defaults['deviceId'] and 'deviceId' in self._values:
del self._values['deviceId']
else:
self._values['deviceId'] = value
@property
def os(self):
"""Gets or sets the os property."""
if 'os' in self._values:
return self._values['os']
return self._defaults['os']
@os.setter
def os(self, value):
if value == self._defaults['os'] and 'os' in self._values:
del self._values['os']
else:
self._values['os'] = value
@property
def os_ver(self):
"""Gets or sets the os_ver property."""
if 'osVer' in self._values:
return self._values['osVer']
return self._defaults['osVer']
@os_ver.setter
def os_ver(self, value):
if value == self._defaults['osVer'] and 'osVer' in self._values:
del self._values['osVer']
else:
self._values['osVer'] = value
@property
def app_id(self):
"""Gets or sets the app_id property."""
if 'appId' in self._values:
return self._values['appId']
return self._defaults['appId']
@app_id.setter
def app_id(self, value):
if value == self._defaults['appId'] and 'appId' in self._values:
del self._values['appId']
else:
self._values['appId'] = value
@property
def app_ver(self):
"""Gets or sets the app_ver property."""
if 'appVer' in self._values:
return self._values['appVer']
return self._defaults['appVer']
@app_ver.setter
def app_ver(self, value):
if value == self._defaults['appVer'] and 'appVer' in self._values:
del self._values['appVer']
else:
self._values['appVer'] = value
@property
def user_id(self):
"""Gets or sets the user_id property."""
if 'userId' in self._values:
return self._values['userId']
return self._defaults['userId']
@user_id.setter
def user_id(self, value):
if value == self._defaults['userId'] and 'userId' in self._values:
del self._values['userId']
else:
self._values['userId'] = value
@property
def tags(self):
"""Gets or sets the tags property."""
if 'tags' in self._values:
return self._values['tags']
self._values['tags'] = copy.deepcopy(self._defaults['tags'])
return self._values['tags']
@tags.setter
def tags(self, value):
if value == self._defaults['tags'] and 'tags' in self._values:
del self._values['tags']
else:
self._values['tags'] = value
@property
def data(self):
"""Gets or sets the data property."""
if 'data' in self._values:
return self._values['data']
return self._defaults['data']
@data.setter
def data(self, value):
if value == self._defaults['data'] and 'data' in self._values:
del self._values['data']
else:
self._values['data'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -0,0 +1,81 @@
import collections
import copy
from .Utils import _write_complex_object
class EventData(object):
"""Data contract class for type EventData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.Event'
DATA_TYPE_NAME = 'EventData'
_defaults = collections.OrderedDict([
('ver', 2),
('name', None),
('properties', {}),
('measurements', {})
])
def __init__(self):
"""Initializes a new instance of the EventData class."""
self._values = {
'ver': 2,
'name': None,
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def name(self):
"""Gets or sets the name property."""
return self._values['name']
@name.setter
def name(self, value):
self._values['name'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
@property
def measurements(self):
"""Gets or sets the measurements property."""
if 'measurements' in self._values:
return self._values['measurements']
self._values['measurements'] = copy.deepcopy(self._defaults['measurements'])
return self._values['measurements']
@measurements.setter
def measurements(self, value):
if value == self._defaults['measurements'] and 'measurements' in self._values:
del self._values['measurements']
else:
self._values['measurements'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,76 +0,0 @@
import json
class EventTelemetry(object):
"""Data contract class for type EventTelemetry."""
def __init__(self):
"""Initializes a new instance of the EventTelemetry class."""
self.__instanceVersion = 0
self.__ver = 1
self.__name = None
self.__properties = {}
self.__measurements = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def name(self):
"""Gets or sets the 'name' property."""
return self.__name
@name.setter
def name(self, value):
self.__name = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
@property
def measurements(self):
"""Gets or sets the 'measurements' property."""
return self.__measurements
@measurements.setter
def measurements(self, value):
self.__measurements = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
output += prefix + "\"name\":"
output += json.dumps(self.__name)
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
if self.__measurements != None:
output += prefix + "\"measurements\":"
output += json.dumps(self.__measurements)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,107 @@
import collections
import copy
from .Utils import _write_complex_object
class ExceptionData(object):
"""Data contract class for type ExceptionData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.Exception'
DATA_TYPE_NAME = 'ExceptionData'
_defaults = collections.OrderedDict([
('ver', 2),
('handledAt', None),
('exceptions', []),
('severityLevel', None),
('properties', {}),
('measurements', {})
])
def __init__(self):
"""Initializes a new instance of the ExceptionData class."""
self._values = {
'ver': 2,
'handledAt': None,
'exceptions': [],
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def handled_at(self):
"""Gets or sets the handled_at property."""
return self._values['handledAt']
@handled_at.setter
def handled_at(self, value):
self._values['handledAt'] = value
@property
def exceptions(self):
"""Gets or sets the exceptions property."""
return self._values['exceptions']
@exceptions.setter
def exceptions(self, value):
self._values['exceptions'] = value
@property
def severity_level(self):
"""Gets or sets the severity_level property."""
if 'severityLevel' in self._values:
return self._values['severityLevel']
return self._defaults['severityLevel']
@severity_level.setter
def severity_level(self, value):
if value == self._defaults['severityLevel'] and 'severityLevel' in self._values:
del self._values['severityLevel']
else:
self._values['severityLevel'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
@property
def measurements(self):
"""Gets or sets the measurements property."""
if 'measurements' in self._values:
return self._values['measurements']
self._values['measurements'] = copy.deepcopy(self._defaults['measurements'])
return self._values['measurements']
@measurements.setter
def measurements(self, value):
if value == self._defaults['measurements'] and 'measurements' in self._values:
del self._values['measurements']
else:
self._values['measurements'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -0,0 +1,122 @@
import collections
import copy
from .Utils import _write_complex_object
class ExceptionDetails(object):
"""Data contract class for type ExceptionDetails."""
_defaults = collections.OrderedDict([
('id', None),
('outerId', None),
('typeName', None),
('message', None),
('hasFullStack', True),
('stack', None),
('parsedStack', [])
])
def __init__(self):
"""Initializes a new instance of the ExceptionDetails class."""
self._values = {
'typeName': None,
'message': None,
'hasFullStack': True,
}
self._initialize()
@property
def id(self):
"""Gets or sets the id property."""
if 'id' in self._values:
return self._values['id']
return self._defaults['id']
@id.setter
def id(self, value):
if value == self._defaults['id'] and 'id' in self._values:
del self._values['id']
else:
self._values['id'] = value
@property
def outer_id(self):
"""Gets or sets the outer_id property."""
if 'outerId' in self._values:
return self._values['outerId']
return self._defaults['outerId']
@outer_id.setter
def outer_id(self, value):
if value == self._defaults['outerId'] and 'outerId' in self._values:
del self._values['outerId']
else:
self._values['outerId'] = value
@property
def type_name(self):
"""Gets or sets the type_name property."""
return self._values['typeName']
@type_name.setter
def type_name(self, value):
self._values['typeName'] = value
@property
def message(self):
"""Gets or sets the message property."""
return self._values['message']
@message.setter
def message(self, value):
self._values['message'] = value
@property
def has_full_stack(self):
"""Gets or sets the has_full_stack property."""
if 'hasFullStack' in self._values:
return self._values['hasFullStack']
return self._defaults['hasFullStack']
@has_full_stack.setter
def has_full_stack(self, value):
if value == self._defaults['hasFullStack'] and 'hasFullStack' in self._values:
del self._values['hasFullStack']
else:
self._values['hasFullStack'] = value
@property
def stack(self):
"""Gets or sets the stack property."""
if 'stack' in self._values:
return self._values['stack']
return self._defaults['stack']
@stack.setter
def stack(self, value):
if value == self._defaults['stack'] and 'stack' in self._values:
del self._values['stack']
else:
self._values['stack'] = value
@property
def parsed_stack(self):
"""Gets or sets the parsed_stack property."""
if 'parsedStack' in self._values:
return self._values['parsedStack']
self._values['parsedStack'] = copy.deepcopy(self._defaults['parsedStack'])
return self._values['parsedStack']
@parsed_stack.setter
def parsed_stack(self, value):
if value == self._defaults['parsedStack'] and 'parsedStack' in self._values:
del self._values['parsedStack']
else:
self._values['parsedStack'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,93 +0,0 @@
import json
class ExceptionTelemetry(object):
"""Data contract class for type ExceptionTelemetry."""
def __init__(self):
"""Initializes a new instance of the ExceptionTelemetry class."""
self.__instanceVersion = 0
self.__ver = 1
self.__handledAt = "UserCode"
self.__exceptions = []
self.__properties = {}
self.__measurements = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def handledAt(self):
"""Gets or sets the 'handledAt' property."""
return self.__handledAt
@handledAt.setter
def handledAt(self, value):
self.__handledAt = value
self.__instanceVersion += 1
@property
def exceptions(self):
"""Gets or sets the 'exceptions' property."""
return self.__exceptions
@exceptions.setter
def exceptions(self, value):
self.__exceptions = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
@property
def measurements(self):
"""Gets or sets the 'measurements' property."""
return self.__measurements
@measurements.setter
def measurements(self, value):
self.__measurements = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
output += prefix + "\"handledAt\":"
output += json.dumps(self.__handledAt)
arrayPrefix = ""
output += prefix + "\"exceptions\":["
for item in self.__exceptions:
output += arrayPrefix + item.serialize()
arrayPrefix = ","
output += "]"
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
if self.__measurements != None:
output += prefix + "\"measurements\":"
output += json.dumps(self.__measurements)
output += "}"
return output

Просмотреть файл

@ -1,120 +0,0 @@
import json
class ExceptionTelemetryDetails(object):
"""Data contract class for type ExceptionTelemetryDetails."""
def __init__(self):
"""Initializes a new instance of the ExceptionTelemetryDetails class."""
self.__instanceVersion = 0
self.__id = None
self.__outerId = None
self.__typeName = None
self.__message = None
self.__hasFullStack = True
self.__stack = None
self.__parsedStack = []
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
@property
def outerId(self):
"""Gets or sets the 'outerId' property."""
return self.__outerId
@outerId.setter
def outerId(self, value):
self.__outerId = value
self.__instanceVersion += 1
@property
def typeName(self):
"""Gets or sets the 'typeName' property."""
return self.__typeName
@typeName.setter
def typeName(self, value):
self.__typeName = value
self.__instanceVersion += 1
@property
def message(self):
"""Gets or sets the 'message' property."""
return self.__message
@message.setter
def message(self, value):
self.__message = value
self.__instanceVersion += 1
@property
def hasFullStack(self):
"""Gets or sets the 'hasFullStack' property."""
return self.__hasFullStack
@hasFullStack.setter
def hasFullStack(self, value):
self.__hasFullStack = value
self.__instanceVersion += 1
@property
def stack(self):
"""Gets or sets the 'stack' property."""
return self.__stack
@stack.setter
def stack(self, value):
self.__stack = value
self.__instanceVersion += 1
@property
def parsedStack(self):
"""Gets or sets the 'parsedStack' property."""
return self.__parsedStack
@parsedStack.setter
def parsedStack(self, value):
self.__parsedStack = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"id\":"
output += json.dumps(self.__id)
prefix = ","
if self.__outerId != None:
output += prefix + "\"outerId\":"
output += json.dumps(self.__outerId)
output += prefix + "\"typeName\":"
output += json.dumps(self.__typeName)
output += prefix + "\"message\":"
output += json.dumps(self.__message)
output += prefix + "\"hasFullStack\":"
output += json.dumps(self.__hasFullStack)
if self.__stack != None:
output += prefix + "\"stack\":"
output += json.dumps(self.__stack)
if self.__parsedStack != None:
arrayPrefix = ""
output += prefix + "\"parsedStack\":["
for item in self.__parsedStack:
output += arrayPrefix + item.serialize()
arrayPrefix = ","
output += "]"
output += "}"
return output

Просмотреть файл

@ -1,92 +0,0 @@
import json
class ExceptionTelemetryStackFrame(object):
"""Data contract class for type ExceptionTelemetryStackFrame."""
def __init__(self):
"""Initializes a new instance of the ExceptionTelemetryStackFrame class."""
self.__instanceVersion = 0
self.__level = None
self.__method = None
self.__assembly = None
self.__fileName = None
self.__line = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def level(self):
"""Gets or sets the 'level' property."""
return self.__level
@level.setter
def level(self, value):
self.__level = value
self.__instanceVersion += 1
@property
def method(self):
"""Gets or sets the 'method' property."""
return self.__method
@method.setter
def method(self, value):
self.__method = value
self.__instanceVersion += 1
@property
def assembly(self):
"""Gets or sets the 'assembly' property."""
return self.__assembly
@assembly.setter
def assembly(self, value):
self.__assembly = value
self.__instanceVersion += 1
@property
def fileName(self):
"""Gets or sets the 'fileName' property."""
return self.__fileName
@fileName.setter
def fileName(self, value):
self.__fileName = value
self.__instanceVersion += 1
@property
def line(self):
"""Gets or sets the 'line' property."""
return self.__line
@line.setter
def line(self, value):
self.__line = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
if self.__level != None:
output += prefix + "\"level\":"
output += json.dumps(self.__level)
prefix = ","
output += prefix + "\"method\":"
output += json.dumps(self.__method)
prefix = ","
if self.__assembly != None:
output += prefix + "\"assembly\":"
output += json.dumps(self.__assembly)
if self.__fileName != None:
output += prefix + "\"fileName\":"
output += json.dumps(self.__fileName)
if self.__line != None:
output += prefix + "\"line\":"
output += json.dumps(self.__line)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,53 @@
import collections
import copy
from .Utils import _write_complex_object
class Internal(object):
"""Data contract class for type Internal."""
_defaults = collections.OrderedDict([
('ai.internal.sdkVersion', None),
('ai.internal.agentVersion', None)
])
def __init__(self):
"""Initializes a new instance of the Internal class."""
self._values = {
}
self._initialize()
@property
def sdk_version(self):
"""Gets or sets the sdk_version property."""
if 'ai.internal.sdkVersion' in self._values:
return self._values['ai.internal.sdkVersion']
return self._defaults['ai.internal.sdkVersion']
@sdk_version.setter
def sdk_version(self, value):
if value == self._defaults['ai.internal.sdkVersion'] and 'ai.internal.sdkVersion' in self._values:
del self._values['ai.internal.sdkVersion']
else:
self._values['ai.internal.sdkVersion'] = value
@property
def agent_version(self):
"""Gets or sets the agent_version property."""
if 'ai.internal.agentVersion' in self._values:
return self._values['ai.internal.agentVersion']
return self._defaults['ai.internal.agentVersion']
@agent_version.setter
def agent_version(self, value):
if value == self._defaults['ai.internal.agentVersion'] and 'ai.internal.agentVersion' in self._values:
del self._values['ai.internal.agentVersion']
else:
self._values['ai.internal.agentVersion'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -0,0 +1,38 @@
import collections
import copy
from .Utils import _write_complex_object
class Location(object):
"""Data contract class for type Location."""
_defaults = collections.OrderedDict([
('ai.location.ip', None)
])
def __init__(self):
"""Initializes a new instance of the Location class."""
self._values = {
}
self._initialize()
@property
def ip(self):
"""Gets or sets the ip property."""
if 'ai.location.ip' in self._values:
return self._values['ai.location.ip']
return self._defaults['ai.location.ip']
@ip.setter
def ip(self, value):
if value == self._defaults['ai.location.ip'] and 'ai.location.ip' in self._values:
del self._values['ai.location.ip']
else:
self._values['ai.location.ip'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,125 +0,0 @@
import json
class LocationContext(object):
"""Data contract class for type LocationContext."""
def __init__(self):
"""Initializes a new instance of the LocationContext class."""
self.__instanceVersion = 0
self.__latitude = None
self.__longitude = None
self.__ip = None
self.__continent = None
self.__country = None
self.__province = None
self.__city = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def latitude(self):
"""Gets or sets the 'latitude' property."""
return self.__latitude
@latitude.setter
def latitude(self, value):
self.__latitude = value
self.__instanceVersion += 1
@property
def longitude(self):
"""Gets or sets the 'longitude' property."""
return self.__longitude
@longitude.setter
def longitude(self, value):
self.__longitude = value
self.__instanceVersion += 1
@property
def ip(self):
"""Gets or sets the 'ip' property."""
return self.__ip
@ip.setter
def ip(self, value):
self.__ip = value
self.__instanceVersion += 1
@property
def continent(self):
"""Gets or sets the 'continent' property."""
return self.__continent
@continent.setter
def continent(self, value):
self.__continent = value
self.__instanceVersion += 1
@property
def country(self):
"""Gets or sets the 'country' property."""
return self.__country
@country.setter
def country(self, value):
self.__country = value
self.__instanceVersion += 1
@property
def province(self):
"""Gets or sets the 'province' property."""
return self.__province
@province.setter
def province(self, value):
self.__province = value
self.__instanceVersion += 1
@property
def city(self):
"""Gets or sets the 'city' property."""
return self.__city
@city.setter
def city(self, value):
self.__city = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
if self.__latitude != None:
output += prefix + "\"latitude\":"
output += json.dumps(self.__latitude)
prefix = ","
if self.__longitude != None:
output += prefix + "\"longitude\":"
output += json.dumps(self.__longitude)
prefix = ","
if self.__ip != None:
output += prefix + "\"ip\":"
output += json.dumps(self.__ip)
prefix = ","
if self.__continent != None:
output += prefix + "\"continent\":"
output += json.dumps(self.__continent)
prefix = ","
if self.__country != None:
output += prefix + "\"country\":"
output += json.dumps(self.__country)
prefix = ","
if self.__province != None:
output += prefix + "\"province\":"
output += json.dumps(self.__province)
prefix = ","
if self.__city != None:
output += prefix + "\"city\":"
output += json.dumps(self.__city)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,80 @@
import collections
import copy
from .Utils import _write_complex_object
class MessageData(object):
"""Data contract class for type MessageData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.Message'
DATA_TYPE_NAME = 'MessageData'
_defaults = collections.OrderedDict([
('ver', 2),
('message', None),
('severityLevel', None),
('properties', {})
])
def __init__(self):
"""Initializes a new instance of the MessageData class."""
self._values = {
'ver': 2,
'message': None,
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def message(self):
"""Gets or sets the message property."""
return self._values['message']
@message.setter
def message(self, value):
self._values['message'] = value
@property
def severity_level(self):
"""Gets or sets the severity_level property."""
if 'severityLevel' in self._values:
return self._values['severityLevel']
return self._defaults['severityLevel']
@severity_level.setter
def severity_level(self, value):
if value == self._defaults['severityLevel'] and 'severityLevel' in self._values:
del self._values['severityLevel']
else:
self._values['severityLevel'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,76 +0,0 @@
import json
class MessageTelemetry(object):
"""Data contract class for type MessageTelemetry."""
def __init__(self):
"""Initializes a new instance of the MessageTelemetry class."""
self.__instanceVersion = 0
self.__ver = 1
self.__message = None
self.__properties = {}
self.__measurements = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def message(self):
"""Gets or sets the 'message' property."""
return self.__message
@message.setter
def message(self, value):
self.__message = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
@property
def measurements(self):
"""Gets or sets the 'measurements' property."""
return self.__measurements
@measurements.setter
def measurements(self, value):
self.__measurements = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
output += prefix + "\"message\":"
output += json.dumps(self.__message)
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
if self.__measurements != None:
output += prefix + "\"measurements\":"
output += json.dumps(self.__measurements)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,65 @@
import collections
import copy
from .Utils import _write_complex_object
class MetricData(object):
"""Data contract class for type MetricData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.Metric'
DATA_TYPE_NAME = 'MetricData'
_defaults = collections.OrderedDict([
('ver', 2),
('metrics', []),
('properties', {})
])
def __init__(self):
"""Initializes a new instance of the MetricData class."""
self._values = {
'ver': 2,
'metrics': [],
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def metrics(self):
"""Gets or sets the metrics property."""
return self._values['metrics']
@metrics.setter
def metrics(self, value):
self._values['metrics'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,66 +0,0 @@
import json
class MetricTelemetry(object):
"""Data contract class for type MetricTelemetry."""
def __init__(self):
"""Initializes a new instance of the MetricTelemetry class."""
self.__instanceVersion = 0
self.__ver = 1
self.__metrics = []
self.__properties = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def metrics(self):
"""Gets or sets the 'metrics' property."""
return self.__metrics
@metrics.setter
def metrics(self, value):
self.__metrics = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
arrayPrefix = ""
output += prefix + "\"metrics\":["
for item in self.__metrics:
output += arrayPrefix + item.serialize()
arrayPrefix = ","
output += "]"
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
output += "}"
return output

Просмотреть файл

@ -1,117 +0,0 @@
import json
class MetricTelemetryDataPoint(object):
"""Data contract class for type MetricTelemetryDataPoint."""
def __init__(self):
"""Initializes a new instance of the MetricTelemetryDataPoint class."""
self.__instanceVersion = 0
self.__name = None
self.__value = None
self.__kind = "A"
self.__count = None
self.__min = None
self.__max = None
self.__stdDev = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def name(self):
"""Gets or sets the 'name' property."""
return self.__name
@name.setter
def name(self, value):
self.__name = value
self.__instanceVersion += 1
@property
def value(self):
"""Gets or sets the 'value' property."""
return self.__value
@value.setter
def value(self, value):
self.__value = value
self.__instanceVersion += 1
@property
def kind(self):
"""Gets or sets the 'kind' property."""
return self.__kind
@kind.setter
def kind(self, value):
self.__kind = value
self.__instanceVersion += 1
@property
def count(self):
"""Gets or sets the 'count' property."""
return self.__count
@count.setter
def count(self, value):
self.__count = value
self.__instanceVersion += 1
@property
def min(self):
"""Gets or sets the 'min' property."""
return self.__min
@min.setter
def min(self, value):
self.__min = value
self.__instanceVersion += 1
@property
def max(self):
"""Gets or sets the 'max' property."""
return self.__max
@max.setter
def max(self, value):
self.__max = value
self.__instanceVersion += 1
@property
def stdDev(self):
"""Gets or sets the 'stdDev' property."""
return self.__stdDev
@stdDev.setter
def stdDev(self, value):
self.__stdDev = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"name\":"
output += json.dumps(self.__name)
prefix = ","
output += prefix + "\"value\":"
output += json.dumps(self.__value)
output += prefix + "\"kind\":"
output += json.dumps(self.__kind)
if self.__count != None:
output += prefix + "\"count\":"
output += json.dumps(self.__count)
if self.__min != None:
output += prefix + "\"min\":"
output += json.dumps(self.__min)
if self.__max != None:
output += prefix + "\"max\":"
output += json.dumps(self.__max)
if self.__stdDev != None:
output += prefix + "\"stdDev\":"
output += json.dumps(self.__stdDev)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,83 @@
import collections
import copy
from .Utils import _write_complex_object
class Operation(object):
"""Data contract class for type Operation."""
_defaults = collections.OrderedDict([
('ai.operation.id', None),
('ai.operation.name', None),
('ai.operation.parentId', None),
('ai.operation.rootId', None)
])
def __init__(self):
"""Initializes a new instance of the Operation class."""
self._values = {
}
self._initialize()
@property
def id(self):
"""Gets or sets the id property."""
if 'ai.operation.id' in self._values:
return self._values['ai.operation.id']
return self._defaults['ai.operation.id']
@id.setter
def id(self, value):
if value == self._defaults['ai.operation.id'] and 'ai.operation.id' in self._values:
del self._values['ai.operation.id']
else:
self._values['ai.operation.id'] = value
@property
def name(self):
"""Gets or sets the name property."""
if 'ai.operation.name' in self._values:
return self._values['ai.operation.name']
return self._defaults['ai.operation.name']
@name.setter
def name(self, value):
if value == self._defaults['ai.operation.name'] and 'ai.operation.name' in self._values:
del self._values['ai.operation.name']
else:
self._values['ai.operation.name'] = value
@property
def parent_id(self):
"""Gets or sets the parent_id property."""
if 'ai.operation.parentId' in self._values:
return self._values['ai.operation.parentId']
return self._defaults['ai.operation.parentId']
@parent_id.setter
def parent_id(self, value):
if value == self._defaults['ai.operation.parentId'] and 'ai.operation.parentId' in self._values:
del self._values['ai.operation.parentId']
else:
self._values['ai.operation.parentId'] = value
@property
def root_id(self):
"""Gets or sets the root_id property."""
if 'ai.operation.rootId' in self._values:
return self._values['ai.operation.rootId']
return self._defaults['ai.operation.rootId']
@root_id.setter
def root_id(self, value):
if value == self._defaults['ai.operation.rootId'] and 'ai.operation.rootId' in self._values:
del self._values['ai.operation.rootId']
else:
self._values['ai.operation.rootId'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,34 +0,0 @@
import json
class OperationContext(object):
"""Data contract class for type OperationContext."""
def __init__(self):
"""Initializes a new instance of the OperationContext class."""
self.__instanceVersion = 0
self.__id = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"id\":"
output += json.dumps(self.__id)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,111 @@
import collections
import copy
from .Utils import _write_complex_object
class PageViewData(object):
"""Data contract class for type PageViewData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.PageView'
DATA_TYPE_NAME = 'PageViewData'
_defaults = collections.OrderedDict([
('ver', 2),
('url', None),
('name', None),
('duration', None),
('properties', {}),
('measurements', {})
])
def __init__(self):
"""Initializes a new instance of the PageViewData class."""
self._values = {
'ver': 2,
'name': None,
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def url(self):
"""Gets or sets the url property."""
if 'url' in self._values:
return self._values['url']
return self._defaults['url']
@url.setter
def url(self, value):
if value == self._defaults['url'] and 'url' in self._values:
del self._values['url']
else:
self._values['url'] = value
@property
def name(self):
"""Gets or sets the name property."""
return self._values['name']
@name.setter
def name(self, value):
self._values['name'] = value
@property
def duration(self):
"""Gets or sets the duration property."""
if 'duration' in self._values:
return self._values['duration']
return self._defaults['duration']
@duration.setter
def duration(self, value):
if value == self._defaults['duration'] and 'duration' in self._values:
del self._values['duration']
else:
self._values['duration'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
@property
def measurements(self):
"""Gets or sets the measurements property."""
if 'measurements' in self._values:
return self._values['measurements']
self._values['measurements'] = copy.deepcopy(self._defaults['measurements'])
return self._values['measurements']
@measurements.setter
def measurements(self, value):
if value == self._defaults['measurements'] and 'measurements' in self._values:
del self._values['measurements']
else:
self._values['measurements'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,116 +0,0 @@
import json
class PageViewTelemetry(object):
"""Data contract class for type PageViewTelemetry."""
def __init__(self):
"""Initializes a new instance of the PageViewTelemetry class."""
self.__instanceVersion = 0
self.__ver = 1
self.__url = None
self.__pageViewPerf = None
self.__name = None
self.__duration = None
self.__properties = {}
self.__measurements = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def url(self):
"""Gets or sets the 'url' property."""
return self.__url
@url.setter
def url(self, value):
self.__url = value
self.__instanceVersion += 1
@property
def pageViewPerf(self):
"""Gets or sets the 'pageViewPerf' property."""
return self.__pageViewPerf
@pageViewPerf.setter
def pageViewPerf(self, value):
self.__pageViewPerf = value
self.__instanceVersion += 1
@property
def name(self):
"""Gets or sets the 'name' property."""
return self.__name
@name.setter
def name(self, value):
self.__name = value
self.__instanceVersion += 1
@property
def duration(self):
"""Gets or sets the 'duration' property."""
return self.__duration
@duration.setter
def duration(self, value):
self.__duration = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
@property
def measurements(self):
"""Gets or sets the 'measurements' property."""
return self.__measurements
@measurements.setter
def measurements(self, value):
self.__measurements = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
output += prefix + "\"url\":"
output += json.dumps(self.__url)
if self.__pageViewPerf != None and self.__pageViewPerf.hasChanges():
output += prefix + "\"pageViewPerf\":"
output += self.__pageViewPerf.serialize()
output += prefix + "\"name\":"
output += json.dumps(self.__name)
output += prefix + "\"duration\":"
output += json.dumps(self.__duration)
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
if self.__measurements != None:
output += prefix + "\"measurements\":"
output += json.dumps(self.__measurements)
output += "}"
return output

Просмотреть файл

@ -1,95 +0,0 @@
import json
class PageViewTelemetryPerf(object):
"""Data contract class for type PageViewTelemetryPerf."""
def __init__(self):
"""Initializes a new instance of the PageViewTelemetryPerf class."""
self.__instanceVersion = 0
self.__perfTotal = None
self.__networkConnect = None
self.__sentRequest = None
self.__receivedResponse = None
self.__domProcessing = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def perfTotal(self):
"""Gets or sets the 'perfTotal' property."""
return self.__perfTotal
@perfTotal.setter
def perfTotal(self, value):
self.__perfTotal = value
self.__instanceVersion += 1
@property
def networkConnect(self):
"""Gets or sets the 'networkConnect' property."""
return self.__networkConnect
@networkConnect.setter
def networkConnect(self, value):
self.__networkConnect = value
self.__instanceVersion += 1
@property
def sentRequest(self):
"""Gets or sets the 'sentRequest' property."""
return self.__sentRequest
@sentRequest.setter
def sentRequest(self, value):
self.__sentRequest = value
self.__instanceVersion += 1
@property
def receivedResponse(self):
"""Gets or sets the 'receivedResponse' property."""
return self.__receivedResponse
@receivedResponse.setter
def receivedResponse(self, value):
self.__receivedResponse = value
self.__instanceVersion += 1
@property
def domProcessing(self):
"""Gets or sets the 'domProcessing' property."""
return self.__domProcessing
@domProcessing.setter
def domProcessing(self, value):
self.__domProcessing = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
if self.__perfTotal != None:
output += prefix + "\"perfTotal\":"
output += json.dumps(self.__perfTotal)
prefix = ","
if self.__networkConnect != None:
output += prefix + "\"networkConnect\":"
output += json.dumps(self.__networkConnect)
prefix = ","
if self.__sentRequest != None:
output += prefix + "\"sentRequest\":"
output += json.dumps(self.__sentRequest)
prefix = ","
if self.__receivedResponse != None:
output += prefix + "\"receivedResponse\":"
output += json.dumps(self.__receivedResponse)
prefix = ","
if self.__domProcessing != None:
output += prefix + "\"domProcessing\":"
output += json.dumps(self.__domProcessing)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,213 @@
import collections
import copy
from .Utils import _write_complex_object
from .DataPointType import DataPointType
from .DependencyKind import DependencyKind
from .DependencySourceType import DependencySourceType
class RemoteDependencyData(object):
"""Data contract class for type RemoteDependencyData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.RemoteDependency'
DATA_TYPE_NAME = 'RemoteDependencyData'
_defaults = collections.OrderedDict([
('ver', 2),
('name', None),
('kind', DataPointType.measurement),
('value', None),
('count', None),
('min', None),
('max', None),
('stdDev', None),
('dependencyKind', DependencyKind.undefined),
('success', True),
('async', None),
('dependencySource', DependencySourceType.undefined),
('properties', {})
])
def __init__(self):
"""Initializes a new instance of the RemoteDependencyData class."""
self._values = {
'ver': 2,
'name': None,
'kind': DataPointType.measurement,
'value': None,
'dependencyKind': DependencyKind.undefined,
'success': True,
'dependencySource': DependencySourceType.undefined,
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def name(self):
"""Gets or sets the name property."""
return self._values['name']
@name.setter
def name(self, value):
self._values['name'] = value
@property
def kind(self):
"""Gets or sets the kind property."""
if 'kind' in self._values:
return self._values['kind']
return self._defaults['kind']
@kind.setter
def kind(self, value):
if value == self._defaults['kind'] and 'kind' in self._values:
del self._values['kind']
else:
self._values['kind'] = value
@property
def value(self):
"""Gets or sets the value property."""
return self._values['value']
@value.setter
def value(self, value):
self._values['value'] = value
@property
def count(self):
"""Gets or sets the count property."""
if 'count' in self._values:
return self._values['count']
return self._defaults['count']
@count.setter
def count(self, value):
if value == self._defaults['count'] and 'count' in self._values:
del self._values['count']
else:
self._values['count'] = value
@property
def min(self):
"""Gets or sets the min property."""
if 'min' in self._values:
return self._values['min']
return self._defaults['min']
@min.setter
def min(self, value):
if value == self._defaults['min'] and 'min' in self._values:
del self._values['min']
else:
self._values['min'] = value
@property
def max(self):
"""Gets or sets the max property."""
if 'max' in self._values:
return self._values['max']
return self._defaults['max']
@max.setter
def max(self, value):
if value == self._defaults['max'] and 'max' in self._values:
del self._values['max']
else:
self._values['max'] = value
@property
def std_dev(self):
"""Gets or sets the std_dev property."""
if 'stdDev' in self._values:
return self._values['stdDev']
return self._defaults['stdDev']
@std_dev.setter
def std_dev(self, value):
if value == self._defaults['stdDev'] and 'stdDev' in self._values:
del self._values['stdDev']
else:
self._values['stdDev'] = value
@property
def dependency_kind(self):
"""Gets or sets the dependency_kind property."""
return self._values['dependencyKind']
@dependency_kind.setter
def dependency_kind(self, value):
self._values['dependencyKind'] = value
@property
def success(self):
"""Gets or sets the success property."""
if 'success' in self._values:
return self._values['success']
return self._defaults['success']
@success.setter
def success(self, value):
if value == self._defaults['success'] and 'success' in self._values:
del self._values['success']
else:
self._values['success'] = value
@property
def async(self):
"""Gets or sets the async property."""
if 'async' in self._values:
return self._values['async']
return self._defaults['async']
@async.setter
def async(self, value):
if value == self._defaults['async'] and 'async' in self._values:
del self._values['async']
else:
self._values['async'] = value
@property
def dependency_source(self):
"""Gets or sets the dependency_source property."""
if 'dependencySource' in self._values:
return self._values['dependencySource']
return self._defaults['dependencySource']
@dependency_source.setter
def dependency_source(self, value):
if value == self._defaults['dependencySource'] and 'dependencySource' in self._values:
del self._values['dependencySource']
else:
self._values['dependencySource'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,171 +0,0 @@
import json
class RemoteDependencyTelemetry(object):
"""Data contract class for type RemoteDependencyTelemetry."""
def __init__(self):
"""Initializes a new instance of the RemoteDependencyTelemetry class."""
self.__instanceVersion = 0
self.__name = None
self.__dependencyKind = 0
self.__value = None
self.__resource = None
self.__kind = None
self.__count = None
self.__min = None
self.__max = None
self.__stdDev = None
self.__properties = {}
self.__measurements = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def name(self):
"""Gets or sets the 'name' property."""
return self.__name
@name.setter
def name(self, value):
self.__name = value
self.__instanceVersion += 1
@property
def dependencyKind(self):
"""Gets or sets the 'dependencyKind' property."""
return self.__dependencyKind
@dependencyKind.setter
def dependencyKind(self, value):
self.__dependencyKind = value
self.__instanceVersion += 1
@property
def value(self):
"""Gets or sets the 'value' property."""
return self.__value
@value.setter
def value(self, value):
self.__value = value
self.__instanceVersion += 1
@property
def resource(self):
"""Gets or sets the 'resource' property."""
return self.__resource
@resource.setter
def resource(self, value):
self.__resource = value
self.__instanceVersion += 1
@property
def kind(self):
"""Gets or sets the 'kind' property."""
return self.__kind
@kind.setter
def kind(self, value):
self.__kind = value
self.__instanceVersion += 1
@property
def count(self):
"""Gets or sets the 'count' property."""
return self.__count
@count.setter
def count(self, value):
self.__count = value
self.__instanceVersion += 1
@property
def min(self):
"""Gets or sets the 'min' property."""
return self.__min
@min.setter
def min(self, value):
self.__min = value
self.__instanceVersion += 1
@property
def max(self):
"""Gets or sets the 'max' property."""
return self.__max
@max.setter
def max(self, value):
self.__max = value
self.__instanceVersion += 1
@property
def stdDev(self):
"""Gets or sets the 'stdDev' property."""
return self.__stdDev
@stdDev.setter
def stdDev(self, value):
self.__stdDev = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
@property
def measurements(self):
"""Gets or sets the 'measurements' property."""
return self.__measurements
@measurements.setter
def measurements(self, value):
self.__measurements = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"name\":"
output += json.dumps(self.__name)
prefix = ","
output += prefix + "\"dependencyKind\":"
output += json.dumps(self.__dependencyKind)
output += prefix + "\"value\":"
output += json.dumps(self.__value)
output += prefix + "\"resource\":"
output += json.dumps(self.__resource)
output += prefix + "\"kind\":"
output += json.dumps(self.__kind)
if self.__count != None:
output += prefix + "\"count\":"
output += json.dumps(self.__count)
if self.__min != None:
output += prefix + "\"min\":"
output += json.dumps(self.__min)
if self.__max != None:
output += prefix + "\"max\":"
output += json.dumps(self.__max)
if self.__stdDev != None:
output += prefix + "\"stdDev\":"
output += json.dumps(self.__stdDev)
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
if self.__measurements != None:
output += prefix + "\"measurements\":"
output += json.dumps(self.__measurements)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,170 @@
import collections
import copy
from .Utils import _write_complex_object
class RequestData(object):
"""Data contract class for type RequestData."""
ENVELOPE_TYPE_NAME = 'Microsoft.ApplicationInsights.Request'
DATA_TYPE_NAME = 'RequestData'
_defaults = collections.OrderedDict([
('ver', 2),
('id', None),
('name', None),
('startTime', None),
('duration', None),
('responseCode', None),
('success', None),
('httpMethod', None),
('url', None),
('properties', {}),
('measurements', {})
])
def __init__(self):
"""Initializes a new instance of the RequestData class."""
self._values = {
'ver': 2,
'id': None,
'startTime': None,
'duration': None,
'responseCode': None,
'success': None,
}
self._initialize()
@property
def ver(self):
"""Gets or sets the ver property."""
return self._values['ver']
@ver.setter
def ver(self, value):
self._values['ver'] = value
@property
def id(self):
"""Gets or sets the id property."""
return self._values['id']
@id.setter
def id(self, value):
self._values['id'] = value
@property
def name(self):
"""Gets or sets the name property."""
if 'name' in self._values:
return self._values['name']
return self._defaults['name']
@name.setter
def name(self, value):
if value == self._defaults['name'] and 'name' in self._values:
del self._values['name']
else:
self._values['name'] = value
@property
def start_time(self):
"""Gets or sets the start_time property."""
return self._values['startTime']
@start_time.setter
def start_time(self, value):
self._values['startTime'] = value
@property
def duration(self):
"""Gets or sets the duration property."""
return self._values['duration']
@duration.setter
def duration(self, value):
self._values['duration'] = value
@property
def response_code(self):
"""Gets or sets the response_code property."""
return self._values['responseCode']
@response_code.setter
def response_code(self, value):
self._values['responseCode'] = value
@property
def success(self):
"""Gets or sets the success property."""
return self._values['success']
@success.setter
def success(self, value):
self._values['success'] = value
@property
def http_method(self):
"""Gets or sets the http_method property."""
if 'httpMethod' in self._values:
return self._values['httpMethod']
return self._defaults['httpMethod']
@http_method.setter
def http_method(self, value):
if value == self._defaults['httpMethod'] and 'httpMethod' in self._values:
del self._values['httpMethod']
else:
self._values['httpMethod'] = value
@property
def url(self):
"""Gets or sets the url property."""
if 'url' in self._values:
return self._values['url']
return self._defaults['url']
@url.setter
def url(self, value):
if value == self._defaults['url'] and 'url' in self._values:
del self._values['url']
else:
self._values['url'] = value
@property
def properties(self):
"""Gets or sets the properties property."""
if 'properties' in self._values:
return self._values['properties']
self._values['properties'] = copy.deepcopy(self._defaults['properties'])
return self._values['properties']
@properties.setter
def properties(self, value):
if value == self._defaults['properties'] and 'properties' in self._values:
del self._values['properties']
else:
self._values['properties'] = value
@property
def measurements(self):
"""Gets or sets the measurements property."""
if 'measurements' in self._values:
return self._values['measurements']
self._values['measurements'] = copy.deepcopy(self._defaults['measurements'])
return self._values['measurements']
@measurements.setter
def measurements(self, value):
if value == self._defaults['measurements'] and 'measurements' in self._values:
del self._values['measurements']
else:
self._values['measurements'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,146 +0,0 @@
import json
class RequestTelemetry(object):
"""Data contract class for type RequestTelemetry."""
def __init__(self):
"""Initializes a new instance of the RequestTelemetry class."""
self.__instanceVersion = 0
self.__ver = 1
self.__name = ""
self.__id = None
self.__startTime = None
self.__duration = None
self.__responseCode = None
self.__success = None
self.__properties = {}
self.__measurements = {}
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def name(self):
"""Gets or sets the 'name' property."""
return self.__name
@name.setter
def name(self, value):
self.__name = value
self.__instanceVersion += 1
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
@property
def startTime(self):
"""Gets or sets the 'startTime' property."""
return self.__startTime
@startTime.setter
def startTime(self, value):
self.__startTime = value
self.__instanceVersion += 1
@property
def duration(self):
"""Gets or sets the 'duration' property."""
return self.__duration
@duration.setter
def duration(self, value):
self.__duration = value
self.__instanceVersion += 1
@property
def responseCode(self):
"""Gets or sets the 'responseCode' property."""
return self.__responseCode
@responseCode.setter
def responseCode(self, value):
self.__responseCode = value
self.__instanceVersion += 1
@property
def success(self):
"""Gets or sets the 'success' property."""
return self.__success
@success.setter
def success(self, value):
self.__success = value
self.__instanceVersion += 1
@property
def properties(self):
"""Gets or sets the 'properties' property."""
return self.__properties
@properties.setter
def properties(self, value):
self.__properties = value
self.__instanceVersion += 1
@property
def measurements(self):
"""Gets or sets the 'measurements' property."""
return self.__measurements
@measurements.setter
def measurements(self, value):
self.__measurements = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
output += prefix + "\"name\":"
output += json.dumps(self.__name)
if self.__id != None:
output += prefix + "\"id\":"
output += json.dumps(self.__id)
if self.__startTime != None:
output += prefix + "\"startTime\":"
output += json.dumps(self.__startTime)
if self.__duration != None:
output += prefix + "\"duration\":"
output += json.dumps(self.__duration)
if self.__responseCode != None:
output += prefix + "\"responseCode\":"
output += json.dumps(self.__responseCode)
if self.__success != None:
output += prefix + "\"success\":"
output += json.dumps(self.__success)
if self.__properties != None:
output += prefix + "\"properties\":"
output += json.dumps(self.__properties)
if self.__measurements != None:
output += prefix + "\"measurements\":"
output += json.dumps(self.__measurements)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,68 @@
import collections
import copy
from .Utils import _write_complex_object
class Session(object):
"""Data contract class for type Session."""
_defaults = collections.OrderedDict([
('ai.session.id', None),
('ai.session.isFirst', None),
('ai.session.isNew', None)
])
def __init__(self):
"""Initializes a new instance of the Session class."""
self._values = {
}
self._initialize()
@property
def id(self):
"""Gets or sets the id property."""
if 'ai.session.id' in self._values:
return self._values['ai.session.id']
return self._defaults['ai.session.id']
@id.setter
def id(self, value):
if value == self._defaults['ai.session.id'] and 'ai.session.id' in self._values:
del self._values['ai.session.id']
else:
self._values['ai.session.id'] = value
@property
def is_first(self):
"""Gets or sets the is_first property."""
if 'ai.session.isFirst' in self._values:
return self._values['ai.session.isFirst']
return self._defaults['ai.session.isFirst']
@is_first.setter
def is_first(self, value):
if value == self._defaults['ai.session.isFirst'] and 'ai.session.isFirst' in self._values:
del self._values['ai.session.isFirst']
else:
self._values['ai.session.isFirst'] = value
@property
def is_new(self):
"""Gets or sets the is_new property."""
if 'ai.session.isNew' in self._values:
return self._values['ai.session.isNew']
return self._defaults['ai.session.isNew']
@is_new.setter
def is_new(self, value):
if value == self._defaults['ai.session.isNew'] and 'ai.session.isNew' in self._values:
del self._values['ai.session.isNew']
else:
self._values['ai.session.isNew'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,49 +0,0 @@
import json
class SessionContext(object):
"""Data contract class for type SessionContext."""
def __init__(self):
"""Initializes a new instance of the SessionContext class."""
self.__instanceVersion = 0
self.__id = None
self.__firstSession = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
@property
def firstSession(self):
"""Gets or sets the 'firstSession' property."""
return self.__firstSession
@firstSession.setter
def firstSession(self, value):
self.__firstSession = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"id\":"
output += json.dumps(self.__id)
prefix = ","
if self.__firstSession != None:
output += prefix + "\"firstSession\":"
output += json.dumps(self.__firstSession)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,18 @@
class SeverityLevel(object):
"""Data contract class for type SeverityLevel."""
# Enumeration value verbose
verbose = 0
# Enumeration value information
information = 1
# Enumeration value warning
warning = 2
# Enumeration value error
error = 3
# Enumeration value critical
critical = 4

Просмотреть файл

@ -0,0 +1,90 @@
import collections
import copy
from .Utils import _write_complex_object
class StackFrame(object):
"""Data contract class for type StackFrame."""
_defaults = collections.OrderedDict([
('level', None),
('method', None),
('assembly', None),
('fileName', None),
('line', None)
])
def __init__(self):
"""Initializes a new instance of the StackFrame class."""
self._values = {
'level': None,
'method': None,
}
self._initialize()
@property
def level(self):
"""Gets or sets the level property."""
return self._values['level']
@level.setter
def level(self, value):
self._values['level'] = value
@property
def method(self):
"""Gets or sets the method property."""
return self._values['method']
@method.setter
def method(self, value):
self._values['method'] = value
@property
def assembly(self):
"""Gets or sets the assembly property."""
if 'assembly' in self._values:
return self._values['assembly']
return self._defaults['assembly']
@assembly.setter
def assembly(self, value):
if value == self._defaults['assembly'] and 'assembly' in self._values:
del self._values['assembly']
else:
self._values['assembly'] = value
@property
def file_name(self):
"""Gets or sets the file_name property."""
if 'fileName' in self._values:
return self._values['fileName']
return self._defaults['fileName']
@file_name.setter
def file_name(self, value):
if value == self._defaults['fileName'] and 'fileName' in self._values:
del self._values['fileName']
else:
self._values['fileName'] = value
@property
def line(self):
"""Gets or sets the line property."""
if 'line' in self._values:
return self._values['line']
return self._defaults['line']
@line.setter
def line(self, value):
if value == self._defaults['line'] and 'line' in self._values:
del self._values['line']
else:
self._values['line'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,176 +0,0 @@
import json
class TelemetryEnvelope(object):
"""Data contract class for type TelemetryEnvelope."""
def __init__(self):
"""Initializes a new instance of the TelemetryEnvelope class."""
self.__instanceVersion = 0
self.__ver = 1
self.__name = None
self.__time = None
self.__iKey = None
self.__application = None
self.__device = None
self.__user = None
self.__session = None
self.__location = None
self.__operation = None
self.__data = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def ver(self):
"""Gets or sets the 'ver' property."""
return self.__ver
@ver.setter
def ver(self, value):
self.__ver = value
self.__instanceVersion += 1
@property
def name(self):
"""Gets or sets the 'name' property."""
return self.__name
@name.setter
def name(self, value):
self.__name = value
self.__instanceVersion += 1
@property
def time(self):
"""Gets or sets the 'time' property."""
return self.__time
@time.setter
def time(self, value):
self.__time = value
self.__instanceVersion += 1
@property
def iKey(self):
"""Gets or sets the 'iKey' property."""
return self.__iKey
@iKey.setter
def iKey(self, value):
self.__iKey = value
self.__instanceVersion += 1
@property
def application(self):
"""Gets or sets the 'application' property."""
return self.__application
@application.setter
def application(self, value):
self.__application = value
self.__instanceVersion += 1
@property
def device(self):
"""Gets or sets the 'device' property."""
return self.__device
@device.setter
def device(self, value):
self.__device = value
self.__instanceVersion += 1
@property
def user(self):
"""Gets or sets the 'user' property."""
return self.__user
@user.setter
def user(self, value):
self.__user = value
self.__instanceVersion += 1
@property
def session(self):
"""Gets or sets the 'session' property."""
return self.__session
@session.setter
def session(self, value):
self.__session = value
self.__instanceVersion += 1
@property
def location(self):
"""Gets or sets the 'location' property."""
return self.__location
@location.setter
def location(self, value):
self.__location = value
self.__instanceVersion += 1
@property
def operation(self):
"""Gets or sets the 'operation' property."""
return self.__operation
@operation.setter
def operation(self, value):
self.__operation = value
self.__instanceVersion += 1
@property
def data(self):
"""Gets or sets the 'data' property."""
return self.__data
@data.setter
def data(self, value):
self.__data = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
if self.__ver != None:
output += prefix + "\"ver\":"
output += json.dumps(self.__ver)
prefix = ","
if self.__name != None:
output += prefix + "\"name\":"
output += json.dumps(self.__name)
prefix = ","
output += prefix + "\"time\":"
output += json.dumps(self.__time)
prefix = ","
output += prefix + "\"iKey\":"
output += json.dumps(self.__iKey)
if self.__application != None and self.__application.hasChanges():
output += prefix + "\"application\":"
output += self.__application.serialize()
if self.__device != None and self.__device.hasChanges():
output += prefix + "\"device\":"
output += self.__device.serialize()
if self.__user != None and self.__user.hasChanges():
output += prefix + "\"user\":"
output += self.__user.serialize()
if self.__session != None and self.__session.hasChanges():
output += prefix + "\"session\":"
output += self.__session.serialize()
if self.__location != None and self.__location.hasChanges():
output += prefix + "\"location\":"
output += self.__location.serialize()
if self.__operation != None and self.__operation.hasChanges():
output += prefix + "\"operation\":"
output += self.__operation.serialize()
if self.__data != None and self.__data.hasChanges():
output += prefix + "\"data\":"
output += self.__data.serialize()
output += "}"
return output

Просмотреть файл

@ -1,50 +0,0 @@
import json
class TelemetryEnvelopeData(object):
"""Data contract class for type TelemetryEnvelopeData."""
def __init__(self):
"""Initializes a new instance of the TelemetryEnvelopeData class."""
self.__instanceVersion = 0
self.__type = None
self.__item = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def type(self):
"""Gets or sets the 'type' property."""
return self.__type
@type.setter
def type(self, value):
self.__type = value
self.__instanceVersion += 1
@property
def item(self):
"""Gets or sets the 'item' property."""
return self.__item
@item.setter
def item(self, value):
self.__item = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
if self.__type != None:
output += prefix + "\"type\":"
output += json.dumps(self.__type)
prefix = ","
if self.__item != None and self.__item.hasChanges():
output += prefix + "\"item\":"
output += self.__item.serialize()
output += "}"
return output

Просмотреть файл

@ -0,0 +1,83 @@
import collections
import copy
from .Utils import _write_complex_object
class User(object):
"""Data contract class for type User."""
_defaults = collections.OrderedDict([
('ai.user.accountAcquisitionDate', None),
('ai.user.accountId', None),
('ai.user.userAgent', None),
('ai.user.id', None)
])
def __init__(self):
"""Initializes a new instance of the User class."""
self._values = {
}
self._initialize()
@property
def account_acquisition_date(self):
"""Gets or sets the account_acquisition_date property."""
if 'ai.user.accountAcquisitionDate' in self._values:
return self._values['ai.user.accountAcquisitionDate']
return self._defaults['ai.user.accountAcquisitionDate']
@account_acquisition_date.setter
def account_acquisition_date(self, value):
if value == self._defaults['ai.user.accountAcquisitionDate'] and 'ai.user.accountAcquisitionDate' in self._values:
del self._values['ai.user.accountAcquisitionDate']
else:
self._values['ai.user.accountAcquisitionDate'] = value
@property
def account_id(self):
"""Gets or sets the account_id property."""
if 'ai.user.accountId' in self._values:
return self._values['ai.user.accountId']
return self._defaults['ai.user.accountId']
@account_id.setter
def account_id(self, value):
if value == self._defaults['ai.user.accountId'] and 'ai.user.accountId' in self._values:
del self._values['ai.user.accountId']
else:
self._values['ai.user.accountId'] = value
@property
def user_agent(self):
"""Gets or sets the user_agent property."""
if 'ai.user.userAgent' in self._values:
return self._values['ai.user.userAgent']
return self._defaults['ai.user.userAgent']
@user_agent.setter
def user_agent(self, value):
if value == self._defaults['ai.user.userAgent'] and 'ai.user.userAgent' in self._values:
del self._values['ai.user.userAgent']
else:
self._values['ai.user.userAgent'] = value
@property
def id(self):
"""Gets or sets the id property."""
if 'ai.user.id' in self._values:
return self._values['ai.user.id']
return self._defaults['ai.user.id']
@id.setter
def id(self, value):
if value == self._defaults['ai.user.id'] and 'ai.user.id' in self._values:
del self._values['ai.user.id']
else:
self._values['ai.user.id'] = value
def _initialize(self):
"""Initializes the current instance of the object (can be overridden)."""
pass
def write(self):
"""Writes the contents of this object and returns the content as a dict object."""
return _write_complex_object(self._defaults, self._values)

Просмотреть файл

@ -1,49 +0,0 @@
import json
class UserContext(object):
"""Data contract class for type UserContext."""
def __init__(self):
"""Initializes a new instance of the UserContext class."""
self.__instanceVersion = 0
self.__id = None
self.__accountId = None
if hasattr(self.__class__, 'initialize') and callable(getattr(self.__class__, 'initialize')):
self.initialize()
@property
def id(self):
"""Gets or sets the 'id' property."""
return self.__id
@id.setter
def id(self, value):
self.__id = value
self.__instanceVersion += 1
@property
def accountId(self):
"""Gets or sets the 'accountId' property."""
return self.__accountId
@accountId.setter
def accountId(self, value):
self.__accountId = value
self.__instanceVersion += 1
def hasChanges(self):
"""Checks if the current instance has changes since its initalization."""
return self.__instanceVersion != 0
def serialize(self):
"""Serializes the contents of this object and returns the content as a JSON encoded string."""
output = "{"
prefix = ""
output += prefix + "\"id\":"
output += json.dumps(self.__id)
prefix = ","
if self.__accountId != None:
output += prefix + "\"accountId\":"
output += json.dumps(self.__accountId)
output += "}"
return output

Просмотреть файл

@ -0,0 +1,36 @@
import collections
def _write_complex_object(defaults, values):
output = collections.OrderedDict()
for key in [ field for field in defaults.keys() if field in values ]:
value = values[key]
if value == None:
value = defaults[key]
if isinstance(value, list):
value_copy = []
for item in value:
if hasattr(item, 'write') and callable(getattr(item, 'write')):
value_copy.append(item.write())
else:
value_copy.append(item)
if len(value_copy) > 0:
output[key] = value_copy
elif isinstance(value, dict):
value_copy = collections.OrderedDict()
keys = sorted(value.keys())
for item_key in keys:
item_value = value[item_key]
if hasattr(item_value, 'write') and callable(getattr(item_value, 'write')):
value_copy[item_key] = item_value.write()
else:
value_copy[item_key] = item_value
if len(value_copy) > 0:
output[key] = value_copy
elif hasattr(value, 'write') and callable(getattr(value, 'write')):
value_copy = value.write()
if len(value_copy) > 0:
output[key] = value_copy
else:
value_copy = value
output[key] = value_copy
return output

Просмотреть файл

@ -1,19 +1,23 @@
from .ApplicationContext import ApplicationContext
from .DeviceContext import DeviceContext
from .LocationContext import LocationContext
from .OperationContext import OperationContext
from .SessionContext import SessionContext
from .UserContext import UserContext
from .TelemetryEnvelopeData import TelemetryEnvelopeData
from .TelemetryEnvelope import TelemetryEnvelope
from .EventTelemetry import EventTelemetry
from .ExceptionTelemetryStackFrame import ExceptionTelemetryStackFrame
from .ExceptionTelemetryDetails import ExceptionTelemetryDetails
from .ExceptionTelemetry import ExceptionTelemetry
from .MetricTelemetryDataPoint import MetricTelemetryDataPoint
from .MetricTelemetry import MetricTelemetry
from .PageViewTelemetryPerf import PageViewTelemetryPerf
from .PageViewTelemetry import PageViewTelemetry
from .RemoteDependencyTelemetry import RemoteDependencyTelemetry
from .RequestTelemetry import RequestTelemetry
from .MessageTelemetry import MessageTelemetry
from .Data import Data
from .Envelope import Envelope
from .DependencyKind import DependencyKind
from .SeverityLevel import SeverityLevel
from .DataPoint import DataPoint
from .MetricData import MetricData
from .RemoteDependencyData import RemoteDependencyData
from .RequestData import RequestData
from .StackFrame import StackFrame
from .ExceptionDetails import ExceptionDetails
from .ExceptionData import ExceptionData
from .MessageData import MessageData
from .EventData import EventData
from .PageViewData import PageViewData
from .DataPointType import DataPointType
from .DependencySourceType import DependencySourceType
from .Application import Application
from .Device import Device
from .Location import Location
from .Operation import Operation
from .Session import Session
from .User import User
from .Internal import Internal

Просмотреть файл

@ -14,7 +14,7 @@ setup(
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version='0.1.0',
version='0.2.0',
description='This project extends the Application Insights API surface to support Python.',
long_description=long_description,

Просмотреть файл

@ -5,88 +5,104 @@ import json
from test import test_support
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights import TelemetryClient, channel
class TestTelemetryClient(unittest.TestCase):
def test_contextReturnsNonNullValue(self):
def test_context_property_works_as_expected(self):
client = TelemetryClient()
self.assertIsNotNone(client.context)
def test_channelWorksAsExpected(self):
def test_channel_property_works_as_expected(self):
expected = channel.TelemetryChannel()
client = TelemetryClient(expected)
self.assertEqual(expected, client.channel)
def test_trackEventWorksAsExpected(self):
def test_track_event_works_as_expected(self):
sender = MockTelemetrySender()
client = TelemetryClient(channel.TelemetryChannel(context=None, sender=sender))
client.context.instrumentationKey = "99999999-9999-9999-9999-999999999999"
client.context.instrumentation_key = '99999999-9999-9999-9999-999999999999'
client.context.device = None
client.context.session = None
client.trackEvent("test", {}, { "x": 42 })
expected = '{"ver":1,"name":"Microsoft.ApplicationInsights.Event","time":"TIME_PLACEHOLDER","iKey":"99999999-9999-9999-9999-999999999999","data":{"type":"Microsoft.ApplicationInsights.EventData","item":{"ver":1,"name":"test","properties":{"SDKVersion": "Python;0.1"},"measurements":{"x": 42}}}}'
sender.data.time = "TIME_PLACEHOLDER"
actual = sender.data.serialize()
client.track_event('test', { 'foo': 'bar' }, { 'x': 42 })
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Event", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "EventData", "baseData": {"ver": 2, "name": "test", "properties": {"foo": "bar"}, "measurements": {"x": 42}}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
actual = json.dumps(sender.data.write())
self.maxDiff = None
self.assertEqual(expected, actual)
def test_trackMetricWorksAsExpected(self):
def test_track_metric_works_as_expected(self):
sender = MockTelemetrySender()
client = TelemetryClient(channel.TelemetryChannel(context=None, sender=sender))
client.context.instrumentationKey = "99999999-9999-9999-9999-999999999999"
client.context.instrumentation_key = '99999999-9999-9999-9999-999999999999'
client.context.device = None
client.context.session = None
client.trackMetric("metric", 42, "A", 13, 1, 123, {})
expected = '{"ver":1,"name":"Microsoft.ApplicationInsights.Metric","time":"TIME_PLACEHOLDER","iKey":"99999999-9999-9999-9999-999999999999","data":{"type":"Microsoft.ApplicationInsights.MetricData","item":{"ver":1,"metrics":[{"name":"metric","value":42,"kind":"A","count":13,"min":1,"max":123}],"properties":{"SDKVersion": "Python;0.1"}}}}'
sender.data.time = "TIME_PLACEHOLDER"
actual = sender.data.serialize()
client.track_metric('metric', 42, channel.contracts.DataPointType.aggregation, 13, 1, 123, 111, {'foo': 'bar'})
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Metric", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "MetricData", "baseData": {"ver": 2, "metrics": [{"name": "metric", "kind": 1, "value": 42, "count": 13, "min": 1, "max": 123, "stdDev": 111}], "properties": {"foo": "bar"}}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
actual = json.dumps(sender.data.write())
self.maxDiff = None
self.assertEqual(expected, actual)
def test_trackTraceWorksAsExpected(self):
def test_track_trace_works_as_expected(self):
sender = MockTelemetrySender()
client = TelemetryClient(channel.TelemetryChannel(context=None, sender=sender))
client.context.instrumentationKey = "99999999-9999-9999-9999-999999999999"
client.context.instrumentation_key = '99999999-9999-9999-9999-999999999999'
client.context.device = None
client.context.session = None
client.trackTrace("test", {}, { "x": 42 })
expected = '{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","iKey":"99999999-9999-9999-9999-999999999999","data":{"type":"Microsoft.ApplicationInsights.MessageData","item":{"ver":1,"message":"test","properties":{"SDKVersion": "Python;0.1"},"measurements":{"x": 42}}}}'
sender.data.time = "TIME_PLACEHOLDER"
actual = sender.data.serialize()
client.track_trace('test', { 'foo': 'bar' })
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Message", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "MessageData", "baseData": {"ver": 2, "message": "test", "properties": {"foo": "bar"}}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
actual = json.dumps(sender.data.write())
self.maxDiff = None
self.assertEqual(expected, actual)
def test_trackPageViewWorksAsExpected(self):
def test_track_pageview_works_as_expected(self):
sender = MockTelemetrySender()
client = TelemetryClient(channel.TelemetryChannel(context=None, sender=sender))
client.context.instrumentationKey = "99999999-9999-9999-9999-999999999999"
client.context.instrumentation_key = '99999999-9999-9999-9999-999999999999'
client.context.device = None
client.context.session = None
client.trackPageView("test", "http://tempuri.org", 13, {}, { "x": 42 })
expected = '{"ver":1,"name":"Microsoft.ApplicationInsights.Pageview","time":"TIME_PLACEHOLDER","iKey":"99999999-9999-9999-9999-999999999999","data":{"type":"Microsoft.ApplicationInsights.PageviewData","item":{"ver":1,"url":"http://tempuri.org","name":"test","duration":13,"properties":{"SDKVersion": "Python;0.1"},"measurements":{"x": 42}}}}'
sender.data.time = "TIME_PLACEHOLDER"
actual = sender.data.serialize()
client.track_pageview('test', 'http://tempuri.org', 13, { 'foo': 'bar' }, { 'x': 42 })
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.PageView", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "PageViewData", "baseData": {"ver": 2, "url": "http://tempuri.org", "name": "test", "duration": 13, "properties": {"foo": "bar"}, "measurements": {"x": 42}}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
actual = json.dumps(sender.data.write())
self.maxDiff = None
self.assertEqual(expected, actual)
def test_trackExceptionWorksAsExpected(self):
def test_track_exception_works_as_expected(self):
sender = MockTelemetrySender()
client = TelemetryClient(channel.TelemetryChannel(context=None, sender=sender))
client.context.instrumentationKey = "99999999-9999-9999-9999-999999999999"
client.context.instrumentation_key = '99999999-9999-9999-9999-999999999999'
client.context.device = None
client.context.session = None
try:
raise Exception("blah")
except Exception as e:
client.trackException(e, {}, { "x": 42 })
expected27 = '{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","iKey":"99999999-9999-9999-9999-999999999999","data":{"type":"Microsoft.ApplicationInsights.ExceptionData","item":{"ver":1,"handledAt":"UserCode","exceptions":[{"id":1,"outerId":0,"typeName":"Exception","message":"blah","hasFullStack":false,"parsedStack":[]}],"properties":{"SDKVersion": "Python;0.1"},"measurements":{"x": 42}}}}'
expected34 = '{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","iKey":"99999999-9999-9999-9999-999999999999","data":{"type":"Microsoft.ApplicationInsights.ExceptionData","item":{"ver":1,"handledAt":"UserCode","exceptions":[{"id":1,"outerId":0,"typeName":"Exception","message":"blah","hasFullStack":true,"parsedStack":[{"level":0,"method":"test_trackExceptionWorksAsExpected(self)","assembly":"<module>","fileName":' + json.dumps(os.path.abspath(inspect.getfile(inspect.currentframe()))) + ',"line":"LINE_PLACEHOLDER"}]}],"properties":{"SDKVersion": "Python;0.1"},"measurements":{"x": 42}}}}'
expected = expected27
sender.data.time = "TIME_PLACEHOLDER"
if len(sender.data.data.item.exceptions[0].parsedStack) > 0:
expected = expected34
sender.data.data.item.exceptions[0].parsedStack[0].line = "LINE_PLACEHOLDER"
actual = sender.data.serialize()
client.track_exception(*sys.exc_info(), properties={}, measurements={ 'x': 42 })
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Exception", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "ExceptionData", "baseData": {"ver": 2, "handledAt": "UserCode", "exceptions": [{"id": 1, "outerId": 0, "typeName": "Exception", "message": "blah", "parsedStack": [{"level": 0, "method": "test_track_exception_works_as_expected", "assembly": "Unknown", "fileName": "TestTelemetryClient.py", "line": 0}]}], "measurements": {"x": 42}}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
for item in sender.data.data.base_data.exceptions:
for frame in item.parsed_stack:
frame.file_name = os.path.basename(frame.file_name)
frame.line = 0
actual = json.dumps(sender.data.write())
self.assertEqual(expected, actual)
try:
raise Exception("blah")
except Exception as e:
client.track_exception()
expected = '{"ver": 1, "name": "Microsoft.ApplicationInsights.Exception", "time": "TIME_PLACEHOLDER", "sampleRate": 100.0, "iKey": "99999999-9999-9999-9999-999999999999", "tags": {"ai.internal.sdkVersion": "SDK_VERSION_PLACEHOLDER"}, "data": {"baseType": "ExceptionData", "baseData": {"ver": 2, "handledAt": "UserCode", "exceptions": [{"id": 1, "outerId": 0, "typeName": "Exception", "message": "blah", "parsedStack": [{"level": 0, "method": "test_track_exception_works_as_expected", "assembly": "Unknown", "fileName": "TestTelemetryClient.py", "line": 0}]}]}}}'
sender.data.time = 'TIME_PLACEHOLDER'
sender.data.tags['ai.internal.sdkVersion'] = 'SDK_VERSION_PLACEHOLDER'
for item in sender.data.data.base_data.exceptions:
for frame in item.parsed_stack:
frame.file_name = os.path.basename(frame.file_name)
frame.line = 0
actual = json.dumps(sender.data.write())
self.assertEqual(expected, actual)

Просмотреть файл

@ -2,82 +2,81 @@ import unittest
from test import test_support
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights import channel
class TestTelemetryChannel(unittest.TestCase):
def test_constructTelemetryChannel(self):
def test_construct(self):
actual = channel.TelemetryChannel()
self.assertIsNotNone(actual)
def test_constructTelemetryChannelWithContextAndSender(self):
mockSender = MockTelemetrySender()
contextGlobal = channel.TelemetryContext()
actual = channel.TelemetryChannel(contextGlobal, mockSender)
actual.write(channel.contracts.MessageTelemetry())
self.assertIsNotNone(mockSender.data)
self.assertEqual(contextGlobal.device, mockSender.data.device)
def test_construct_with_context_and_sender(self):
mock_sender = MockTelemetrySender()
context_global = channel.TelemetryContext()
context_global.device.id = "global"
actual = channel.TelemetryChannel(context_global, mock_sender)
actual.write(channel.contracts.MessageData())
self.assertIsNotNone(mock_sender.data)
self.assertEqual("global", mock_sender.data.tags["ai.device.id"])
def test_writeWithNoGlobalOrLocalContextRaisesException(self):
mockSender = MockTelemetrySender()
actual = channel.TelemetryChannel(None, mockSender)
self.assertRaises(Exception, actual.write, channel.contracts.MessageTelemetry(), None)
def test_write_with_no_global_or_local_context_raises_exception(self):
mock_sender = MockTelemetrySender()
actual = channel.TelemetryChannel(None, mock_sender)
self.assertRaises(Exception, actual.write, channel.contracts.MessageData(), None)
def test_writeWithNoDataRaisesException(self):
mockSender = MockTelemetrySender()
actual = channel.TelemetryChannel(None, mockSender)
def test_write_with_no_data_raises_exception(self):
mock_sender = MockTelemetrySender()
actual = channel.TelemetryChannel(None, mock_sender)
self.assertRaises(Exception, actual.write, None)
def test_writeWithNonClassTypeRaisesException(self):
mockSender = MockTelemetrySender()
actual = channel.TelemetryChannel(None, mockSender)
self.assertRaises(Exception, actual.write, 42)
def test_writeWithBadTypeRaisesException(self):
mockSender = MockTelemetrySender()
actual = channel.TelemetryChannel(None, mockSender)
self.assertRaises(Exception, actual.write, mockSender)
def test_writeTransfersLocalConvextOverGlobalContext(self):
mockSender = MockTelemetrySender()
contextGlobal = channel.TelemetryContext()
contextLocal = channel.TelemetryContext()
actual = channel.TelemetryChannel(contextGlobal, mockSender)
actual.write(channel.contracts.MessageTelemetry(), contextLocal)
self.assertIsNotNone(mockSender.data)
self.assertEqual(contextLocal.device, mockSender.data.device)
def test_write_transfers_local_convext_over_global_context(self):
mock_sender = MockTelemetrySender()
context_global = channel.TelemetryContext()
context_global.device.id = "global"
context_local = channel.TelemetryContext()
context_local.device.id = "local"
actual = channel.TelemetryChannel(context_global, mock_sender)
actual.write(channel.contracts.MessageData(), context_local)
self.assertIsNotNone(mock_sender.data)
self.assertEqual("local", mock_sender.data.tags["ai.device.id"])
def test_writeConstructsValidEnvelope(self):
mockSender = MockTelemetrySender()
contextGlobal = channel.TelemetryContext()
contextGlobal.instrumentationKey = "42"
actual = channel.TelemetryChannel(contextGlobal, mockSender)
def test_write_constructs_valid_envelope(self):
mock_sender = MockTelemetrySender()
context_global = channel.TelemetryContext()
context_global.instrumentation_key = "42"
actual = channel.TelemetryChannel(context_global, mock_sender)
cases = [
(channel.contracts.EventTelemetry(), "Microsoft.ApplicationInsights.Event", "Microsoft.ApplicationInsights.EventData"),
(channel.contracts.MetricTelemetry(), "Microsoft.ApplicationInsights.Metric", "Microsoft.ApplicationInsights.MetricData"),
(channel.contracts.MessageTelemetry(), "Microsoft.ApplicationInsights.Message", "Microsoft.ApplicationInsights.MessageData"),
(channel.contracts.PageViewTelemetry(), "Microsoft.ApplicationInsights.Pageview", "Microsoft.ApplicationInsights.PageviewData"),
(channel.contracts.ExceptionTelemetry(), "Microsoft.ApplicationInsights.Exception", "Microsoft.ApplicationInsights.ExceptionData")
channel.contracts.EventData(),
channel.contracts.MetricData(),
channel.contracts.MessageData(),
channel.contracts.PageViewData(),
channel.contracts.ExceptionData(),
]
for message, typeName1, typeName2 in cases:
actual.write(message)
self.assertIsNotNone(mockSender.data)
self.assertTrue(isinstance(mockSender.data, channel.contracts.TelemetryEnvelope))
self.assertEqual(typeName1, mockSender.data.name)
self.assertIsNotNone(mockSender.data.time)
self.assertEqual("42", mockSender.data.iKey)
self.assertEqual(contextGlobal.device, mockSender.data.device)
self.assertEqual(contextGlobal.application, mockSender.data.application)
self.assertEqual(contextGlobal.user, mockSender.data.user)
self.assertEqual(contextGlobal.session, mockSender.data.session)
self.assertEqual(contextGlobal.location, mockSender.data.location)
self.assertEqual(contextGlobal.operation, mockSender.data.operation)
self.assertIsNotNone(mockSender.data.data)
self.assertEqual(typeName2, mockSender.data.data.type)
self.assertEqual(message, mockSender.data.data.item)
for item in cases:
actual.write(item)
self.assertIsNotNone(mock_sender.data)
self.assertTrue(isinstance(mock_sender.data, channel.contracts.Envelope))
self.assertEqual(item.ENVELOPE_TYPE_NAME, mock_sender.data.name)
self.assertIsNotNone(mock_sender.data.time)
self.assertEqual("42", mock_sender.data.ikey)
for key, value in context_global.device.write().items():
self.assertEqual(value, mock_sender.data.tags[key])
for key, value in context_global.application.write().items():
self.assertEqual(value, mock_sender.data.tags[key])
for key, value in context_global.user.write().items():
self.assertEqual(value, mock_sender.data.tags[key])
for key, value in context_global.session.write().items():
self.assertEqual(value, mock_sender.data.tags[key])
for key, value in context_global.location.write().items():
self.assertEqual(value, mock_sender.data.tags[key])
for key, value in context_global.operation.write().items():
self.assertEqual(value, mock_sender.data.tags[key])
self.assertIsNotNone(mock_sender.data.data)
self.assertEqual(item.DATA_TYPE_NAME, mock_sender.data.data.base_type)
self.assertEqual(item, mock_sender.data.data.base_data)
class MockTelemetrySender(channel.TelemetryChannel().sender.__class__):
def __init__(self):

Просмотреть файл

@ -5,20 +5,20 @@ import locale
from test import test_support
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights import channel
class TestTelemetryContext(unittest.TestCase):
def test_constructTelemetryContext(self):
def test_construct(self):
context = channel.TelemetryContext()
self.assertIsNone(context.instrumentationKey)
self.assertIsNone(context.instrumentation_key)
self.assertIsNotNone(context.device)
self.assertEqual("Other", context.device.type)
self.assertEqual(platform.node(), context.device.id)
self.assertEqual(platform.version(), context.device.osVersion)
self.assertEqual(platform.version(), context.device.os_version)
self.assertEqual(locale.getdefaultlocale()[0], context.device.locale)
self.assertIsNotNone(context.application)
self.assertIsNotNone(context.user)
@ -27,72 +27,84 @@ class TestTelemetryContext(unittest.TestCase):
self.assertIsNotNone(context.location)
self.assertIsNotNone(context.properties)
def test_instrumentationKeyPropertyWorksAsExpected(self):
def test_instrumentation_key_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNone(context.instrumentationKey)
context.instrumentationKey = "foo"
self.assertEqual("foo", context.instrumentationKey)
self.assertIsNone(context.instrumentation_key)
context.instrumentation_key = "foo"
self.assertEqual("foo", context.instrumentation_key)
def test_devicePropertyWorksAsExpected(self):
def test_device_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.device)
context.device = None
self.assertIsNone(context.device)
context.device = Exception()
self.assertIsNone(context.device)
context.device = channel.contracts.DeviceContext()
self.assertIsNotNone(context.device)
self.assertIsInstance(context.device, Exception)
context.device = channel.contracts.Device()
self.assertIsNotNone(context.device)
self.assertIsInstance(context.device, channel.contracts.Device)
def test_applicationPropertyWorksAsExpected(self):
def test_application_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.application)
context.application = None
self.assertIsNone(context.application)
context.application = Exception()
self.assertIsNone(context.application)
context.application = channel.contracts.ApplicationContext()
self.assertIsNotNone(context.application)
self.assertIsInstance(context.application, Exception)
context.application = channel.contracts.Application()
self.assertIsNotNone(context.application)
self.assertIsInstance(context.application, channel.contracts.Application)
def test_userPropertyWorksAsExpected(self):
def test_user_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.user)
context.user = None
self.assertIsNone(context.user)
context.user = Exception()
self.assertIsNone(context.user)
context.user = channel.contracts.UserContext()
self.assertIsNotNone(context.user)
self.assertIsInstance(context.user, Exception)
context.user = channel.contracts.User()
self.assertIsNotNone(context.user)
self.assertIsInstance(context.user, channel.contracts.User)
def test_sessionPropertyWorksAsExpected(self):
def test_session_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.session)
context.session = None
self.assertIsNone(context.session)
context.session = Exception()
self.assertIsNone(context.session)
context.session = channel.contracts.SessionContext()
self.assertIsNotNone(context.session)
self.assertIsInstance(context.session, Exception)
context.session = channel.contracts.Session()
self.assertIsNotNone(context.session)
self.assertIsInstance(context.session, channel.contracts.Session)
def test_locationPropertyWorksAsExpected(self):
def test_location_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.location)
context.location = None
self.assertIsNone(context.location)
context.location = Exception()
self.assertIsNone(context.location)
context.location = channel.contracts.LocationContext()
self.assertIsNotNone(context.location)
self.assertIsInstance(context.location, Exception)
context.location = channel.contracts.Location()
self.assertIsNotNone(context.location)
self.assertIsInstance(context.location, channel.contracts.Location)
def test_operationPropertyWorksAsExpected(self):
def test_operation_attribute_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.operation)
context.operation = None
self.assertIsNone(context.operation)
context.operation = Exception()
self.assertIsNone(context.operation)
context.operation = channel.contracts.OperationContext()
self.assertIsNotNone(context.operation)
self.assertIsInstance(context.operation, Exception)
context.operation = channel.contracts.Operation()
self.assertIsNotNone(context.operation)
self.assertIsInstance(context.operation, channel.contracts.Operation)
def test_propertiesPropertyWorksAsExpected(self):
def test_properties_property_works_as_expected(self):
context = channel.TelemetryContext()
self.assertIsNotNone(context.properties)

Просмотреть файл

@ -5,14 +5,14 @@ import uuid
import unittest
import random
try:
import BaseHTTPServer
import BaseHTTPServer as HTTPServer
except ImportError:
import http.server as BaseHTTPServer
import http.server as HTTPServer
from test import test_support
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
@ -27,44 +27,44 @@ class TestTelemetrySender(unittest.TestCase):
# clean up the telemetry sender type
del self.TelemetrySender
def test_constructTelemetrySender(self):
def test_construct(self):
actual = self.TelemetrySender()
self.assertEqual("http://dc.services.visualstudio.com/v2/track", actual.serviceEndpointUri)
self.assertEqual("http://dc.services.visualstudio.com/v2/track", actual.service_endpoint_uri)
def test_constructTelemetrySenderWithNoEndpoint(self):
def test_construct_with_no_endpoint(self):
self.assertRaises(Exception, self.TelemetrySender, None)
def test_serviceEndpointUriPropertyWorksAsExpected(self):
def test_service_endpoint_uri_property_works_as_expected(self):
actual = self.TelemetrySender()
self.assertEqual("http://dc.services.visualstudio.com/v2/track", actual.serviceEndpointUri)
self.assertEqual("http://dc.services.visualstudio.com/v2/track", actual.service_endpoint_uri)
actual = self.TelemetrySender("blah")
self.assertEqual("blah", actual.serviceEndpointUri)
self.assertEqual("blah", actual.service_endpoint_uri)
def test_sendIntervalInMillisecondsPropertyWorksAsExpected(self):
def test_send_interval_in_milliseconds_property_works_as_expected(self):
actual = self.TelemetrySender()
self.assertEqual(6000, actual.sendIntervalInMilliseconds)
actual.sendIntervalInMilliseconds = 12345;
self.assertEqual(12345, actual.sendIntervalInMilliseconds)
actual.sendIntervalInMilliseconds = -42;
self.assertEqual(1000, actual.sendIntervalInMilliseconds)
self.assertEqual(6000, actual.send_interval_in_milliseconds)
actual.send_interval_in_milliseconds = 12345;
self.assertEqual(12345, actual.send_interval_in_milliseconds)
actual.send_interval_in_milliseconds = -42;
self.assertEqual(1000, actual.send_interval_in_milliseconds)
def test_maxQueueItemCountPropertyWorksAsExpected(self):
def test_max_queue_item_count_property_works_as_expected(self):
actual = self.TelemetrySender()
self.assertEqual(100, actual.maxQueueItemCount)
actual.maxQueueItemCount = 12345;
self.assertEqual(12345, actual.maxQueueItemCount)
actual.maxQueueItemCount = -42;
self.assertEqual(1, actual.maxQueueItemCount)
self.assertEqual(100, actual.max_queue_item_count)
actual.max_queue_item_count = 12345;
self.assertEqual(12345, actual.max_queue_item_count)
actual.max_queue_item_count = -42;
self.assertEqual(1, actual.max_queue_item_count)
def test_sendWorksAsExpected(self):
def test_send_works_as_expected(self):
port = random.randint(50000, 60000)
actual = self.TelemetrySender("http://localhost:" + str(port) + "/track")
actual.maxQueueItemCount = 3
actual.sendIntervalInMilliseconds = 2000
MockHTTPRequestHandler.ExpectedContent = "[42,13]"
actual.max_queue_item_count = 3
actual.send_interval_in_milliseconds = 2000
MockHTTPRequestHandler.ExpectedContent = "[42, 13]"
MockHTTPRequestHandler.TestCase = self # save a reference to the test case in our handler
actual.send(MockSerializable("42")) # send the mock item
actual.send(MockSerializable("13")) # send the mock item
actual.send(MockSerializable(42)) # send the mock item
actual.send(MockSerializable(13)) # send the mock item
runHttpHandlerOnce(handler=MockHTTPRequestHandler, port=port) # run the HTTP request
time.sleep(1)
if "failed" in dir(self):
@ -73,13 +73,13 @@ class TestTelemetrySender(unittest.TestCase):
class MockSerializable(object):
def __init__(self, data):
self.__data = data
self._data = data
def serialize(self):
return self.__data
def write(self):
return self._data
class MockHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class MockHTTPRequestHandler(HTTPServer.BaseHTTPRequestHandler):
ExpectedContent = None
TestCase = None
def do_POST(self):
@ -104,7 +104,7 @@ class MockHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.wfile.write(response)
def runHttpHandlerOnce(server=BaseHTTPServer.HTTPServer, handler=BaseHTTPServer.BaseHTTPRequestHandler, port=8121):
def runHttpHandlerOnce(server=HTTPServer.HTTPServer, handler=HTTPServer.BaseHTTPRequestHandler, port=8121):
serverAddress = ('', port)
httpd = server(serverAddress, handler)
httpd.handle_request()

Просмотреть файл

@ -0,0 +1,36 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestApplication(unittest.TestCase):
def test_construct(self):
item = Application()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 'Test string'
item = Application()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 'Other string'
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Application()
item.ver = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.application.ver": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,48 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestApplicationContext(unittest.TestCase):
def test_constructApplicationContext(self):
item = ApplicationContext()
self.assertNotEqual(item, None)
def test_idPropertyWorksAsExpected(self):
expected = "Test string 1"
item = ApplicationContext()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = "Test string 2"
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_verPropertyWorksAsExpected(self):
expected = "Test string 1"
item = ApplicationContext()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = "Test string 2"
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = ApplicationContext()
item.id = "Test string 1"
item.ver = "Test string 1"
actual = item.serialize()
expected = '{"id":"Test string 1","ver":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,48 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestData(unittest.TestCase):
def test_construct(self):
item = Data()
self.assertNotEqual(item, None)
def test_base_type_property_works_as_expected(self):
expected = 'Test string'
item = Data()
item.base_type = expected
actual = item.base_type
self.assertEqual(expected, actual)
expected = 'Other string'
item.base_type = expected
actual = item.base_type
self.assertEqual(expected, actual)
def test_base_data_property_works_as_expected(self):
expected = Application()
item = Data()
item.base_data = expected
actual = item.base_data
self.assertEqual(expected, actual)
expected = Device()
item.base_data = expected
actual = item.base_data
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Data()
item.base_type = 'Test string'
item.base_data = Application()
actual = json.dumps(item.write())
expected = '{"baseType": "Test string"}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -5,31 +5,42 @@ import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestMetricTelemetryDataPoint(unittest.TestCase):
def test_constructMetricTelemetryDataPoint(self):
item = MetricTelemetryDataPoint()
class TestDataPoint(unittest.TestCase):
def test_construct(self):
item = DataPoint()
self.assertNotEqual(item, None)
def test_namePropertyWorksAsExpected(self):
expected = "Test string 1"
item = MetricTelemetryDataPoint()
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = DataPoint()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = "Test string 2"
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_valuePropertyWorksAsExpected(self):
def test_kind_property_works_as_expected(self):
expected = DataPointType()
item = DataPoint()
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
expected = DataPointType()
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
def test_value_property_works_as_expected(self):
expected = 3.14159265358979
item = MetricTelemetryDataPoint()
item = DataPoint()
item.value = expected
actual = item.value
self.assertEqual(expected, actual)
@ -38,20 +49,9 @@ class TestMetricTelemetryDataPoint(unittest.TestCase):
actual = item.value
self.assertEqual(expected, actual)
def test_kindPropertyWorksAsExpected(self):
expected = "Test string 1"
item = MetricTelemetryDataPoint()
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
expected = "Test string 2"
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
def test_countPropertyWorksAsExpected(self):
def test_count_property_works_as_expected(self):
expected = 42
item = MetricTelemetryDataPoint()
item = DataPoint()
item.count = expected
actual = item.count
self.assertEqual(expected, actual)
@ -60,9 +60,9 @@ class TestMetricTelemetryDataPoint(unittest.TestCase):
actual = item.count
self.assertEqual(expected, actual)
def test_minPropertyWorksAsExpected(self):
def test_min_property_works_as_expected(self):
expected = 3.14159265358979
item = MetricTelemetryDataPoint()
item = DataPoint()
item.min = expected
actual = item.min
self.assertEqual(expected, actual)
@ -71,9 +71,9 @@ class TestMetricTelemetryDataPoint(unittest.TestCase):
actual = item.min
self.assertEqual(expected, actual)
def test_maxPropertyWorksAsExpected(self):
def test_max_property_works_as_expected(self):
expected = 3.14159265358979
item = MetricTelemetryDataPoint()
item = DataPoint()
item.max = expected
actual = item.max
self.assertEqual(expected, actual)
@ -82,27 +82,27 @@ class TestMetricTelemetryDataPoint(unittest.TestCase):
actual = item.max
self.assertEqual(expected, actual)
def test_stdDevPropertyWorksAsExpected(self):
def test_std_dev_property_works_as_expected(self):
expected = 3.14159265358979
item = MetricTelemetryDataPoint()
item.stdDev = expected
actual = item.stdDev
item = DataPoint()
item.std_dev = expected
actual = item.std_dev
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.stdDev = expected
actual = item.stdDev
item.std_dev = expected
actual = item.std_dev
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = MetricTelemetryDataPoint()
item.name = "Test string 1"
def test_serialize_works_as_expected(self):
item = DataPoint()
item.name = 'Test string'
item.kind = DataPointType.aggregation
item.value = 3.14159265358979
item.kind = "Test string 1"
item.count = 42
item.min = 3.14159265358979
item.max = 3.14159265358979
item.stdDev = 3.14159265358979
actual = item.serialize()
expected = '{"name":"Test string 1","value":3.14159265358979,"kind":"Test string 1","count":42,"min":3.14159265358979,"max":3.14159265358979,"stdDev":3.14159265358979}'
self.assertEqual(expected, actual)
item.std_dev = 3.14159265358979
actual = json.dumps(item.write())
expected = '{"name": "Test string", "kind": 1, "value": 3.14159265358979, "count": 42, "min": 3.14159265358979, "max": 3.14159265358979, "stdDev": 3.14159265358979}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -0,0 +1,192 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestDevice(unittest.TestCase):
def test_construct(self):
item = Device()
self.assertNotEqual(item, None)
def test_id_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 'Other string'
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_ip_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.ip = expected
actual = item.ip
self.assertEqual(expected, actual)
expected = 'Other string'
item.ip = expected
actual = item.ip
self.assertEqual(expected, actual)
def test_language_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.language = expected
actual = item.language
self.assertEqual(expected, actual)
expected = 'Other string'
item.language = expected
actual = item.language
self.assertEqual(expected, actual)
def test_locale_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.locale = expected
actual = item.locale
self.assertEqual(expected, actual)
expected = 'Other string'
item.locale = expected
actual = item.locale
self.assertEqual(expected, actual)
def test_model_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.model = expected
actual = item.model
self.assertEqual(expected, actual)
expected = 'Other string'
item.model = expected
actual = item.model
self.assertEqual(expected, actual)
def test_network_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.network = expected
actual = item.network
self.assertEqual(expected, actual)
expected = 'Other string'
item.network = expected
actual = item.network
self.assertEqual(expected, actual)
def test_oem_name_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.oem_name = expected
actual = item.oem_name
self.assertEqual(expected, actual)
expected = 'Other string'
item.oem_name = expected
actual = item.oem_name
self.assertEqual(expected, actual)
def test_os_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.os = expected
actual = item.os
self.assertEqual(expected, actual)
expected = 'Other string'
item.os = expected
actual = item.os
self.assertEqual(expected, actual)
def test_os_version_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.os_version = expected
actual = item.os_version
self.assertEqual(expected, actual)
expected = 'Other string'
item.os_version = expected
actual = item.os_version
self.assertEqual(expected, actual)
def test_role_instance_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.role_instance = expected
actual = item.role_instance
self.assertEqual(expected, actual)
expected = 'Other string'
item.role_instance = expected
actual = item.role_instance
self.assertEqual(expected, actual)
def test_role_name_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.role_name = expected
actual = item.role_name
self.assertEqual(expected, actual)
expected = 'Other string'
item.role_name = expected
actual = item.role_name
self.assertEqual(expected, actual)
def test_screen_resolution_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.screen_resolution = expected
actual = item.screen_resolution
self.assertEqual(expected, actual)
expected = 'Other string'
item.screen_resolution = expected
actual = item.screen_resolution
self.assertEqual(expected, actual)
def test_type_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.type = expected
actual = item.type
self.assertEqual(expected, actual)
expected = 'Other string'
item.type = expected
actual = item.type
self.assertEqual(expected, actual)
def test_vm_name_property_works_as_expected(self):
expected = 'Test string'
item = Device()
item.vm_name = expected
actual = item.vm_name
self.assertEqual(expected, actual)
expected = 'Other string'
item.vm_name = expected
actual = item.vm_name
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Device()
item.id = 'Test string'
item.ip = 'Test string'
item.language = 'Test string'
item.locale = 'Test string'
item.model = 'Test string'
item.network = 'Test string'
item.oem_name = 'Test string'
item.os = 'Test string'
item.os_version = 'Test string'
item.role_instance = 'Test string'
item.role_name = 'Test string'
item.screen_resolution = 'Test string'
item.type = 'Test string'
item.vm_name = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.device.id": "Test string", "ai.device.ip": "Test string", "ai.device.language": "Test string", "ai.device.locale": "Test string", "ai.device.model": "Test string", "ai.device.network": "Test string", "ai.device.oemName": "Test string", "ai.device.os": "Test string", "ai.device.osVersion": "Test string", "ai.device.roleInstance": "Test string", "ai.device.roleName": "Test string", "ai.device.screenResolution": "Test string", "ai.device.type": "Test string", "ai.device.vmName": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,132 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestDeviceContext(unittest.TestCase):
def test_constructDeviceContext(self):
item = DeviceContext()
self.assertNotEqual(item, None)
def test_typePropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.type = expected
actual = item.type
self.assertEqual(expected, actual)
expected = "Test string 2"
item.type = expected
actual = item.type
self.assertEqual(expected, actual)
def test_idPropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = "Test string 2"
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_osPropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.os = expected
actual = item.os
self.assertEqual(expected, actual)
expected = "Test string 2"
item.os = expected
actual = item.os
self.assertEqual(expected, actual)
def test_osVersionPropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.osVersion = expected
actual = item.osVersion
self.assertEqual(expected, actual)
expected = "Test string 2"
item.osVersion = expected
actual = item.osVersion
self.assertEqual(expected, actual)
def test_oemNamePropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.oemName = expected
actual = item.oemName
self.assertEqual(expected, actual)
expected = "Test string 2"
item.oemName = expected
actual = item.oemName
self.assertEqual(expected, actual)
def test_modelPropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.model = expected
actual = item.model
self.assertEqual(expected, actual)
expected = "Test string 2"
item.model = expected
actual = item.model
self.assertEqual(expected, actual)
def test_networkPropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.network = expected
actual = item.network
self.assertEqual(expected, actual)
expected = "Test string 2"
item.network = expected
actual = item.network
self.assertEqual(expected, actual)
def test_resolutionPropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.resolution = expected
actual = item.resolution
self.assertEqual(expected, actual)
expected = "Test string 2"
item.resolution = expected
actual = item.resolution
self.assertEqual(expected, actual)
def test_localePropertyWorksAsExpected(self):
expected = "Test string 1"
item = DeviceContext()
item.locale = expected
actual = item.locale
self.assertEqual(expected, actual)
expected = "Test string 2"
item.locale = expected
actual = item.locale
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = DeviceContext()
item.type = "Test string 1"
item.id = "Test string 1"
item.os = "Test string 1"
item.osVersion = "Test string 1"
item.oemName = "Test string 1"
item.model = "Test string 1"
item.network = "Test string 1"
item.resolution = "Test string 1"
item.locale = "Test string 1"
actual = item.serialize()
expected = '{"type":"Test string 1","id":"Test string 1","os":"Test string 1","osVersion":"Test string 1","oemName":"Test string 1","model":"Test string 1","network":"Test string 1","resolution":"Test string 1","locale":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,202 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestEnvelope(unittest.TestCase):
def test_construct(self):
item = Envelope()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 42
item = Envelope()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_time_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.time = expected
actual = item.time
self.assertEqual(expected, actual)
expected = 'Other string'
item.time = expected
actual = item.time
self.assertEqual(expected, actual)
def test_sample_rate_property_works_as_expected(self):
expected = 3.14159265358979
item = Envelope()
item.sample_rate = expected
actual = item.sample_rate
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.sample_rate = expected
actual = item.sample_rate
self.assertEqual(expected, actual)
def test_seq_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.seq = expected
actual = item.seq
self.assertEqual(expected, actual)
expected = 'Other string'
item.seq = expected
actual = item.seq
self.assertEqual(expected, actual)
def test_ikey_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.ikey = expected
actual = item.ikey
self.assertEqual(expected, actual)
expected = 'Other string'
item.ikey = expected
actual = item.ikey
self.assertEqual(expected, actual)
def test_flags_property_works_as_expected(self):
expected = 42
item = Envelope()
item.flags = expected
actual = item.flags
self.assertEqual(expected, actual)
expected = 13
item.flags = expected
actual = item.flags
self.assertEqual(expected, actual)
def test_device_id_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.device_id = expected
actual = item.device_id
self.assertEqual(expected, actual)
expected = 'Other string'
item.device_id = expected
actual = item.device_id
self.assertEqual(expected, actual)
def test_os_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.os = expected
actual = item.os
self.assertEqual(expected, actual)
expected = 'Other string'
item.os = expected
actual = item.os
self.assertEqual(expected, actual)
def test_os_ver_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.os_ver = expected
actual = item.os_ver
self.assertEqual(expected, actual)
expected = 'Other string'
item.os_ver = expected
actual = item.os_ver
self.assertEqual(expected, actual)
def test_app_id_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.app_id = expected
actual = item.app_id
self.assertEqual(expected, actual)
expected = 'Other string'
item.app_id = expected
actual = item.app_id
self.assertEqual(expected, actual)
def test_app_ver_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.app_ver = expected
actual = item.app_ver
self.assertEqual(expected, actual)
expected = 'Other string'
item.app_ver = expected
actual = item.app_ver
self.assertEqual(expected, actual)
def test_user_id_property_works_as_expected(self):
expected = 'Test string'
item = Envelope()
item.user_id = expected
actual = item.user_id
self.assertEqual(expected, actual)
expected = 'Other string'
item.user_id = expected
actual = item.user_id
self.assertEqual(expected, actual)
def test_tags_property_works_as_expected(self):
item = Envelope()
actual = item.tags
self.assertNotEqual(actual, None)
def test_data_property_works_as_expected(self):
expected = Data()
item = Envelope()
item.data = expected
actual = item.data
self.assertEqual(expected, actual)
expected = Device()
item.data = expected
actual = item.data
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Envelope()
item.ver = 42
item.name = 'Test string'
item.time = 'Test string'
item.sample_rate = 3.14159265358979
item.seq = 'Test string'
item.ikey = 'Test string'
item.flags = 42
item.device_id = 'Test string'
item.os = 'Test string'
item.os_ver = 'Test string'
item.app_id = 'Test string'
item.app_ver = 'Test string'
item.user_id = 'Test string'
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.tags[key] = value
item.data = Data()
item.data.base_type = 'Test string'
actual = json.dumps(item.write())
expected = '{"ver": 42, "name": "Test string", "time": "Test string", "sampleRate": 3.14159265358979, "seq": "Test string", "iKey": "Test string", "flags": 42, "deviceId": "Test string", "os": "Test string", "osVer": "Test string", "appId": "Test string", "appVer": "Test string", "userId": "Test string", "tags": {"key1": "test value 1", "key2": "test value 2"}, "data": {"baseType": "Test string", "baseData": null}}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -5,20 +5,20 @@ import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestEventTelemetry(unittest.TestCase):
def test_constructEventTelemetry(self):
item = EventTelemetry()
class TestEventData(unittest.TestCase):
def test_construct(self):
item = EventData()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
def test_ver_property_works_as_expected(self):
expected = 42
item = EventTelemetry()
item = EventData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
@ -27,40 +27,40 @@ class TestEventTelemetry(unittest.TestCase):
actual = item.ver
self.assertEqual(expected, actual)
def test_namePropertyWorksAsExpected(self):
expected = "Test string 1"
item = EventTelemetry()
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = EventData()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = "Test string 2"
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_propertiesPropertyWorksAsExpected(self):
item = EventTelemetry()
def test_properties_property_works_as_expected(self):
item = EventData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurementsPropertyWorksAsExpected(self):
item = EventTelemetry()
def test_measurements_property_works_as_expected(self):
item = EventData()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = EventTelemetry()
def test_serialize_works_as_expected(self):
item = EventData()
item.ver = 42
item.name = "Test string 1"
myItemDictionary = { "key1": "test value 1" }
item.name = 'Test string'
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { "key1": 3.1415 }
myItemDictionary = { 'key1': 3.1415, 'key2': 42.2 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = item.serialize()
expected = '{"ver":42,"name":"Test string 1","properties":{"key1": "test value 1"},"measurements":{"key1": 3.1415}}'
actual = json.dumps(item.write())
expected = '{"ver": 42, "name": "Test string", "properties": {"key1": "test value 1", "key2": "test value 2"}, "measurements": {"key1": 3.1415, "key2": 42.2}}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,86 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestExceptionData(unittest.TestCase):
def test_construct(self):
item = ExceptionData()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 42
item = ExceptionData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_handled_at_property_works_as_expected(self):
expected = 'Test string'
item = ExceptionData()
item.handled_at = expected
actual = item.handled_at
self.assertEqual(expected, actual)
expected = 'Other string'
item.handled_at = expected
actual = item.handled_at
self.assertEqual(expected, actual)
def test_exceptions_property_works_as_expected(self):
item = ExceptionData()
actual = item.exceptions
self.assertNotEqual(actual, None)
def test_severity_level_property_works_as_expected(self):
expected = SeverityLevel.warning
item = ExceptionData()
item.severity_level = expected
actual = item.severity_level
self.assertEqual(expected, actual)
expected = SeverityLevel.warning
item.severity_level = expected
actual = item.severity_level
self.assertEqual(expected, actual)
def test_properties_property_works_as_expected(self):
item = ExceptionData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurements_property_works_as_expected(self):
item = ExceptionData()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serialize_works_as_expected(self):
item = ExceptionData()
item.ver = 42
item.handled_at = 'Test string'
for value in [ ExceptionDetails() ]:
item.exceptions.append(value)
item.severity_level = SeverityLevel.warning
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { 'key1': 3.1415, 'key2': 42.2 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = json.dumps(item.write())
expected = '{"ver": 42, "handledAt": "Test string", "exceptions": [{"typeName": null, "message": null, "hasFullStack": true}], "severityLevel": 2, "properties": {"key1": "test value 1", "key2": "test value 2"}, "measurements": {"key1": 3.1415, "key2": 42.2}}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -0,0 +1,104 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestExceptionDetails(unittest.TestCase):
def test_construct(self):
item = ExceptionDetails()
self.assertNotEqual(item, None)
def test_id_property_works_as_expected(self):
expected = 42
item = ExceptionDetails()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 13
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_outer_id_property_works_as_expected(self):
expected = 42
item = ExceptionDetails()
item.outer_id = expected
actual = item.outer_id
self.assertEqual(expected, actual)
expected = 13
item.outer_id = expected
actual = item.outer_id
self.assertEqual(expected, actual)
def test_type_name_property_works_as_expected(self):
expected = 'Test string'
item = ExceptionDetails()
item.type_name = expected
actual = item.type_name
self.assertEqual(expected, actual)
expected = 'Other string'
item.type_name = expected
actual = item.type_name
self.assertEqual(expected, actual)
def test_message_property_works_as_expected(self):
expected = 'Test string'
item = ExceptionDetails()
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
expected = 'Other string'
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
def test_has_full_stack_property_works_as_expected(self):
expected = True
item = ExceptionDetails()
item.has_full_stack = expected
actual = item.has_full_stack
self.assertEqual(expected, actual)
expected = False
item.has_full_stack = expected
actual = item.has_full_stack
self.assertEqual(expected, actual)
def test_stack_property_works_as_expected(self):
expected = 'Test string'
item = ExceptionDetails()
item.stack = expected
actual = item.stack
self.assertEqual(expected, actual)
expected = 'Other string'
item.stack = expected
actual = item.stack
self.assertEqual(expected, actual)
def test_parsed_stack_property_works_as_expected(self):
item = ExceptionDetails()
actual = item.parsed_stack
self.assertNotEqual(actual, None)
def test_serialize_works_as_expected(self):
item = ExceptionDetails()
item.id = 42
item.outer_id = 42
item.type_name = 'Test string'
item.message = 'Test string'
item.has_full_stack = True
item.stack = 'Test string'
for value in [ StackFrame() ]:
item.parsed_stack.append(value)
actual = json.dumps(item.write())
expected = '{"id": 42, "outerId": 42, "typeName": "Test string", "message": "Test string", "stack": "Test string", "parsedStack": [{"level": null, "method": null}]}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -1,73 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestExceptionTelemetry(unittest.TestCase):
def test_constructExceptionTelemetry(self):
item = ExceptionTelemetry()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
expected = 42
item = ExceptionTelemetry()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_handledAtPropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetry()
item.handledAt = expected
actual = item.handledAt
self.assertEqual(expected, actual)
expected = "Test string 2"
item.handledAt = expected
actual = item.handledAt
self.assertEqual(expected, actual)
def test_exceptionsPropertyWorksAsExpected(self):
item = ExceptionTelemetry()
actual = item.exceptions
self.assertNotEqual(actual, None)
def test_propertiesPropertyWorksAsExpected(self):
item = ExceptionTelemetry()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurementsPropertyWorksAsExpected(self):
item = ExceptionTelemetry()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = ExceptionTelemetry()
item.ver = 42
item.handledAt = "Test string 1"
for value in [ ExceptionTelemetryDetails() ]:
item.exceptions.append(value)
myItemDictionary = { "key1": "test value 1" }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { "key1": 3.1415 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = item.serialize()
self.assertNotEqual(actual, None)

Просмотреть файл

@ -1,103 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestExceptionTelemetryDetails(unittest.TestCase):
def test_constructExceptionTelemetryDetails(self):
item = ExceptionTelemetryDetails()
self.assertNotEqual(item, None)
def test_idPropertyWorksAsExpected(self):
expected = 42
item = ExceptionTelemetryDetails()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 13
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_outerIdPropertyWorksAsExpected(self):
expected = 42
item = ExceptionTelemetryDetails()
item.outerId = expected
actual = item.outerId
self.assertEqual(expected, actual)
expected = 13
item.outerId = expected
actual = item.outerId
self.assertEqual(expected, actual)
def test_typeNamePropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetryDetails()
item.typeName = expected
actual = item.typeName
self.assertEqual(expected, actual)
expected = "Test string 2"
item.typeName = expected
actual = item.typeName
self.assertEqual(expected, actual)
def test_messagePropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetryDetails()
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
expected = "Test string 2"
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
def test_hasFullStackPropertyWorksAsExpected(self):
expected = True
item = ExceptionTelemetryDetails()
item.hasFullStack = expected
actual = item.hasFullStack
self.assertEqual(expected, actual)
expected = False
item.hasFullStack = expected
actual = item.hasFullStack
self.assertEqual(expected, actual)
def test_stackPropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetryDetails()
item.stack = expected
actual = item.stack
self.assertEqual(expected, actual)
expected = "Test string 2"
item.stack = expected
actual = item.stack
self.assertEqual(expected, actual)
def test_parsedStackPropertyWorksAsExpected(self):
item = ExceptionTelemetryDetails()
actual = item.parsedStack
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = ExceptionTelemetryDetails()
item.id = 42
item.outerId = 42
item.typeName = "Test string 1"
item.message = "Test string 1"
item.hasFullStack = True
item.stack = "Test string 1"
for value in [ ExceptionTelemetryStackFrame() ]:
item.parsedStack.append(value)
actual = item.serialize()
self.assertNotEqual(actual, None)

Просмотреть файл

@ -0,0 +1,48 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestInternal(unittest.TestCase):
def test_construct(self):
item = Internal()
self.assertNotEqual(item, None)
def test_sdk_version_property_works_as_expected(self):
expected = 'Test string'
item = Internal()
item.sdk_version = expected
actual = item.sdk_version
self.assertEqual(expected, actual)
expected = 'Other string'
item.sdk_version = expected
actual = item.sdk_version
self.assertEqual(expected, actual)
def test_agent_version_property_works_as_expected(self):
expected = 'Test string'
item = Internal()
item.agent_version = expected
actual = item.agent_version
self.assertEqual(expected, actual)
expected = 'Other string'
item.agent_version = expected
actual = item.agent_version
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Internal()
item.sdk_version = 'Test string'
item.agent_version = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.internal.sdkVersion": "Test string", "ai.internal.agentVersion": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,36 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestLocation(unittest.TestCase):
def test_construct(self):
item = Location()
self.assertNotEqual(item, None)
def test_ip_property_works_as_expected(self):
expected = 'Test string'
item = Location()
item.ip = expected
actual = item.ip
self.assertEqual(expected, actual)
expected = 'Other string'
item.ip = expected
actual = item.ip
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Location()
item.ip = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.location.ip": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,108 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestLocationContext(unittest.TestCase):
def test_constructLocationContext(self):
item = LocationContext()
self.assertNotEqual(item, None)
def test_latitudePropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.latitude = expected
actual = item.latitude
self.assertEqual(expected, actual)
expected = "Test string 2"
item.latitude = expected
actual = item.latitude
self.assertEqual(expected, actual)
def test_longitudePropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.longitude = expected
actual = item.longitude
self.assertEqual(expected, actual)
expected = "Test string 2"
item.longitude = expected
actual = item.longitude
self.assertEqual(expected, actual)
def test_ipPropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.ip = expected
actual = item.ip
self.assertEqual(expected, actual)
expected = "Test string 2"
item.ip = expected
actual = item.ip
self.assertEqual(expected, actual)
def test_continentPropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.continent = expected
actual = item.continent
self.assertEqual(expected, actual)
expected = "Test string 2"
item.continent = expected
actual = item.continent
self.assertEqual(expected, actual)
def test_countryPropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.country = expected
actual = item.country
self.assertEqual(expected, actual)
expected = "Test string 2"
item.country = expected
actual = item.country
self.assertEqual(expected, actual)
def test_provincePropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.province = expected
actual = item.province
self.assertEqual(expected, actual)
expected = "Test string 2"
item.province = expected
actual = item.province
self.assertEqual(expected, actual)
def test_cityPropertyWorksAsExpected(self):
expected = "Test string 1"
item = LocationContext()
item.city = expected
actual = item.city
self.assertEqual(expected, actual)
expected = "Test string 2"
item.city = expected
actual = item.city
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = LocationContext()
item.latitude = "Test string 1"
item.longitude = "Test string 1"
item.ip = "Test string 1"
item.continent = "Test string 1"
item.country = "Test string 1"
item.province = "Test string 1"
item.city = "Test string 1"
actual = item.serialize()
expected = '{"latitude":"Test string 1","longitude":"Test string 1","ip":"Test string 1","continent":"Test string 1","country":"Test string 1","province":"Test string 1","city":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,69 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestMessageData(unittest.TestCase):
def test_construct(self):
item = MessageData()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 42
item = MessageData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_message_property_works_as_expected(self):
expected = 'Test string'
item = MessageData()
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
expected = 'Other string'
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
def test_severity_level_property_works_as_expected(self):
expected = SeverityLevel.verbose
item = MessageData()
item.severity_level = expected
actual = item.severity_level
self.assertEqual(expected, actual)
expected = SeverityLevel.warning
item.severity_level = expected
actual = item.severity_level
self.assertEqual(expected, actual)
def test_properties_property_works_as_expected(self):
item = MessageData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_serialize_works_as_expected(self):
item = MessageData()
item.ver = 42
item.message = 'Test string'
item.severity_level = SeverityLevel.warning
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
actual = json.dumps(item.write())
expected = '{"ver": 42, "message": "Test string", "severityLevel": 2, "properties": {"key1": "test value 1", "key2": "test value 2"}}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -1,66 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestMessageTelemetry(unittest.TestCase):
def test_constructMessageTelemetry(self):
item = MessageTelemetry()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
expected = 42
item = MessageTelemetry()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_messagePropertyWorksAsExpected(self):
expected = "Test string 1"
item = MessageTelemetry()
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
expected = "Test string 2"
item.message = expected
actual = item.message
self.assertEqual(expected, actual)
def test_propertiesPropertyWorksAsExpected(self):
item = MessageTelemetry()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurementsPropertyWorksAsExpected(self):
item = MessageTelemetry()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = MessageTelemetry()
item.ver = 42
item.message = "Test string 1"
myItemDictionary = { "key1": "test value 1" }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { "key1": 3.1415 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = item.serialize()
expected = '{"ver":42,"message":"Test string 1","properties":{"key1": "test value 1"},"measurements":{"key1": 3.1415}}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -5,20 +5,20 @@ import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestMetricTelemetry(unittest.TestCase):
def test_constructMetricTelemetry(self):
item = MetricTelemetry()
class TestMetricData(unittest.TestCase):
def test_construct(self):
item = MetricData()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
def test_ver_property_works_as_expected(self):
expected = 42
item = MetricTelemetry()
item = MetricData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
@ -27,26 +27,27 @@ class TestMetricTelemetry(unittest.TestCase):
actual = item.ver
self.assertEqual(expected, actual)
def test_metricsPropertyWorksAsExpected(self):
item = MetricTelemetry()
def test_metrics_property_works_as_expected(self):
item = MetricData()
actual = item.metrics
self.assertNotEqual(actual, None)
def test_propertiesPropertyWorksAsExpected(self):
item = MetricTelemetry()
def test_properties_property_works_as_expected(self):
item = MetricData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = MetricTelemetry()
def test_serialize_works_as_expected(self):
item = MetricData()
item.ver = 42
for value in [ MetricTelemetryDataPoint() ]:
for value in [ DataPoint() ]:
item.metrics.append(value)
myItemDictionary = { "key1": "test value 1" }
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
actual = item.serialize()
self.assertNotEqual(actual, None)
actual = json.dumps(item.write())
expected = '{"ver": 42, "metrics": [{"name": null, "kind": 0, "value": null}], "properties": {"key1": "test value 1", "key2": "test value 2"}}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -0,0 +1,72 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestOperation(unittest.TestCase):
def test_construct(self):
item = Operation()
self.assertNotEqual(item, None)
def test_id_property_works_as_expected(self):
expected = 'Test string'
item = Operation()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 'Other string'
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = Operation()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_parent_id_property_works_as_expected(self):
expected = 'Test string'
item = Operation()
item.parent_id = expected
actual = item.parent_id
self.assertEqual(expected, actual)
expected = 'Other string'
item.parent_id = expected
actual = item.parent_id
self.assertEqual(expected, actual)
def test_root_id_property_works_as_expected(self):
expected = 'Test string'
item = Operation()
item.root_id = expected
actual = item.root_id
self.assertEqual(expected, actual)
expected = 'Other string'
item.root_id = expected
actual = item.root_id
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Operation()
item.id = 'Test string'
item.name = 'Test string'
item.parent_id = 'Test string'
item.root_id = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.operation.id": "Test string", "ai.operation.name": "Test string", "ai.operation.parentId": "Test string", "ai.operation.rootId": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,36 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestOperationContext(unittest.TestCase):
def test_constructOperationContext(self):
item = OperationContext()
self.assertNotEqual(item, None)
def test_idPropertyWorksAsExpected(self):
expected = "Test string 1"
item = OperationContext()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = "Test string 2"
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = OperationContext()
item.id = "Test string 1"
actual = item.serialize()
expected = '{"id":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,90 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestPageViewData(unittest.TestCase):
def test_construct(self):
item = PageViewData()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 42
item = PageViewData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_url_property_works_as_expected(self):
expected = 'Test string'
item = PageViewData()
item.url = expected
actual = item.url
self.assertEqual(expected, actual)
expected = 'Other string'
item.url = expected
actual = item.url
self.assertEqual(expected, actual)
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = PageViewData()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_duration_property_works_as_expected(self):
expected = 'Test string'
item = PageViewData()
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
expected = 'Other string'
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
def test_properties_property_works_as_expected(self):
item = PageViewData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurements_property_works_as_expected(self):
item = PageViewData()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serialize_works_as_expected(self):
item = PageViewData()
item.ver = 42
item.url = 'Test string'
item.name = 'Test string'
item.duration = 'Test string'
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { 'key1': 3.1415, 'key2': 42.2 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = json.dumps(item.write())
expected = '{"ver": 42, "url": "Test string", "name": "Test string", "duration": "Test string", "properties": {"key1": "test value 1", "key2": "test value 2"}, "measurements": {"key1": 3.1415, "key2": 42.2}}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,101 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestPageViewTelemetry(unittest.TestCase):
def test_constructPageViewTelemetry(self):
item = PageViewTelemetry()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
expected = 42
item = PageViewTelemetry()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_urlPropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetry()
item.url = expected
actual = item.url
self.assertEqual(expected, actual)
expected = "Test string 2"
item.url = expected
actual = item.url
self.assertEqual(expected, actual)
def test_pageViewPerfPropertyWorksAsExpected(self):
expected = PageViewTelemetryPerf()
item = PageViewTelemetry()
item.pageViewPerf = expected
actual = item.pageViewPerf
self.assertEqual(expected, actual)
expected = PageViewTelemetryPerf()
item.pageViewPerf = expected
actual = item.pageViewPerf
self.assertEqual(expected, actual)
def test_namePropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetry()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = "Test string 2"
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_durationPropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetry()
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
expected = "Test string 2"
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
def test_propertiesPropertyWorksAsExpected(self):
item = PageViewTelemetry()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurementsPropertyWorksAsExpected(self):
item = PageViewTelemetry()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = PageViewTelemetry()
item.ver = 42
item.url = "Test string 1"
item.pageViewPerf = PageViewTelemetryPerf()
item.name = "Test string 1"
item.duration = "Test string 1"
myItemDictionary = { "key1": "test value 1" }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { "key1": 3.1415 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = item.serialize()
self.assertNotEqual(actual, None)

Просмотреть файл

@ -1,84 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestPageViewTelemetryPerf(unittest.TestCase):
def test_constructPageViewTelemetryPerf(self):
item = PageViewTelemetryPerf()
self.assertNotEqual(item, None)
def test_perfTotalPropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetryPerf()
item.perfTotal = expected
actual = item.perfTotal
self.assertEqual(expected, actual)
expected = "Test string 2"
item.perfTotal = expected
actual = item.perfTotal
self.assertEqual(expected, actual)
def test_networkConnectPropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetryPerf()
item.networkConnect = expected
actual = item.networkConnect
self.assertEqual(expected, actual)
expected = "Test string 2"
item.networkConnect = expected
actual = item.networkConnect
self.assertEqual(expected, actual)
def test_sentRequestPropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetryPerf()
item.sentRequest = expected
actual = item.sentRequest
self.assertEqual(expected, actual)
expected = "Test string 2"
item.sentRequest = expected
actual = item.sentRequest
self.assertEqual(expected, actual)
def test_receivedResponsePropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetryPerf()
item.receivedResponse = expected
actual = item.receivedResponse
self.assertEqual(expected, actual)
expected = "Test string 2"
item.receivedResponse = expected
actual = item.receivedResponse
self.assertEqual(expected, actual)
def test_domProcessingPropertyWorksAsExpected(self):
expected = "Test string 1"
item = PageViewTelemetryPerf()
item.domProcessing = expected
actual = item.domProcessing
self.assertEqual(expected, actual)
expected = "Test string 2"
item.domProcessing = expected
actual = item.domProcessing
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = PageViewTelemetryPerf()
item.perfTotal = "Test string 1"
item.networkConnect = "Test string 1"
item.sentRequest = "Test string 1"
item.receivedResponse = "Test string 1"
item.domProcessing = "Test string 1"
actual = item.serialize()
expected = '{"perfTotal":"Test string 1","networkConnect":"Test string 1","sentRequest":"Test string 1","receivedResponse":"Test string 1","domProcessing":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,177 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestRemoteDependencyData(unittest.TestCase):
def test_construct(self):
item = RemoteDependencyData()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 42
item = RemoteDependencyData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = RemoteDependencyData()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_kind_property_works_as_expected(self):
expected = DataPointType()
item = RemoteDependencyData()
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
expected = DataPointType()
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
def test_value_property_works_as_expected(self):
expected = 3.14159265358979
item = RemoteDependencyData()
item.value = expected
actual = item.value
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.value = expected
actual = item.value
self.assertEqual(expected, actual)
def test_count_property_works_as_expected(self):
expected = 42
item = RemoteDependencyData()
item.count = expected
actual = item.count
self.assertEqual(expected, actual)
expected = 13
item.count = expected
actual = item.count
self.assertEqual(expected, actual)
def test_min_property_works_as_expected(self):
expected = 3.14159265358979
item = RemoteDependencyData()
item.min = expected
actual = item.min
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.min = expected
actual = item.min
self.assertEqual(expected, actual)
def test_max_property_works_as_expected(self):
expected = 3.14159265358979
item = RemoteDependencyData()
item.max = expected
actual = item.max
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.max = expected
actual = item.max
self.assertEqual(expected, actual)
def test_std_dev_property_works_as_expected(self):
expected = 3.14159265358979
item = RemoteDependencyData()
item.std_dev = expected
actual = item.std_dev
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.std_dev = expected
actual = item.std_dev
self.assertEqual(expected, actual)
def test_dependency_kind_property_works_as_expected(self):
expected = DependencyKind()
item = RemoteDependencyData()
item.dependency_kind = expected
actual = item.dependency_kind
self.assertEqual(expected, actual)
expected = DependencyKind()
item.dependency_kind = expected
actual = item.dependency_kind
self.assertEqual(expected, actual)
def test_success_property_works_as_expected(self):
expected = True
item = RemoteDependencyData()
item.success = expected
actual = item.success
self.assertEqual(expected, actual)
expected = False
item.success = expected
actual = item.success
self.assertEqual(expected, actual)
def test_async_property_works_as_expected(self):
expected = True
item = RemoteDependencyData()
item.async = expected
actual = item.async
self.assertEqual(expected, actual)
expected = False
item.async = expected
actual = item.async
self.assertEqual(expected, actual)
def test_dependency_source_property_works_as_expected(self):
expected = DependencySourceType()
item = RemoteDependencyData()
item.dependency_source = expected
actual = item.dependency_source
self.assertEqual(expected, actual)
expected = DependencySourceType()
item.dependency_source = expected
actual = item.dependency_source
self.assertEqual(expected, actual)
def test_properties_property_works_as_expected(self):
item = RemoteDependencyData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_serialize_works_as_expected(self):
item = RemoteDependencyData()
item.ver = 42
item.name = 'Test string'
item.kind = DataPointType.aggregation
item.value = 3.14159265358979
item.count = 42
item.min = 3.14159265358979
item.max = 3.14159265358979
item.std_dev = 3.14159265358979
item.dependency_kind = DependencyKind.http_any
item.success = True
item.async = True
item.dependency_source = DependencySourceType.apmc
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
actual = json.dumps(item.write())
expected = '{"ver": 42, "name": "Test string", "kind": 1, "value": 3.14159265358979, "count": 42, "min": 3.14159265358979, "max": 3.14159265358979, "stdDev": 3.14159265358979, "dependencyKind": 2, "async": true, "dependencySource": 2, "properties": {"key1": "test value 1", "key2": "test value 2"}}'
self.assertEqual(actual, expected)

Просмотреть файл

@ -1,150 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestRemoteDependencyTelemetry(unittest.TestCase):
def test_constructRemoteDependencyTelemetry(self):
item = RemoteDependencyTelemetry()
self.assertNotEqual(item, None)
def test_namePropertyWorksAsExpected(self):
expected = "Test string 1"
item = RemoteDependencyTelemetry()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = "Test string 2"
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_dependencyKindPropertyWorksAsExpected(self):
expected = 42
item = RemoteDependencyTelemetry()
item.dependencyKind = expected
actual = item.dependencyKind
self.assertEqual(expected, actual)
expected = 13
item.dependencyKind = expected
actual = item.dependencyKind
self.assertEqual(expected, actual)
def test_valuePropertyWorksAsExpected(self):
expected = 3.14159265358979
item = RemoteDependencyTelemetry()
item.value = expected
actual = item.value
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.value = expected
actual = item.value
self.assertEqual(expected, actual)
def test_resourcePropertyWorksAsExpected(self):
expected = "Test string 1"
item = RemoteDependencyTelemetry()
item.resource = expected
actual = item.resource
self.assertEqual(expected, actual)
expected = "Test string 2"
item.resource = expected
actual = item.resource
self.assertEqual(expected, actual)
def test_kindPropertyWorksAsExpected(self):
expected = "Test string 1"
item = RemoteDependencyTelemetry()
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
expected = "Test string 2"
item.kind = expected
actual = item.kind
self.assertEqual(expected, actual)
def test_countPropertyWorksAsExpected(self):
expected = 42
item = RemoteDependencyTelemetry()
item.count = expected
actual = item.count
self.assertEqual(expected, actual)
expected = 13
item.count = expected
actual = item.count
self.assertEqual(expected, actual)
def test_minPropertyWorksAsExpected(self):
expected = 3.14159265358979
item = RemoteDependencyTelemetry()
item.min = expected
actual = item.min
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.min = expected
actual = item.min
self.assertEqual(expected, actual)
def test_maxPropertyWorksAsExpected(self):
expected = 3.14159265358979
item = RemoteDependencyTelemetry()
item.max = expected
actual = item.max
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.max = expected
actual = item.max
self.assertEqual(expected, actual)
def test_stdDevPropertyWorksAsExpected(self):
expected = 3.14159265358979
item = RemoteDependencyTelemetry()
item.stdDev = expected
actual = item.stdDev
self.assertEqual(expected, actual)
expected = 2.71828182845905
item.stdDev = expected
actual = item.stdDev
self.assertEqual(expected, actual)
def test_propertiesPropertyWorksAsExpected(self):
item = RemoteDependencyTelemetry()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurementsPropertyWorksAsExpected(self):
item = RemoteDependencyTelemetry()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = RemoteDependencyTelemetry()
item.name = "Test string 1"
item.dependencyKind = 42
item.value = 3.14159265358979
item.resource = "Test string 1"
item.kind = "Test string 1"
item.count = 42
item.min = 3.14159265358979
item.max = 3.14159265358979
item.stdDev = 3.14159265358979
myItemDictionary = { "key1": "test value 1" }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { "key1": 3.1415 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = item.serialize()
expected = '{"name":"Test string 1","dependencyKind":42,"value":3.14159265358979,"resource":"Test string 1","kind":"Test string 1","count":42,"min":3.14159265358979,"max":3.14159265358979,"stdDev":3.14159265358979,"properties":{"key1": "test value 1"},"measurements":{"key1": 3.1415}}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,150 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestRequestData(unittest.TestCase):
def test_construct(self):
item = RequestData()
self.assertNotEqual(item, None)
def test_ver_property_works_as_expected(self):
expected = 42
item = RequestData()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_id_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 'Other string'
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_name_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = 'Other string'
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_start_time_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.start_time = expected
actual = item.start_time
self.assertEqual(expected, actual)
expected = 'Other string'
item.start_time = expected
actual = item.start_time
self.assertEqual(expected, actual)
def test_duration_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
expected = 'Other string'
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
def test_response_code_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.response_code = expected
actual = item.response_code
self.assertEqual(expected, actual)
expected = 'Other string'
item.response_code = expected
actual = item.response_code
self.assertEqual(expected, actual)
def test_success_property_works_as_expected(self):
expected = True
item = RequestData()
item.success = expected
actual = item.success
self.assertEqual(expected, actual)
expected = False
item.success = expected
actual = item.success
self.assertEqual(expected, actual)
def test_http_method_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.http_method = expected
actual = item.http_method
self.assertEqual(expected, actual)
expected = 'Other string'
item.http_method = expected
actual = item.http_method
self.assertEqual(expected, actual)
def test_url_property_works_as_expected(self):
expected = 'Test string'
item = RequestData()
item.url = expected
actual = item.url
self.assertEqual(expected, actual)
expected = 'Other string'
item.url = expected
actual = item.url
self.assertEqual(expected, actual)
def test_properties_property_works_as_expected(self):
item = RequestData()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurements_property_works_as_expected(self):
item = RequestData()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serialize_works_as_expected(self):
item = RequestData()
item.ver = 42
item.id = 'Test string'
item.name = 'Test string'
item.start_time = 'Test string'
item.duration = 'Test string'
item.response_code = 'Test string'
item.success = True
item.http_method = 'Test string'
item.url = 'Test string'
myItemDictionary = { 'key1': 'test value 1', 'key2': 'test value 2' }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { 'key1': 3.1415, 'key2': 42.2 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = json.dumps(item.write())
expected = '{"ver": 42, "id": "Test string", "name": "Test string", "startTime": "Test string", "duration": "Test string", "responseCode": "Test string", "success": true, "httpMethod": "Test string", "url": "Test string", "properties": {"key1": "test value 1", "key2": "test value 2"}, "measurements": {"key1": 3.1415, "key2": 42.2}}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,126 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestRequestTelemetry(unittest.TestCase):
def test_constructRequestTelemetry(self):
item = RequestTelemetry()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
expected = 42
item = RequestTelemetry()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_namePropertyWorksAsExpected(self):
expected = "Test string 1"
item = RequestTelemetry()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = "Test string 2"
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_idPropertyWorksAsExpected(self):
expected = "Test string 1"
item = RequestTelemetry()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = "Test string 2"
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_startTimePropertyWorksAsExpected(self):
expected = "Test string 1"
item = RequestTelemetry()
item.startTime = expected
actual = item.startTime
self.assertEqual(expected, actual)
expected = "Test string 2"
item.startTime = expected
actual = item.startTime
self.assertEqual(expected, actual)
def test_durationPropertyWorksAsExpected(self):
expected = "Test string 1"
item = RequestTelemetry()
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
expected = "Test string 2"
item.duration = expected
actual = item.duration
self.assertEqual(expected, actual)
def test_responseCodePropertyWorksAsExpected(self):
expected = "Test string 1"
item = RequestTelemetry()
item.responseCode = expected
actual = item.responseCode
self.assertEqual(expected, actual)
expected = "Test string 2"
item.responseCode = expected
actual = item.responseCode
self.assertEqual(expected, actual)
def test_successPropertyWorksAsExpected(self):
expected = True
item = RequestTelemetry()
item.success = expected
actual = item.success
self.assertEqual(expected, actual)
expected = False
item.success = expected
actual = item.success
self.assertEqual(expected, actual)
def test_propertiesPropertyWorksAsExpected(self):
item = RequestTelemetry()
actual = item.properties
self.assertNotEqual(actual, None)
def test_measurementsPropertyWorksAsExpected(self):
item = RequestTelemetry()
actual = item.measurements
self.assertNotEqual(actual, None)
def test_serializeMethod(self):
item = RequestTelemetry()
item.ver = 42
item.name = "Test string 1"
item.id = "Test string 1"
item.startTime = "Test string 1"
item.duration = "Test string 1"
item.responseCode = "Test string 1"
item.success = True
myItemDictionary = { "key1": "test value 1" }
for key, value in myItemDictionary.items():
item.properties[key] = value
myItemDictionary = { "key1": 3.1415 }
for key, value in myItemDictionary.items():
item.measurements[key] = value
actual = item.serialize()
expected = '{"ver":42,"name":"Test string 1","id":"Test string 1","startTime":"Test string 1","duration":"Test string 1","responseCode":"Test string 1","success":true,"properties":{"key1": "test value 1"},"measurements":{"key1": 3.1415}}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -0,0 +1,60 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestSession(unittest.TestCase):
def test_construct(self):
item = Session()
self.assertNotEqual(item, None)
def test_id_property_works_as_expected(self):
expected = 'Test string'
item = Session()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 'Other string'
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_is_first_property_works_as_expected(self):
expected = 'Test string'
item = Session()
item.is_first = expected
actual = item.is_first
self.assertEqual(expected, actual)
expected = 'Other string'
item.is_first = expected
actual = item.is_first
self.assertEqual(expected, actual)
def test_is_new_property_works_as_expected(self):
expected = 'Test string'
item = Session()
item.is_new = expected
actual = item.is_new
self.assertEqual(expected, actual)
expected = 'Other string'
item.is_new = expected
actual = item.is_new
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = Session()
item.id = 'Test string'
item.is_first = 'Test string'
item.is_new = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.session.id": "Test string", "ai.session.isFirst": "Test string", "ai.session.isNew": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,48 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestSessionContext(unittest.TestCase):
def test_constructSessionContext(self):
item = SessionContext()
self.assertNotEqual(item, None)
def test_idPropertyWorksAsExpected(self):
expected = "Test string 1"
item = SessionContext()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = "Test string 2"
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_firstSessionPropertyWorksAsExpected(self):
expected = "Test string 1"
item = SessionContext()
item.firstSession = expected
actual = item.firstSession
self.assertEqual(expected, actual)
expected = "Test string 2"
item.firstSession = expected
actual = item.firstSession
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = SessionContext()
item.id = "Test string 1"
item.firstSession = "Test string 1"
actual = item.serialize()
expected = '{"id":"Test string 1","firstSession":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -5,20 +5,20 @@ import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestExceptionTelemetryStackFrame(unittest.TestCase):
def test_constructExceptionTelemetryStackFrame(self):
item = ExceptionTelemetryStackFrame()
class TestStackFrame(unittest.TestCase):
def test_construct(self):
item = StackFrame()
self.assertNotEqual(item, None)
def test_levelPropertyWorksAsExpected(self):
def test_level_property_works_as_expected(self):
expected = 42
item = ExceptionTelemetryStackFrame()
item = StackFrame()
item.level = expected
actual = item.level
self.assertEqual(expected, actual)
@ -27,42 +27,42 @@ class TestExceptionTelemetryStackFrame(unittest.TestCase):
actual = item.level
self.assertEqual(expected, actual)
def test_methodPropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetryStackFrame()
def test_method_property_works_as_expected(self):
expected = 'Test string'
item = StackFrame()
item.method = expected
actual = item.method
self.assertEqual(expected, actual)
expected = "Test string 2"
expected = 'Other string'
item.method = expected
actual = item.method
self.assertEqual(expected, actual)
def test_assemblyPropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetryStackFrame()
def test_assembly_property_works_as_expected(self):
expected = 'Test string'
item = StackFrame()
item.assembly = expected
actual = item.assembly
self.assertEqual(expected, actual)
expected = "Test string 2"
expected = 'Other string'
item.assembly = expected
actual = item.assembly
self.assertEqual(expected, actual)
def test_fileNamePropertyWorksAsExpected(self):
expected = "Test string 1"
item = ExceptionTelemetryStackFrame()
item.fileName = expected
actual = item.fileName
def test_file_name_property_works_as_expected(self):
expected = 'Test string'
item = StackFrame()
item.file_name = expected
actual = item.file_name
self.assertEqual(expected, actual)
expected = "Test string 2"
item.fileName = expected
actual = item.fileName
expected = 'Other string'
item.file_name = expected
actual = item.file_name
self.assertEqual(expected, actual)
def test_linePropertyWorksAsExpected(self):
def test_line_property_works_as_expected(self):
expected = 42
item = ExceptionTelemetryStackFrame()
item = StackFrame()
item.line = expected
actual = item.line
self.assertEqual(expected, actual)
@ -71,14 +71,14 @@ class TestExceptionTelemetryStackFrame(unittest.TestCase):
actual = item.line
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = ExceptionTelemetryStackFrame()
def test_serialize_works_as_expected(self):
item = StackFrame()
item.level = 42
item.method = "Test string 1"
item.assembly = "Test string 1"
item.fileName = "Test string 1"
item.method = 'Test string'
item.assembly = 'Test string'
item.file_name = 'Test string'
item.line = 42
actual = item.serialize()
expected = '{"level":42,"method":"Test string 1","assembly":"Test string 1","fileName":"Test string 1","line":42}'
actual = json.dumps(item.write())
expected = '{"level": 42, "method": "Test string", "assembly": "Test string", "fileName": "Test string", "line": 42}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,155 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestTelemetryEnvelope(unittest.TestCase):
def test_constructTelemetryEnvelope(self):
item = TelemetryEnvelope()
self.assertNotEqual(item, None)
def test_verPropertyWorksAsExpected(self):
expected = 42
item = TelemetryEnvelope()
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
expected = 13
item.ver = expected
actual = item.ver
self.assertEqual(expected, actual)
def test_namePropertyWorksAsExpected(self):
expected = "Test string 1"
item = TelemetryEnvelope()
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
expected = "Test string 2"
item.name = expected
actual = item.name
self.assertEqual(expected, actual)
def test_timePropertyWorksAsExpected(self):
expected = "Test string 1"
item = TelemetryEnvelope()
item.time = expected
actual = item.time
self.assertEqual(expected, actual)
expected = "Test string 2"
item.time = expected
actual = item.time
self.assertEqual(expected, actual)
def test_iKeyPropertyWorksAsExpected(self):
expected = "Test string 1"
item = TelemetryEnvelope()
item.iKey = expected
actual = item.iKey
self.assertEqual(expected, actual)
expected = "Test string 2"
item.iKey = expected
actual = item.iKey
self.assertEqual(expected, actual)
def test_applicationPropertyWorksAsExpected(self):
expected = ApplicationContext()
item = TelemetryEnvelope()
item.application = expected
actual = item.application
self.assertEqual(expected, actual)
expected = ApplicationContext()
item.application = expected
actual = item.application
self.assertEqual(expected, actual)
def test_devicePropertyWorksAsExpected(self):
expected = DeviceContext()
item = TelemetryEnvelope()
item.device = expected
actual = item.device
self.assertEqual(expected, actual)
expected = DeviceContext()
item.device = expected
actual = item.device
self.assertEqual(expected, actual)
def test_userPropertyWorksAsExpected(self):
expected = UserContext()
item = TelemetryEnvelope()
item.user = expected
actual = item.user
self.assertEqual(expected, actual)
expected = UserContext()
item.user = expected
actual = item.user
self.assertEqual(expected, actual)
def test_sessionPropertyWorksAsExpected(self):
expected = SessionContext()
item = TelemetryEnvelope()
item.session = expected
actual = item.session
self.assertEqual(expected, actual)
expected = SessionContext()
item.session = expected
actual = item.session
self.assertEqual(expected, actual)
def test_locationPropertyWorksAsExpected(self):
expected = LocationContext()
item = TelemetryEnvelope()
item.location = expected
actual = item.location
self.assertEqual(expected, actual)
expected = LocationContext()
item.location = expected
actual = item.location
self.assertEqual(expected, actual)
def test_operationPropertyWorksAsExpected(self):
expected = OperationContext()
item = TelemetryEnvelope()
item.operation = expected
actual = item.operation
self.assertEqual(expected, actual)
expected = OperationContext()
item.operation = expected
actual = item.operation
self.assertEqual(expected, actual)
def test_dataPropertyWorksAsExpected(self):
expected = TelemetryEnvelopeData()
item = TelemetryEnvelope()
item.data = expected
actual = item.data
self.assertEqual(expected, actual)
expected = TelemetryEnvelopeData()
item.data = expected
actual = item.data
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = TelemetryEnvelope()
item.ver = 42
item.name = "Test string 1"
item.time = "Test string 1"
item.iKey = "Test string 1"
item.application = ApplicationContext()
item.device = DeviceContext()
item.user = UserContext()
item.session = SessionContext()
item.location = LocationContext()
item.operation = OperationContext()
item.data = TelemetryEnvelopeData()
actual = item.serialize()
self.assertNotEqual(actual, None)

Просмотреть файл

@ -1,47 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestTelemetryEnvelopeData(unittest.TestCase):
def test_constructTelemetryEnvelopeData(self):
item = TelemetryEnvelopeData()
self.assertNotEqual(item, None)
def test_typePropertyWorksAsExpected(self):
expected = "Test string 1"
item = TelemetryEnvelopeData()
item.type = expected
actual = item.type
self.assertEqual(expected, actual)
expected = "Test string 2"
item.type = expected
actual = item.type
self.assertEqual(expected, actual)
def test_itemPropertyWorksAsExpected(self):
expected = MetricTelemetry()
item = TelemetryEnvelopeData()
item.item = expected
actual = item.item
self.assertEqual(expected, actual)
expected = MessageTelemetry()
item.item = expected
actual = item.item
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = TelemetryEnvelopeData()
item.type = "Test string 1"
item.item = MetricTelemetry()
actual = item.serialize()
self.assertNotEqual(actual, None)

Просмотреть файл

@ -0,0 +1,72 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..')
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestUser(unittest.TestCase):
def test_construct(self):
item = User()
self.assertNotEqual(item, None)
def test_account_acquisition_date_property_works_as_expected(self):
expected = 'Test string'
item = User()
item.account_acquisition_date = expected
actual = item.account_acquisition_date
self.assertEqual(expected, actual)
expected = 'Other string'
item.account_acquisition_date = expected
actual = item.account_acquisition_date
self.assertEqual(expected, actual)
def test_account_id_property_works_as_expected(self):
expected = 'Test string'
item = User()
item.account_id = expected
actual = item.account_id
self.assertEqual(expected, actual)
expected = 'Other string'
item.account_id = expected
actual = item.account_id
self.assertEqual(expected, actual)
def test_user_agent_property_works_as_expected(self):
expected = 'Test string'
item = User()
item.user_agent = expected
actual = item.user_agent
self.assertEqual(expected, actual)
expected = 'Other string'
item.user_agent = expected
actual = item.user_agent
self.assertEqual(expected, actual)
def test_id_property_works_as_expected(self):
expected = 'Test string'
item = User()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = 'Other string'
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_serialize_works_as_expected(self):
item = User()
item.account_acquisition_date = 'Test string'
item.account_id = 'Test string'
item.user_agent = 'Test string'
item.id = 'Test string'
actual = json.dumps(item.write())
expected = '{"ai.user.accountAcquisitionDate": "Test string", "ai.user.accountId": "Test string", "ai.user.userAgent": "Test string", "ai.user.id": "Test string"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,48 +0,0 @@
import unittest
import datetime
import uuid
import sys
import json
import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "..")
if rootDirectory not in sys.path:
sys.path.append(rootDirectory)
from applicationinsights.channel.contracts import *
class TestUserContext(unittest.TestCase):
def test_constructUserContext(self):
item = UserContext()
self.assertNotEqual(item, None)
def test_idPropertyWorksAsExpected(self):
expected = "Test string 1"
item = UserContext()
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
expected = "Test string 2"
item.id = expected
actual = item.id
self.assertEqual(expected, actual)
def test_accountIdPropertyWorksAsExpected(self):
expected = "Test string 1"
item = UserContext()
item.accountId = expected
actual = item.accountId
self.assertEqual(expected, actual)
expected = "Test string 2"
item.accountId = expected
actual = item.accountId
self.assertEqual(expected, actual)
def test_serializeMethod(self):
item = UserContext()
item.id = "Test string 1"
item.accountId = "Test string 1"
actual = item.serialize()
expected = '{"id":"Test string 1","accountId":"Test string 1"}'
self.assertEqual(expected, actual)

Просмотреть файл

@ -1,19 +1,19 @@
from .TestApplicationContext import TestApplicationContext
from .TestDeviceContext import TestDeviceContext
from .TestLocationContext import TestLocationContext
from .TestOperationContext import TestOperationContext
from .TestSessionContext import TestSessionContext
from .TestUserContext import TestUserContext
from .TestTelemetryEnvelopeData import TestTelemetryEnvelopeData
from .TestTelemetryEnvelope import TestTelemetryEnvelope
from .TestEventTelemetry import TestEventTelemetry
from .TestExceptionTelemetryStackFrame import TestExceptionTelemetryStackFrame
from .TestExceptionTelemetryDetails import TestExceptionTelemetryDetails
from .TestExceptionTelemetry import TestExceptionTelemetry
from .TestMetricTelemetryDataPoint import TestMetricTelemetryDataPoint
from .TestMetricTelemetry import TestMetricTelemetry
from .TestPageViewTelemetryPerf import TestPageViewTelemetryPerf
from .TestPageViewTelemetry import TestPageViewTelemetry
from .TestRemoteDependencyTelemetry import TestRemoteDependencyTelemetry
from .TestRequestTelemetry import TestRequestTelemetry
from .TestMessageTelemetry import TestMessageTelemetry
from .TestData import TestData
from .TestEnvelope import TestEnvelope
from .TestDataPoint import TestDataPoint
from .TestMetricData import TestMetricData
from .TestRemoteDependencyData import TestRemoteDependencyData
from .TestRequestData import TestRequestData
from .TestStackFrame import TestStackFrame
from .TestExceptionDetails import TestExceptionDetails
from .TestExceptionData import TestExceptionData
from .TestMessageData import TestMessageData
from .TestEventData import TestEventData
from .TestPageViewData import TestPageViewData
from .TestApplication import TestApplication
from .TestDevice import TestDevice
from .TestLocation import TestLocation
from .TestOperation import TestOperation
from .TestSession import TestSession
from .TestUser import TestUser
from .TestInternal import TestInternal

Просмотреть файл

@ -13,25 +13,25 @@ def test_main():
applicationinsights_tests.channel_tests.TestTelemetryChannel.TestTelemetryChannel,
applicationinsights_tests.channel_tests.TestTelemetryContext.TestTelemetryContext,
applicationinsights_tests.channel_tests.TestTelemetrySender.TestTelemetrySender,
applicationinsights_tests.channel_tests.contracts_tests.TestApplicationContext,
applicationinsights_tests.channel_tests.contracts_tests.TestDeviceContext,
applicationinsights_tests.channel_tests.contracts_tests.TestEventTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestExceptionTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestExceptionTelemetryDetails,
applicationinsights_tests.channel_tests.contracts_tests.TestExceptionTelemetryStackFrame,
applicationinsights_tests.channel_tests.contracts_tests.TestLocationContext,
applicationinsights_tests.channel_tests.contracts_tests.TestMessageTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestMetricTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestMetricTelemetryDataPoint,
applicationinsights_tests.channel_tests.contracts_tests.TestOperationContext,
applicationinsights_tests.channel_tests.contracts_tests.TestPageViewTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestPageViewTelemetryPerf,
applicationinsights_tests.channel_tests.contracts_tests.TestRemoteDependencyTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestRequestTelemetry,
applicationinsights_tests.channel_tests.contracts_tests.TestSessionContext,
applicationinsights_tests.channel_tests.contracts_tests.TestTelemetryEnvelope,
applicationinsights_tests.channel_tests.contracts_tests.TestTelemetryEnvelopeData,
applicationinsights_tests.channel_tests.contracts_tests.TestUserContext)
applicationinsights_tests.channel_tests.contracts_tests.TestApplication,
applicationinsights_tests.channel_tests.contracts_tests.TestData,
applicationinsights_tests.channel_tests.contracts_tests.TestDataPoint,
applicationinsights_tests.channel_tests.contracts_tests.TestDevice,
applicationinsights_tests.channel_tests.contracts_tests.TestEnvelope,
applicationinsights_tests.channel_tests.contracts_tests.TestEventData,
applicationinsights_tests.channel_tests.contracts_tests.TestExceptionData,
applicationinsights_tests.channel_tests.contracts_tests.TestExceptionDetails,
applicationinsights_tests.channel_tests.contracts_tests.TestInternal,
applicationinsights_tests.channel_tests.contracts_tests.TestLocation,
applicationinsights_tests.channel_tests.contracts_tests.TestMessageData,
applicationinsights_tests.channel_tests.contracts_tests.TestMetricData,
applicationinsights_tests.channel_tests.contracts_tests.TestOperation,
applicationinsights_tests.channel_tests.contracts_tests.TestPageViewData,
applicationinsights_tests.channel_tests.contracts_tests.TestRemoteDependencyData,
applicationinsights_tests.channel_tests.contracts_tests.TestRequestData,
applicationinsights_tests.channel_tests.contracts_tests.TestSession,
applicationinsights_tests.channel_tests.contracts_tests.TestStackFrame,
applicationinsights_tests.channel_tests.contracts_tests.TestUser)
if __name__ == '__main__':
test_main()