diff --git a/termius/app.py b/termius/app.py index acbcc78..9ff74f8 100644 --- a/termius/app.py +++ b/termius/app.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """Module for main app class.""" import logging -import os from os.path import expanduser from pathlib2 import Path @@ -11,7 +10,6 @@ from cliff.commandmanager import CommandManager from cliff import argparse -from termius.core.analytics import Analytics from termius.core.commands.help import HelpCommand, HelpAction from . import __version__ from .core.signals import ( @@ -61,18 +59,6 @@ def configure_signals(self): post_logout.connect(clean_data) - def prepare_to_run_command(self, cmd): - """Collect analytics if it`s not disabled.""" - if os.getenv('NOT_COLLECT_STAT'): - return - - self.collect_analytics(cmd) - - def collect_analytics(self, cmd): - """Make Analytics instance and send analytics.""" - analytics = Analytics(self, getattr(cmd, 'config', None)) - analytics.send_analytics(cmd.cmd_name) - def build_option_parser(self, description, version, argparse_kwargs=None): """Return an argparse option parser for this application. diff --git a/termius/core/analytics.py b/termius/core/analytics.py deleted file mode 100644 index f0e2b59..0000000 --- a/termius/core/analytics.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -"""Module with logic for Analytics.""" - -import platform - -from google_measurement_protocol import Event, report - -from termius.account.managers import AccountManager -from termius.core.settings import Config -from termius import __version__ - - -class Analytics(object): - """Class to send Analytics.""" - - def __init__(self, app, config=None): - """Construct new Analytics instance.""" - self.config = config - self.app = app - - if self.config is None: - self.config = Config(self) - - self.manager = AccountManager(self.config) - - def send_analytics(self, cmd_name): - """Send event to google analytics.""" - os_info = '%s %s' % (platform.system(), platform.release()) - - info = [ - {'av': __version__}, - {'an': 'Termius CLI'}, - {'ua': os_info}, - {'ostype': os_info} - ] - - event = Event('cli', cmd_name) - report( - self.tracking_id, - self.manager.analytics_id, - event, - extra_info=info - ) - - @property - def tracking_id(self): - """Google Analytics id for termius cli application.""" - return 'UA-56746272-4' diff --git a/tests/unit/app_test.py b/tests/unit/app_test.py deleted file mode 100644 index 35b376a..0000000 --- a/tests/unit/app_test.py +++ /dev/null @@ -1,40 +0,0 @@ -from unittest import TestCase - -import mock - -from termius.app import TermiusApp -from termius.handlers import HostCommand - - -class TestApp(TestCase): - def setUp(self): - self.app = TermiusApp() - - @mock.patch('termius.app.os.getenv') - @mock.patch('termius.app.Analytics') - def test_prepare_to_run_with_analytics(self, analytics_class, getenv): - analytics = mock.Mock() - analytics_class.return_value = analytics - getenv.return_value = None - - cmd_name = 'command' - command = HostCommand(self.app, None, cmd_name) - - self.app.prepare_to_run_command(command) - - getenv.assert_called_once_with('NOT_COLLECT_STAT') - analytics_class.assert_called_once_with(self.app, command.config) - analytics.send_analytics.assert_called_once_with(cmd_name) - - @mock.patch('termius.app.os.getenv') - @mock.patch('termius.app.TermiusApp.collect_analytics') - def test_prepare_to_run_without_analytics(self, collect_analytics, getenv): - getenv.return_value = True - command = HostCommand(self.app, None, 'command') - - self.app.prepare_to_run_command(command) - - getenv.assert_called_once_with('NOT_COLLECT_STAT') - collect_analytics.assert_not_called() - - diff --git a/tests/unit/core/analytics_test.py b/tests/unit/core/analytics_test.py deleted file mode 100644 index 16e9865..0000000 --- a/tests/unit/core/analytics_test.py +++ /dev/null @@ -1,54 +0,0 @@ -from unittest import TestCase - -import mock as mock -import platform -from six.moves import configparser - -from termius import __version__ -from termius.app import TermiusApp -from termius.core.analytics import Analytics - - -class TestAnalytics(TestCase): - def setUp(self): - self.app = TermiusApp() - - self.config_patch = mock.patch('termius.core.analytics.Config') - self.config_class = self.config_patch.start() - self.config = mock.Mock() - self.config_class.return_value = self.config - - def tearDown(self): - self.config_patch.stop() - - @mock.patch('termius.core.analytics.report') - @mock.patch( - 'termius.core.analytics.AccountManager.analytics_id', - new_callable=mock.PropertyMock - ) - @mock.patch('termius.core.analytics.Event') - def test_send_analytics(self, event_class, analytics_id, report): - cmd_name = 'command' - client_id = 'client' - - os = '%s %s' % (platform.system(), platform.release()) - - info = [ - {'av': __version__}, - {'an': 'Termius CLI'}, - {'ua': os}, - {'ostype': os} - ] - - event = mock.Mock() - event_class.return_value = event - analytics_id.return_value = client_id - - analytics = Analytics(self.app) - analytics.send_analytics(cmd_name) - - analytics_id.assert_called_once_with() - event_class.assert_called_once_with('cli', cmd_name) - report.assert_called_once_with( - analytics.tracking_id, client_id, event, extra_info=info - )