diff --git a/db_revisions/versions/d6e4a13fbebd_seed_denied_domains_table.py b/db_revisions/versions/d6e4a13fbebd_seed_denied_domains_table.py new file mode 100644 index 0000000..5988fac --- /dev/null +++ b/db_revisions/versions/d6e4a13fbebd_seed_denied_domains_table.py @@ -0,0 +1,189 @@ +"""seed denied domains table + +Revision ID: d6e4a13fbebd +Revises: 0e520c01fb42 +Create Date: 2024-03-22 02:13:50.455432 + +""" + +from typing import Sequence, Union + +from alembic import op +from db_revisions.utils import get_indices_from_collection, get_table_by_name + + +# revision identifiers, used by Alembic. +revision: str = "d6e4a13fbebd" +down_revision: Union[str, None] = "0e520c01fb42" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + +seed_data = [ + {"domain": "aol.com"}, + {"domain": "att.net"}, + {"domain": "comcast.net"}, + {"domain": "facebook.com"}, + {"domain": "gmail.com"}, + {"domain": "gmx.com"}, + {"domain": "googlemail.com"}, + {"domain": "google.com"}, + {"domain": "hotmail.com"}, + {"domain": "hotmail.co.uk"}, + {"domain": "mac.com"}, + {"domain": "me.com"}, + {"domain": "mail.com"}, + {"domain": "msn.com"}, + {"domain": "live.com"}, + {"domain": "sbcglobal.net"}, + {"domain": "verizon.net"}, + {"domain": "yahoo.com"}, + {"domain": "yahoo.co.uk"}, + {"domain": "email.com"}, + {"domain": "fastmail.fm"}, + {"domain": "games.com"}, + {"domain": "gmx.net"}, + {"domain": "hush.com"}, + {"domain": "hushmail.com"}, + {"domain": "icloud.com"}, + {"domain": "iname.com"}, + {"domain": "inbox.com"}, + {"domain": "lavabit.com"}, + {"domain": "love.com"}, + {"domain": "outlook.com"}, + {"domain": "pobox.com"}, + {"domain": "protonmail.ch"}, + {"domain": "protonmail.com"}, + {"domain": "tutanota.de"}, + {"domain": "tutanota.com"}, + {"domain": "tutamail.com"}, + {"domain": "tuta.io"}, + {"domain": "keemail.me"}, + {"domain": "rocketmail.com"}, + {"domain": "safe-mail.net"}, + {"domain": "wow.com,ygm.com"}, + {"domain": "ymail.com"}, + {"domain": "zoho.com"}, + {"domain": "yandex.com"}, + {"domain": "bellsouth.net"}, + {"domain": "charter.net"}, + {"domain": "cox.net"}, + {"domain": "earthlink.net"}, + {"domain": "juno.com"}, + {"domain": "btinternet.com"}, + {"domain": "virginmedia.com"}, + {"domain": "blueyonder.co.uk"}, + {"domain": "freeserve.co.uk"}, + {"domain": "live.co.uk"}, + {"domain": "ntlworld.com"}, + {"domain": "o2.co.uk"}, + {"domain": "orange.net"}, + {"domain": "sky.com"}, + {"domain": "talktalk.co.uk"}, + {"domain": "tiscali.co.uk"}, + {"domain": "virgin.net"}, + {"domain": "wanadoo.co.uk"}, + {"domain": "bt.com"}, + {"domain": "sina.com"}, + {"domain": "sina.cn"}, + {"domain": "qq.com"}, + {"domain": "naver.com"}, + {"domain": "hanmail.net"}, + {"domain": "daum.net"}, + {"domain": "nate.com"}, + {"domain": "yahoo.co.jp"}, + {"domain": "yahoo.co.kr"}, + {"domain": "yahoo.co.id"}, + {"domain": "yahoo.co.in"}, + {"domain": "yahoo.com.sg"}, + {"domain": "yahoo.com.ph"}, + {"domain": "163.com"}, + {"domain": "yeah.net"}, + {"domain": "126.com"}, + {"domain": "21cn.com"}, + {"domain": "aliyun.com"}, + {"domain": "foxmail.com"}, + {"domain": "hotmail.fr"}, + {"domain": "live.fr"}, + {"domain": "laposte.net"}, + {"domain": "yahoo.fr"}, + {"domain": "wanadoo.fr"}, + {"domain": "orange.fr"}, + {"domain": "gmx.fr"}, + {"domain": "sfr.fr"}, + {"domain": "neuf.fr"}, + {"domain": "free.fr"}, + {"domain": "gmx.de"}, + {"domain": "hotmail.de"}, + {"domain": "live.de"}, + {"domain": "online.de"}, + {"domain": "t-online.de"}, + {"domain": "web.de"}, + {"domain": "yahoo.de"}, + {"domain": "libero.it"}, + {"domain": "virgilio.it"}, + {"domain": "hotmail.it"}, + {"domain": "aol.it"}, + {"domain": "tiscali.it"}, + {"domain": "alice.it"}, + {"domain": "live.it"}, + {"domain": "yahoo.it"}, + {"domain": "email.it"}, + {"domain": "tin.it"}, + {"domain": "poste.it"}, + {"domain": "teletu.it"}, + {"domain": "mail.ru"}, + {"domain": "rambler.ru"}, + {"domain": "yandex.ru"}, + {"domain": "ya.ru"}, + {"domain": "list.ru"}, + {"domain": "hotmail.be"}, + {"domain": "live.be"}, + {"domain": "skynet.be"}, + {"domain": "voo.be"}, + {"domain": "tvcablenet.be"}, + {"domain": "telenet.be"}, + {"domain": "hotmail.com.ar"}, + {"domain": "live.com.ar"}, + {"domain": "yahoo.com.ar"}, + {"domain": "fibertel.com.ar"}, + {"domain": "speedy.com.ar"}, + {"domain": "arnet.com.ar"}, + {"domain": "yahoo.com.mx"}, + {"domain": "live.com.mx"}, + {"domain": "hotmail.es"}, + {"domain": "hotmail.com.mx"}, + {"domain": "prodigy.net.mx"}, + {"domain": "yahoo.ca"}, + {"domain": "hotmail.ca"}, + {"domain": "bell.net"}, + {"domain": "shaw.ca"}, + {"domain": "sympatico.ca"}, + {"domain": "rogers.com"}, + {"domain": "yahoo.com.br"}, + {"domain": "hotmail.com.br"}, + {"domain": "outlook.com.br"}, + {"domain": "uol.com.br"}, + {"domain": "bol.com.br"}, + {"domain": "terra.com.br"}, + {"domain": "ig.com.br"}, + {"domain": "itelefonica.com.br"}, + {"domain": "r7.com"}, + {"domain": "zipmail.com.br"}, + {"domain": "globo.com"}, + {"domain": "globomail.com"}, + {"domain": "oi.com.br"}, +] + + +def upgrade() -> None: + table = get_table_by_name("denied_domains") + + op.bulk_insert(table, seed_data) + + +def downgrade() -> None: + table = get_table_by_name("denied_domains") + + domains = get_indices_from_collection(seed_data, "domain") + + op.execute(table.delete().where(table.c.domain.in_(domains))) diff --git a/poetry.lock b/poetry.lock index a489c2f..e28544f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. [[package]] name = "aiosqlite" @@ -1165,17 +1165,17 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "pytest-mock (>=3.12)"] [[package]] name = "pytest-mock" -version = "3.12.0" +version = "3.14.0" description = "Thin-wrapper around the mock package for easier use with pytest" optional = false python-versions = ">=3.8" files = [ - {file = "pytest-mock-3.12.0.tar.gz", hash = "sha256:31a40f038c22cad32287bb43932054451ff5583ff094bca6f675df2f8bc1a6e9"}, - {file = "pytest_mock-3.12.0-py3-none-any.whl", hash = "sha256:0972719a7263072da3a21c7f4773069bcc7486027d7e8e1f81d98a47e701bc4f"}, + {file = "pytest-mock-3.14.0.tar.gz", hash = "sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0"}, + {file = "pytest_mock-3.14.0-py3-none-any.whl", hash = "sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f"}, ] [package.dependencies] -pytest = ">=5.0" +pytest = ">=6.2.5" [package.extras] dev = ["pre-commit", "pytest-asyncio", "tox"] @@ -1240,7 +1240,7 @@ name = "regtech-api-commons" version = "0.1.0" description = "" optional = false -python-versions = "^3.11" +python-versions = "^3.12" files = [] develop = false @@ -1255,7 +1255,7 @@ requests = "^2.31.0" type = "git" url = "https://github.com/cfpb/regtech-api-commons.git" reference = "HEAD" -resolved_reference = "29356c630d2609cb81087ce35dd6c79512954d49" +resolved_reference = "8d98c7e574a6f8290d83f7836dd9d402263d891f" [[package]] name = "requests" diff --git a/tests/migrations/test_lookup_tables_data_seed.py b/tests/migrations/test_lookup_tables_data_seed.py index 90940f1..6baf727 100644 --- a/tests/migrations/test_lookup_tables_data_seed.py +++ b/tests/migrations/test_lookup_tables_data_seed.py @@ -106,3 +106,24 @@ def test_sbl_institution_type_data_seed(alembic_runner: MigrationContext, alembi text("SELECT id, name FROM %s" % sbl_institution_type_tablename) ).fetchall() assert sbl_institution_type_before_seed == [("00", "TestSblInstitutionType")] + + +def test_denied_domains_data_seed(alembic_runner: MigrationContext, alembic_engine: Engine): + # Migrate up to, but not including this new migration + alembic_runner.migrate_up_before("d6e4a13fbebd") + + # Test denied_domains seed + denied_domain_tablename = "denied_domains" + alembic_runner.migrate_up_one() + with alembic_engine.connect() as conn: + denied_domains_rows = conn.execute( + text("SELECT domain from %s where domain = :domain " % denied_domain_tablename), (dict(domain="yahoo.fr")) + ).fetchall() + denied_domains_expected = [("yahoo.fr",)] + + assert denied_domains_rows == denied_domains_expected + + alembic_runner.migrate_down_one() + with alembic_engine.connect() as conn: + denied_domains_before_seed = conn.execute(text("SELECT domain FROM %s" % denied_domain_tablename)).fetchall() + assert denied_domains_before_seed == []