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..d965c15 --- /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": "126.com"}, + {"domain": "163.com"}, + {"domain": "21cn.com"}, + {"domain": "alice.it"}, + {"domain": "aliyun.com"}, + {"domain": "aol.com"}, + {"domain": "aol.it"}, + {"domain": "arnet.com.ar"}, + {"domain": "att.net"}, + {"domain": "bell.net"}, + {"domain": "bellsouth.net"}, + {"domain": "blueyonder.co.uk"}, + {"domain": "bol.com.br"}, + {"domain": "bt.com"}, + {"domain": "btinternet.com"}, + {"domain": "charter.net"}, + {"domain": "comcast.net"}, + {"domain": "cox.net"}, + {"domain": "daum.net"}, + {"domain": "earthlink.net"}, + {"domain": "email.com"}, + {"domain": "email.it"}, + {"domain": "facebook.com"}, + {"domain": "fastmail.fm"}, + {"domain": "fibertel.com.ar"}, + {"domain": "foxmail.com"}, + {"domain": "free.fr"}, + {"domain": "freeserve.co.uk"}, + {"domain": "games.com"}, + {"domain": "globo.com"}, + {"domain": "globomail.com"}, + {"domain": "gmail.com"}, + {"domain": "gmx.com"}, + {"domain": "gmx.de"}, + {"domain": "gmx.fr"}, + {"domain": "gmx.net"}, + {"domain": "google.com"}, + {"domain": "googlemail.com"}, + {"domain": "hanmail.net"}, + {"domain": "hotmail.be"}, + {"domain": "hotmail.ca"}, + {"domain": "hotmail.co.uk"}, + {"domain": "hotmail.com.ar"}, + {"domain": "hotmail.com.br"}, + {"domain": "hotmail.com.mx"}, + {"domain": "hotmail.com"}, + {"domain": "hotmail.de"}, + {"domain": "hotmail.es"}, + {"domain": "hotmail.fr"}, + {"domain": "hotmail.it"}, + {"domain": "hush.com"}, + {"domain": "hushmail.com"}, + {"domain": "icloud.com"}, + {"domain": "ig.com.br"}, + {"domain": "iname.com"}, + {"domain": "inbox.com"}, + {"domain": "itelefonica.com.br"}, + {"domain": "juno.com"}, + {"domain": "keemail.me"}, + {"domain": "laposte.net"}, + {"domain": "lavabit.com"}, + {"domain": "libero.it"}, + {"domain": "list.ru"}, + {"domain": "live.be"}, + {"domain": "live.co.uk"}, + {"domain": "live.com.ar"}, + {"domain": "live.com.mx"}, + {"domain": "live.com"}, + {"domain": "live.de"}, + {"domain": "live.fr"}, + {"domain": "live.it"}, + {"domain": "love.com"}, + {"domain": "mac.com"}, + {"domain": "mail.com"}, + {"domain": "mail.ru"}, + {"domain": "me.com"}, + {"domain": "msn.com"}, + {"domain": "nate.com"}, + {"domain": "naver.com"}, + {"domain": "neuf.fr"}, + {"domain": "ntlworld.com"}, + {"domain": "o2.co.uk"}, + {"domain": "oi.com.br"}, + {"domain": "online.de"}, + {"domain": "orange.fr"}, + {"domain": "orange.net"}, + {"domain": "outlook.com.br"}, + {"domain": "outlook.com"}, + {"domain": "pobox.com"}, + {"domain": "poste.it"}, + {"domain": "prodigy.net.mx"}, + {"domain": "protonmail.ch"}, + {"domain": "protonmail.com"}, + {"domain": "qq.com"}, + {"domain": "r7.com"}, + {"domain": "rambler.ru"}, + {"domain": "rocketmail.com"}, + {"domain": "rogers.com"}, + {"domain": "safe-mail.net"}, + {"domain": "sbcglobal.net"}, + {"domain": "sfr.fr"}, + {"domain": "shaw.ca"}, + {"domain": "sina.cn"}, + {"domain": "sina.com"}, + {"domain": "sky.com"}, + {"domain": "skynet.be"}, + {"domain": "speedy.com.ar"}, + {"domain": "sympatico.ca"}, + {"domain": "t-online.de"}, + {"domain": "talktalk.co.uk"}, + {"domain": "telenet.be"}, + {"domain": "teletu.it"}, + {"domain": "terra.com.br"}, + {"domain": "tin.it"}, + {"domain": "tiscali.co.uk"}, + {"domain": "tiscali.it"}, + {"domain": "tuta.io"}, + {"domain": "tutamail.com"}, + {"domain": "tutanota.com"}, + {"domain": "tutanota.de"}, + {"domain": "tvcablenet.be"}, + {"domain": "uol.com.br"}, + {"domain": "verizon.net"}, + {"domain": "virgilio.it"}, + {"domain": "virgin.net"}, + {"domain": "virginmedia.com"}, + {"domain": "voo.be"}, + {"domain": "wanadoo.co.uk"}, + {"domain": "wanadoo.fr"}, + {"domain": "web.de"}, + {"domain": "wow.com,ygm.com"}, + {"domain": "ya.ru"}, + {"domain": "yahoo.ca"}, + {"domain": "yahoo.co.id"}, + {"domain": "yahoo.co.in"}, + {"domain": "yahoo.co.jp"}, + {"domain": "yahoo.co.kr"}, + {"domain": "yahoo.co.uk"}, + {"domain": "yahoo.com.ar"}, + {"domain": "yahoo.com.br"}, + {"domain": "yahoo.com.mx"}, + {"domain": "yahoo.com.ph"}, + {"domain": "yahoo.com.sg"}, + {"domain": "yahoo.com"}, + {"domain": "yahoo.de"}, + {"domain": "yahoo.fr"}, + {"domain": "yahoo.it"}, + {"domain": "yandex.com"}, + {"domain": "yandex.ru"}, + {"domain": "yeah.net"}, + {"domain": "ymail.com"}, + {"domain": "zipmail.com.br"}, + {"domain": "zoho.com"}, +] + + +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..753ffff 100644 --- a/tests/migrations/test_lookup_tables_data_seed.py +++ b/tests/migrations/test_lookup_tables_data_seed.py @@ -106,3 +106,177 @@ 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") + + denied_domains_inserted = [ + ("126.com"), + ("163.com"), + ("21cn.com"), + ("alice.it"), + ("aliyun.com"), + ("aol.com"), + ("aol.it"), + ("arnet.com.ar"), + ("att.net"), + ("bell.net"), + ("bellsouth.net"), + ("blueyonder.co.uk"), + ("bol.com.br"), + ("bt.com"), + ("btinternet.com"), + ("charter.net"), + ("comcast.net"), + ("cox.net"), + ("daum.net"), + ("earthlink.net"), + ("email.com"), + ("email.it"), + ("facebook.com"), + ("fastmail.fm"), + ("fibertel.com.ar"), + ("foxmail.com"), + ("free.fr"), + ("freeserve.co.uk"), + ("games.com"), + ("globo.com"), + ("globomail.com"), + ("gmail.com"), + ("gmx.com"), + ("gmx.de"), + ("gmx.fr"), + ("gmx.net"), + ("google.com"), + ("googlemail.com"), + ("hanmail.net"), + ("hotmail.be"), + ("hotmail.ca"), + ("hotmail.co.uk"), + ("hotmail.com.ar"), + ("hotmail.com.br"), + ("hotmail.com.mx"), + ("hotmail.com"), + ("hotmail.de"), + ("hotmail.es"), + ("hotmail.fr"), + ("hotmail.it"), + ("hush.com"), + ("hushmail.com"), + ("icloud.com"), + ("ig.com.br"), + ("iname.com"), + ("inbox.com"), + ("itelefonica.com.br"), + ("juno.com"), + ("keemail.me"), + ("laposte.net"), + ("lavabit.com"), + ("libero.it"), + ("list.ru"), + ("live.be"), + ("live.co.uk"), + ("live.com.ar"), + ("live.com.mx"), + ("live.com"), + ("live.de"), + ("live.fr"), + ("live.it"), + ("love.com"), + ("mac.com"), + ("mail.com"), + ("mail.ru"), + ("me.com"), + ("msn.com"), + ("nate.com"), + ("naver.com"), + ("neuf.fr"), + ("ntlworld.com"), + ("o2.co.uk"), + ("oi.com.br"), + ("online.de"), + ("orange.fr"), + ("orange.net"), + ("outlook.com.br"), + ("outlook.com"), + ("pobox.com"), + ("poste.it"), + ("prodigy.net.mx"), + ("protonmail.ch"), + ("protonmail.com"), + ("qq.com"), + ("r7.com"), + ("rambler.ru"), + ("rocketmail.com"), + ("rogers.com"), + ("safe-mail.net"), + ("sbcglobal.net"), + ("sfr.fr"), + ("shaw.ca"), + ("sina.cn"), + ("sina.com"), + ("sky.com"), + ("skynet.be"), + ("speedy.com.ar"), + ("sympatico.ca"), + ("t-online.de"), + ("talktalk.co.uk"), + ("telenet.be"), + ("teletu.it"), + ("terra.com.br"), + ("tin.it"), + ("tiscali.co.uk"), + ("tiscali.it"), + ("tuta.io"), + ("tutamail.com"), + ("tutanota.com"), + ("tutanota.de"), + ("tvcablenet.be"), + ("uol.com.br"), + ("verizon.net"), + ("virgilio.it"), + ("virgin.net"), + ("virginmedia.com"), + ("voo.be"), + ("wanadoo.co.uk"), + ("wanadoo.fr"), + ("web.de"), + ("wow.com,ygm.com"), + ("ya.ru"), + ("yahoo.ca"), + ("yahoo.co.id"), + ("yahoo.co.in"), + ("yahoo.co.jp"), + ("yahoo.co.kr"), + ("yahoo.co.uk"), + ("yahoo.com.ar"), + ("yahoo.com.br"), + ("yahoo.com.mx"), + ("yahoo.com.ph"), + ("yahoo.com.sg"), + ("yahoo.com"), + ("yahoo.de"), + ("yahoo.fr"), + ("yahoo.it"), + ("yandex.com"), + ("yandex.ru"), + ("yeah.net"), + ("ymail.com"), + ("zipmail.com.br"), + ("zoho.com"), + ] + + # 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 * FROM %s" % denied_domain_tablename)).fetchall() + + assert [elem[0] for elem in denied_domains_rows] == denied_domains_inserted + + 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 == []