diff --git a/app/__init__.py b/app/__init__.py index e9a528072..2f834193b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -66,6 +66,7 @@ def create_app(app_name=None): notify_celery.init_app(application) encryption.init_app(application) redis_store.init_app(application) + performance_platform_client.init_app(application) clients.init_app(sms_clients=[firetext_client, mmg_client, loadtest_client], email_clients=[aws_ses_client]) register_blueprint(application) diff --git a/app/clients/performance_platform/performance_platform_client.py b/app/clients/performance_platform/performance_platform_client.py index 5ad2de7c6..a1d6ca17f 100644 --- a/app/clients/performance_platform/performance_platform_client.py +++ b/app/clients/performance_platform/performance_platform_client.py @@ -13,16 +13,24 @@ from app.utils import ( class PerformancePlatformClient: + @property + def active(self): + return self._active + + @active.setter + def active(self, value): + self._active = value + def init_app(self, app): - self.active = app.config.get('PERFORMANCE_PLATFORM_ENABLED') + self._active = app.config.get('PERFORMANCE_PLATFORM_ENABLED') if self.active: self.bearer_token = app.config.get('PERFORMANCE_PLATFORM_TOKEN') - self.performance_platform_url = current_app.config.get('PERFORMANCE_PLATFORM_URL') + self.performance_platform_url = app.config.get('PERFORMANCE_PLATFORM_URL') def send_performance_stats(self, date, channel, count, period): if self.active: payload = { - '_timestamp': date, + '_timestamp': str(date), 'service': 'govuk-notify', 'channel': channel, 'count': count, @@ -61,9 +69,14 @@ class PerformancePlatformClient: headers=headers ) - if resp.status_code != 200: + if resp.status_code == 200: + current_app.logger.info( + "Updated performance platform successfully with payload {}".format(json.dumps(payload)) + ) + else: current_app.logger.error( - "Performance platform update request failed with {} '{}'".format( + "Performance platform update request failed for payload with response details: {} '{}'".format( + json.dumps(payload), resp.status_code, resp.json()) ) diff --git a/tests/app/clients/test_performance_platform.py b/tests/app/clients/test_performance_platform.py index f72a9ce33..530398dc9 100644 --- a/tests/app/clients/test_performance_platform.py +++ b/tests/app/clients/test_performance_platform.py @@ -17,7 +17,7 @@ def client(mocker): client = PerformancePlatformClient() current_app = mocker.Mock(config={ 'PERFORMANCE_PLATFORM_ENABLED': True, - 'PERFORMANCE_PLATFORM_URL': 'performance-platform-url', + 'PERFORMANCE_PLATFORM_URL': 'https://performance-platform-url/', 'PERFORMANCE_PLATFORM_TOKEN': 'token' }) client.init_app(current_app)