From 726c4d5ce636396cd4ba543567b4ac6ee4f4cf28 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 | 42 ++----------------- .../commands/import_market_guides_data.py | 7 +--- .../commands/tests/test_import_data.py | 10 +---- dataservices/tests/test_helpers.py | 36 ---------------- 6 files changed, 7 insertions(+), 91 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..9dffbcea 100644 --- a/dataservices/management/commands/helpers.py +++ b/dataservices/management/commands/helpers.py @@ -46,35 +46,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 +85,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..59224e83 100644 --- a/dataservices/management/commands/import_market_guides_data.py +++ b/dataservices/management/commands/import_market_guides_data.py @@ -4,7 +4,6 @@ from dataservices.management.commands.helpers import ( MarketGuidesDataIngestionCommand, send_ingest_error_notify_email, - send_review_request_message, ) @@ -45,10 +44,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..8e5b1cb2 100644 --- a/dataservices/management/commands/tests/test_import_data.py +++ b/dataservices/management/commands/tests/test_import_data.py @@ -433,16 +433,9 @@ 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 -): +def test_import_market_guides_data(mock_should_run, mock_call_command, env): with override_settings(APP_ENVIRONMENT=env): command_list = [ 'import_uk_total_trade_data', @@ -457,7 +450,6 @@ def test_import_market_guides_data( 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 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..ded4557f 100644 --- a/dataservices/tests/test_helpers.py +++ b/dataservices/tests/test_helpers.py @@ -202,42 +202,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',