Skip to content

Commit

Permalink
Delete test for waitlist migrations (#720)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
grahamalama authored Jun 29, 2023
1 parent 69d3f20 commit be55776
Showing 1 changed file with 1 addition and 96 deletions.
97 changes: 1 addition & 96 deletions tests/unit/test_backport_legacy_waitlists.py
Original file line number Diff line number Diff line change
@@ -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_or_update_contact,
Expand All @@ -17,7 +10,7 @@
from ctms.schemas.contact import ContactSchema
from ctms.schemas.newsletter import NewsletterTableSchema
from ctms.schemas.waitlist import WaitlistTableSchema
from tests.unit.conftest import APP_FOLDER, create_full_contact
from tests.unit.conftest import create_full_contact


@pytest.fixture
Expand Down Expand Up @@ -158,91 +151,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"

0 comments on commit be55776

Please sign in to comment.