From de2da76fc3018d6efa14be79bbc4bbf0f6849127 Mon Sep 17 00:00:00 2001 From: Rafa Garcia Date: Mon, 30 Sep 2024 10:22:23 +0100 Subject: [PATCH] Disable pre-release workflow --- conf/env.py | 1 - conf/settings.py | 2 - dataservices/management/commands/helpers.py | 45 +++---------------- .../commands/import_market_guides_data.py | 13 ++---- .../commands/tests/test_import_data.py | 43 +++++++----------- dataservices/tests/test_helpers.py | 38 ---------------- 6 files changed, 25 insertions(+), 117 deletions(-) diff --git a/conf/env.py b/conf/env.py index 7107374c..f5ba5144 100644 --- a/conf/env.py +++ b/conf/env.py @@ -102,7 +102,6 @@ class BaseSettings(PydanticBaseSettings): ownership_invite_subject: str = 'Confirm ownership of {company_name}’s Find a buyer profile' collaborator_invite_subject: str = 'Confirm you’ve been added to {company_name}’s Find a buyer profile' great_marketguides_teams_channel_email: str - great_marketguides_review_period_days: int = 10 # Automated email settings verification_code_not_given_subject: str = 'Please verify your company’s Find a buyer profile' diff --git a/conf/settings.py b/conf/settings.py index a95d5b78..353927da 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -333,8 +333,6 @@ OWNERSHIP_INVITE_SUBJECT = env.ownership_invite_subject COLLABORATOR_INVITE_SUBJECT = env.collaborator_invite_subject GREAT_MARKETGUIDES_TEAMS_CHANNEL_EMAIL = env.great_marketguides_teams_channel_email -GREAT_MARKETGUIDES_REVIEW_PERIOD_DAYS = env.great_marketguides_review_period_days - # Public storage for company profile logo STORAGE_CLASSES = { diff --git a/dataservices/management/commands/helpers.py b/dataservices/management/commands/helpers.py index 62565ee5..d17e74bb 100644 --- a/dataservices/management/commands/helpers.py +++ b/dataservices/management/commands/helpers.py @@ -1,6 +1,5 @@ import io -from datetime import datetime, timedelta -from sys import stdout +from datetime import datetime from zipfile import ZipFile import pandas as pd @@ -46,35 +45,6 @@ def send_ingest_error_notify_email(view_name, error_details): ) -def send_review_request_message(view_name): - instance, _created = Metadata.objects.get_or_create(view_name=view_name) - last_release = datetime.strptime(instance.data['source']['last_release'], '%Y-%m-%dT%H:%M:%S') - - try: - last_notification_sent = datetime.strptime( - instance.data['review_process']['notification_sent'], '%Y-%m-%dT%H:%M:%S' - ) - except KeyError: - instance.data['review_process'] = {'notification_sent': None} - last_notification_sent = None - - if last_notification_sent is None or (((last_notification_sent.timestamp() - last_release.timestamp())) < 0): - notifications_client().send_email_notification( - email_address=settings.GREAT_MARKETGUIDES_TEAMS_CHANNEL_EMAIL, - template_id=settings.GOVNOTIFY_GREAT_MARKETGUIDES_REVIEW_REQUEST_TEMPLATE_ID, - personalisation={ - 'view_name': view_name, - 'review_url': 'https://great.staging.uktrade.digital/markets/', - 'release_date': ( - last_release + timedelta(days=settings.GREAT_MARKETGUIDES_REVIEW_PERIOD_DAYS) - ).strftime('%d/%m/%Y'), - }, - ) - stdout.write(f"Sent review request notification for {view_name}") - instance.data['review_process']['notification_sent'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') - instance.save() - - class BaseDataWorkspaceIngestionCommand(BaseCommand): engine = sa.create_engine(settings.DATA_WORKSPACE_DATASETS_URL, execution_options={'stream_results': True}) @@ -114,15 +84,10 @@ def should_ingestion_run(self, view_name, table_name): if great_metadata is not None: great_metadata_date = datetime.strptime(great_metadata, '%Y-%m-%dT%H:%M:%S').date() if swapped_date > great_metadata_date: - if settings.APP_ENVIRONMENT != 'production' or ( - settings.APP_ENVIRONMENT == 'production' - and datetime.now().date() - > (swapped_date + timedelta(days=settings.GREAT_MARKETGUIDES_REVIEW_PERIOD_DAYS)) - ): - self.stdout.write( - self.style.SUCCESS(f'Importing {view_name} data into {settings.APP_ENVIRONMENT} env.') - ) - return True + self.stdout.write( + self.style.SUCCESS(f'Importing {view_name} data into {settings.APP_ENVIRONMENT} env.') + ) + return True return False diff --git a/dataservices/management/commands/import_market_guides_data.py b/dataservices/management/commands/import_market_guides_data.py index c596d00f..b0d39a2d 100644 --- a/dataservices/management/commands/import_market_guides_data.py +++ b/dataservices/management/commands/import_market_guides_data.py @@ -1,11 +1,6 @@ -from django.conf import settings from django.core.management import BaseCommand, call_command -from dataservices.management.commands.helpers import ( - MarketGuidesDataIngestionCommand, - send_ingest_error_notify_email, - send_review_request_message, -) +from dataservices.management.commands.helpers import MarketGuidesDataIngestionCommand, send_ingest_error_notify_email class Command(BaseCommand): @@ -45,10 +40,8 @@ def handle(self, *args, **options): self.stdout.write(self.style.NOTICE(f'Running {command_name}')) try: call_command(command_name, **options) - call_command('import_metadata_source_data', table=table_view_names['table_name']) - - if settings.APP_ENVIRONMENT == 'staging': - send_review_request_message(table_view_names['view_name']) + if options['write']: + call_command('import_metadata_source_data', table=table_view_names['table_name']) self.stdout.write(self.style.SUCCESS(f'Finished import for {table_view_names["view_name"]}')) except Exception as e: diff --git a/dataservices/management/commands/tests/test_import_data.py b/dataservices/management/commands/tests/test_import_data.py index b3922c15..1c1d9a93 100644 --- a/dataservices/management/commands/tests/test_import_data.py +++ b/dataservices/management/commands/tests/test_import_data.py @@ -433,35 +433,26 @@ def test_import_metadata_source_data_filter_tables(): @pytest.mark.django_db -@pytest.mark.parametrize( - 'env, review_requested_x_times', - [('dev', 0), ('staging', 4), ('uat', 0), ('production', 0)], -) @mock.patch('dataservices.management.commands.import_market_guides_data.call_command') @mock.patch('dataservices.management.commands.helpers.MarketGuidesDataIngestionCommand.should_ingestion_run') -@mock.patch('dataservices.management.commands.import_market_guides_data.send_review_request_message') -def test_import_market_guides_data( - mock_send_review_request, mock_should_run, mock_call_command, env, review_requested_x_times -): - with override_settings(APP_ENVIRONMENT=env): - command_list = [ - 'import_uk_total_trade_data', - 'import_uk_trade_in_goods_data', - 'import_uk_trade_in_services_data', - 'import_world_economic_outlook_data', - ] - mock_should_run.return_value = False - management.call_command('import_market_guides_data', '--write') - assert mock_call_command.call_count == 0 +def test_import_market_guides_data(mock_should_run, mock_call_command): + command_list = [ + 'import_uk_total_trade_data', + 'import_uk_trade_in_goods_data', + 'import_uk_trade_in_services_data', + 'import_world_economic_outlook_data', + ] + mock_should_run.return_value = False + management.call_command('import_market_guides_data', '--write') + assert mock_call_command.call_count == 0 - mock_should_run.return_value = True - management.call_command('import_market_guides_data', '--write') - assert mock_call_command.call_count == 8 - assert mock_send_review_request.call_count == review_requested_x_times + mock_should_run.return_value = True + management.call_command('import_market_guides_data', '--write') + assert mock_call_command.call_count == 8 - for command in command_list: - assert command in str(mock_call_command.call_args_list) - assert 'write=True' in str(mock_call_command.call_args_list) + for command in command_list: + assert command in str(mock_call_command.call_args_list) + assert 'write=True' in str(mock_call_command.call_args_list) @pytest.mark.django_db @@ -478,7 +469,7 @@ def test_import_market_guides_data_dry_run(mock_call_command, mock_should_run): management.call_command('import_market_guides_data') - assert mock_call_command.call_count == 8 + assert mock_call_command.call_count == 4 for command in command_list: assert command in str(mock_call_command.call_args_list) diff --git a/dataservices/tests/test_helpers.py b/dataservices/tests/test_helpers.py index 70fe26dc..81ab8113 100644 --- a/dataservices/tests/test_helpers.py +++ b/dataservices/tests/test_helpers.py @@ -1,10 +1,8 @@ import re -from datetime import datetime, timedelta from unittest import mock import pytest from django.conf import settings -from freezegun import freeze_time from dataservices import helpers, models from dataservices.management.commands import helpers as dmch @@ -202,42 +200,6 @@ def test_notify_error_message(mock_notify): assert mock_notify.call_count == 1 -@freeze_time('2023-09-13T15:21:10') -@pytest.mark.django_db -@mock.patch('dataservices.management.commands.helpers.notifications_client') -@pytest.mark.parametrize( - "last_release, notification_sent, result", - [ - (datetime.now().strftime('%Y-%m-%dT%H:%M:%S'), None, 1), - ( - datetime.now().strftime('%Y-%m-%dT%H:%M:%S'), - (datetime.now() - timedelta(days=10)).strftime('%Y-%m-%dT%H:%M:%S'), - 1, - ), - ( - datetime.now().strftime('%Y-%m-%dT%H:%M:%S'), - (datetime.now() + timedelta(minutes=1)).strftime('%Y-%m-%dT%H:%M:%S'), - 0, - ), - ], -) -def test_send_review_request_message(mock_notify, last_release, notification_sent, result): - data = {'source': {'last_release': last_release}} - data['review_process'] = {} if notification_sent is None else {'notification_sent': notification_sent} - factories.MetadataFactory(view_name='TestView', data=data) - dmch.send_review_request_message('TestView') - mock_notify.call_args = mock.call( - email_address='a@b.com', - template_id=settings.GOVNOTIFY_GREAT_MARKETGUIDES_REVIEW_REQUEST_TEMPLATE_ID, - personalisation={ - 'view_name': 'view_name', - 'review_url': 'https://great.staging.uktrade.digital/markets/', - 'release_date': 'dd/mm/YYYY', - }, - ) - assert mock_notify.call_count == result - - @pytest.mark.django_db @pytest.mark.parametrize( 'statista_vertical_name, expected_vertical_name',