Skip to content

Commit 0e714e7

Browse files
committed
Add interpreter to GA
1 parent 8d41543 commit 0e714e7

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

reportportal_client/external/google_analytics.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import logging
19+
from platform import python_version
1920
from pkg_resources import get_distribution
2021
import requests
2122
from uuid import uuid4
@@ -34,6 +35,14 @@ def _get_client_info():
3435
return client.project_name, client.version
3536

3637

38+
def _get_platform_info():
39+
"""Get current platform basic info, e.g.: 'Python 3.6.1'.
40+
41+
:return: str represents the current platform, e.g.: 'Python 3.6.1'
42+
"""
43+
return "Python " + python_version()
44+
45+
3746
def send_event(agent_name, agent_version):
3847
"""Send an event to GA about client and agent versions with their names.
3948
@@ -47,8 +56,8 @@ def send_event(agent_name, agent_version):
4756
'aip': '1',
4857
'cid': str(uuid4()),
4958
't': 'event',
50-
'ec': 'Client name "{}", version "{}"'.format(
51-
client_name, client_version
59+
'ec': 'Client name "{}", version "{}", interpreter "{}"'.format(
60+
client_name, client_version, _get_platform_info()
5261
),
5362
'ea': 'Start launch',
5463
'el': 'Agent name "{}", version "{}"'.format(

reportportal_client/external/google_analytics.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ logger: Logger
77

88
def _get_client_info() -> tuple: ...
99

10+
def _get_platform_info() -> str: ...
11+
1012
def send_event(agent_name: Text, agent_version: Text) -> requests.Response: ...

tests/test_analytics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
from reportportal_client.external.constants import GA_ENDPOINT, GA_INSTANCE
2323
from reportportal_client.external.google_analytics import send_event
2424

25+
TEST_PYTHON_VERSION = '3.6.6'
26+
2527

2628
@mock.patch('reportportal_client.external.google_analytics.uuid4',
2729
mock.Mock(return_value=555))
2830
@mock.patch('reportportal_client.external.google_analytics.requests.post')
2931
@mock.patch('reportportal_client.external.google_analytics.get_distribution')
32+
@mock.patch('reportportal_client.external.google_analytics.python_version',
33+
mock.Mock(return_value=TEST_PYTHON_VERSION))
3034
def test_send_event(mocked_distribution, mocked_requests):
3135
"""Test functionality of the send_event() function.
3236
@@ -46,8 +50,8 @@ def test_send_event(mocked_distribution, mocked_requests):
4650
'aip': '1',
4751
'cid': '555',
4852
't': 'event',
49-
'ec': 'Client name "{}", version "{}"'.format(
50-
expected_cl_name, expected_cl_version
53+
'ec': 'Client name "{}", version "{}", interpreter "Python {}"'.format(
54+
expected_cl_name, expected_cl_version, TEST_PYTHON_VERSION
5155
),
5256
'ea': 'Start launch',
5357
'el': 'Agent name "{}", version "{}"'.format(

0 commit comments

Comments
 (0)