Skip to content

Commit

Permalink
Disable pre-release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa-garcia committed Sep 30, 2024
1 parent f2067d4 commit 726c4d5
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 91 deletions.
1 change: 0 additions & 1 deletion conf/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
42 changes: 4 additions & 38 deletions dataservices/management/commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions dataservices/management/commands/import_market_guides_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from dataservices.management.commands.helpers import (
MarketGuidesDataIngestionCommand,
send_ingest_error_notify_email,
send_review_request_message,
)


Expand Down Expand Up @@ -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:
Expand Down
10 changes: 1 addition & 9 deletions dataservices/management/commands/tests/test_import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand Down
36 changes: 0 additions & 36 deletions dataservices/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
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',
Expand Down

0 comments on commit 726c4d5

Please sign in to comment.