Skip to content

Commit

Permalink
Ticket 131: seed denied domains table
Browse files Browse the repository at this point in the history
  • Loading branch information
Nargis Sultani committed Mar 22, 2024
1 parent 3d846b2 commit d3777c2
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 7 deletions.
189 changes: 189 additions & 0 deletions db_revisions/versions/d6e4a13fbebd_seed_denied_domains_table.py
Original file line number Diff line number Diff line change
@@ -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)))
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/migrations/test_lookup_tables_data_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []

0 comments on commit d3777c2

Please sign in to comment.