From 97faa56a81d1847b58eb2aa19b1668615cd34844 Mon Sep 17 00:00:00 2001 From: Graham Beckley Date: Thu, 29 Jun 2023 08:56:36 -0400 Subject: [PATCH 1/2] Delete test for waitlist migrations This test was helpful to validate the migrations we did in 5d20eb5, but now that we've run the migrations, this test can be safely deleted. --- tests/unit/test_backport_legacy_waitlists.py | 88 -------------------- 1 file changed, 88 deletions(-) diff --git a/tests/unit/test_backport_legacy_waitlists.py b/tests/unit/test_backport_legacy_waitlists.py index b75997dc..d46fb2ae 100644 --- a/tests/unit/test_backport_legacy_waitlists.py +++ b/tests/unit/test_backport_legacy_waitlists.py @@ -121,91 +121,3 @@ def test_relay_waitlist_unsubscribed_on_all_newsletters_unsubscribed( waitlists = get_waitlists_by_email_id(dbsession, email_id) assert waitlists == [] - - -def test_alembic_migration_waitlists(engine): - # Rollback to a revision before the waitlists were implemented as relationships. - # As a side effect, this will test the rollback steps of the migrations files. - cfg = alembic_config.Config(os.path.join(APP_FOLDER, "alembic.ini")) - # pylint: disable-next=unsupported-assignment-operation - cfg.attributes["connection"] = engine - alembic_command.downgrade(cfg, "9c37ea9b5bba") - - # At this point we have the `waitlist` table, but the `vpn_waitlist` - # and `relay_waitlist` haven't been migrated. - - # Create 3 contacts: - # - subscribed to the vpn waitlist - # - subscribed to the relay waitlist - # - subscribed to the relay-vpn-waitlist newsletter - - email_id_vpn, email_id_relay, email_id_newsletter = uuid4(), uuid4(), uuid4() - with engine.connect() as connection: - with connection.begin(): - for email_id in email_id_vpn, email_id_relay, email_id_newsletter: - create_statement = """ - INSERT INTO emails (email_id, primary_email, basket_token, sfdc_id, first_name, last_name, mailing_country, email_format, email_lang, double_opt_in, has_opted_out_of_email, unsubscribe_reason, create_timestamp, update_timestamp) - VALUES (:email_id, :email, :token, '00VA000001aABcDEFG', NULL, NULL, 'us', 'H', 'en', False, False, NULL, NOW(), NOW()) - """ - connection.execute( - text(create_statement), - { - "email_id": str(email_id), - "email": f"{email_id}@example.org", - "token": str(uuid4()), - }, - ) - - subscribe_vpn = """ - INSERT INTO vpn_waitlist(email_id, geo, platform, create_timestamp, update_timestamp) - VALUES (:email_id, 'fr', 'linux', NOW(), NOW()) - """ - connection.execute(text(subscribe_vpn), {"email_id": email_id_vpn}) - - subscribe_relay = """ - INSERT INTO relay_waitlist(email_id, geo, create_timestamp, update_timestamp) - VALUES (:email_id, 'it', NOW(), NOW()) - """ - connection.execute(text(subscribe_relay), {"email_id": email_id_relay}) - - subscribe_newsletter = """ - INSERT INTO newsletters(email_id, name, subscribed, format, lang, source, unsub_reason, update_timestamp) - VALUES (:email_id, 'relay-vpn-waitlist', true, 'H', 'en', NULL, NULL, NOW()); - """ - connection.execute( - text(subscribe_newsletter), {"email_id": email_id_newsletter} - ) - subscribe_relay = """ - INSERT INTO relay_waitlist(email_id, geo, create_timestamp, update_timestamp) - VALUES (:email_id, 'es', NOW(), NOW()) - """ - connection.execute(text(subscribe_relay), {"email_id": email_id_newsletter}) - - # Now migrate. - # pylint: disable-next=unsupported-assignment-operation - cfg.attributes["connection"] = engine - alembic_command.upgrade(cfg, "head") - - # Now use the ORM to inspect that the migration went as expected. - with engine.connect() as connection: - test_sessionmaker = sessionmaker( - autocommit=False, autoflush=False, bind=connection - ) - db = test_sessionmaker() - - contact_vpn = get_email(db, email_id_vpn) - contact_relay = get_email(db, email_id_relay) - contact_newsletter = get_email(db, email_id_newsletter) - - assert len(contact_vpn.waitlists) == 1 - assert contact_vpn.waitlists[0].name == "vpn" - assert contact_vpn.waitlists[0].fields["geo"] == "fr" - assert contact_vpn.waitlists[0].fields["platform"] == "linux" - - assert len(contact_relay.waitlists) == 1 - assert contact_relay.waitlists[0].name == "relay" - assert contact_relay.waitlists[0].fields["geo"] == "it" - - assert len(contact_newsletter.waitlists) == 1 - assert contact_newsletter.waitlists[0].name == "relay-vpn" - assert contact_newsletter.waitlists[0].fields["geo"] == "es" From 4b36110f76893ebbe68d45fd555800788b03cab0 Mon Sep 17 00:00:00 2001 From: Graham Beckley Date: Thu, 29 Jun 2023 09:24:23 -0400 Subject: [PATCH 2/2] Remove now-unneeded imports --- tests/unit/test_backport_legacy_waitlists.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/unit/test_backport_legacy_waitlists.py b/tests/unit/test_backport_legacy_waitlists.py index d46fb2ae..df7e2bc8 100644 --- a/tests/unit/test_backport_legacy_waitlists.py +++ b/tests/unit/test_backport_legacy_waitlists.py @@ -1,11 +1,4 @@ -import os -from uuid import uuid4 - import pytest -from alembic import command as alembic_command -from alembic import config as alembic_config -from sqlalchemy import text -from sqlalchemy.orm import sessionmaker from ctms.crud import ( create_contact, @@ -15,7 +8,6 @@ update_contact, ) from ctms.schemas import ContactPatchSchema, NewsletterInSchema, WaitlistInSchema -from tests.unit.conftest import APP_FOLDER @pytest.fixture