Skip to content

Commit

Permalink
test: replace nicks by Monty Python references
Browse files Browse the repository at this point in the history
As noted by dgw, it's better to replace Sopel's owner/dev/users
nicks by more neutral references to Monty Python characters
and actors.

Is that a dead parrot?
  • Loading branch information
Exirel committed May 13, 2022
1 parent 45dd946 commit d4189c2
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions test/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

TMP_CONFIG = """
[core]
owner = Embolalia
owner = Pepperpots
db_filename = {db_filename}
"""

Expand Down Expand Up @@ -57,15 +57,15 @@ def test_execute(db: SopelDB):

def test_connect(db: SopelDB):
"""Test it's possible to get a raw connection and to use it properly."""
nick_id = db.get_nick_id('Exirel', create=True)
nick_id = db.get_nick_id('MrEricPraline', create=True)
connection = db.connect()

try:
cursor_obj = connection.cursor()
cursor_obj.execute("SELECT nick_id, canonical, slug FROM nicknames")
results = cursor_obj.fetchall()
cursor_obj.close()
assert results == [(nick_id, 'Exirel', 'exirel')]
assert results == [(nick_id, 'MrEricPraline', 'mrericpraline')]
finally:
connection.close()

Expand All @@ -80,7 +80,7 @@ def test_get_uri(db: SopelDB, tmpconfig):

def test_get_nick_id(db: SopelDB):
"""Test get_nick_id does not create NickID by default."""
nick = Identifier('Exirel')
nick = Identifier('MrEricPraline')

# Attempt to get nick ID: it is not created by default
with pytest.raises(ValueError):
Expand All @@ -94,17 +94,17 @@ def test_get_nick_id(db: SopelDB):
nickname = session.execute(
select(Nicknames).where(Nicknames.nick_id == nick_id)
).scalar_one() # will raise if not one and exactly one
assert nickname.canonical == 'Exirel'
assert nickname.canonical == 'MrEricPraline'
assert nickname.slug == nick.lower()


@pytest.mark.parametrize('name, slug, variant', (
# Check case insensitive with ASCII only
('Embolalia', 'embolalia', 'eMBOLALIA'),
('MrEricPraline', 'mrericpraline', 'mRErICPraLINE'),
# Ensures case conversion is handled properly
('[][]', '{}{}', '[}{]'),
# Unicode, just in case
('EmbölaliÅ', 'embölaliÅ', 'EMBöLALIÅ'),
('MrÉrïcPrâliné', 'mrÉrïcprâliné', 'MRÉRïCPRâLINé'),
))
def test_get_nick_id_casemapping(db: SopelDB, name, slug, variant):
"""Test get_nick_id is case-insensitive through an Identifier."""
Expand Down Expand Up @@ -181,8 +181,8 @@ def test_get_nick_id_migration(db: SopelDB):


def test_alias_nick(db: SopelDB):
nick = 'Embolalia'
aliases = ['EmbölaliÅ', 'Embo`work', 'Embo']
nick = 'MrEricPraline'
aliases = ['MrÉrïcPrâliné', 'John`Cleese', 'DeadParrot']

nick_id = db.get_nick_id(nick, create=True)
for alias in aliases:
Expand All @@ -207,34 +207,34 @@ def test_alias_nick(db: SopelDB):
['structured', 'value'],
))
def test_set_nick_value(db: SopelDB, value):
nick = 'TestNick'
nick = 'Pepperpots'
db.set_nick_value(nick, 'testkey', value)
assert db.get_nick_value(nick, 'testkey') == value, (
'The value retrieved must be exactly what was stored.')


def test_set_nick_value_update(db: SopelDB):
"""Test set_nick_value can update an existing value."""
db.set_nick_value('TestNick', 'testkey', 'first-value')
db.set_nick_value('TestNick', 'otherkey', 'other-value')
db.set_nick_value('OtherNick', 'testkey', 'other-nick-value')
db.set_nick_value('Pepperpots', 'testkey', 'first-value')
db.set_nick_value('Pepperpots', 'otherkey', 'other-value')
db.set_nick_value('Vikings', 'testkey', 'other-nick-value')

# sanity check: ensure every (nick, key, value) is correct
assert db.get_nick_value('TestNick', 'testkey') == 'first-value'
assert db.get_nick_value('TestNick', 'otherkey') == 'other-value'
assert db.get_nick_value('OtherNick', 'testkey') == 'other-nick-value'
assert db.get_nick_value('Pepperpots', 'testkey') == 'first-value'
assert db.get_nick_value('Pepperpots', 'otherkey') == 'other-value'
assert db.get_nick_value('Vikings', 'testkey') == 'other-nick-value'

# update only one key
db.set_nick_value('TestNick', 'testkey', 'new-value')
db.set_nick_value('Pepperpots', 'testkey', 'new-value')

# check new value while old values are still the same
assert db.get_nick_value('TestNick', 'testkey') == 'new-value'
assert db.get_nick_value('TestNick', 'otherkey') == 'other-value'
assert db.get_nick_value('OtherNick', 'testkey') == 'other-nick-value'
assert db.get_nick_value('Pepperpots', 'testkey') == 'new-value'
assert db.get_nick_value('Pepperpots', 'otherkey') == 'other-value'
assert db.get_nick_value('Vikings', 'testkey') == 'other-nick-value'


def test_delete_nick_value(db: SopelDB):
nick = 'TestUser'
nick = 'TerryGilliam'
db.set_nick_value(nick, 'testkey', 'test-value')

# sanity check
Expand All @@ -248,7 +248,7 @@ def test_delete_nick_value(db: SopelDB):

def test_delete_nick_value_none(db: SopelDB):
"""Test method doesn't raise an error when there is nothing to delete."""
nick = 'TestUser'
nick = 'TerryGilliam'

# this user doesn't even exist
db.delete_nick_value(nick, 'testkey')
Expand All @@ -275,7 +275,7 @@ def test_delete_nick_value_none(db: SopelDB):
['structured', 'value'],
))
def test_get_nick_value(db: SopelDB, value):
nick = 'TestUser'
nick = 'TerryGilliam'
nick_id = db.get_nick_id(nick, create=True)

with db.session() as session:
Expand All @@ -290,12 +290,12 @@ def test_get_nick_value(db: SopelDB, value):
assert db.get_nick_value(nick, 'testkey') == value
assert db.get_nick_value(nick, 'otherkey') is None
assert db.get_nick_value('NotTestUser', 'testkey') is None, (
'This key must be defined for TestUser only.')
'This key must be defined for TerryGilliam only.')


def test_get_nick_value_default(db: SopelDB):
assert db.get_nick_value("TestUser", "nokey") is None
assert db.get_nick_value("TestUser", "nokey", "default") == "default"
assert db.get_nick_value("TerryGilliam", "nokey") is None
assert db.get_nick_value("TerryGilliam", "nokey", "default") == "default"


def test_unalias_nick(db: SopelDB):
Expand Down Expand Up @@ -336,20 +336,20 @@ def test_unalias_nick(db: SopelDB):

def test_unalias_nick_one_or_none(db: SopelDB):
# this will create the first version of the nick
db.get_nick_id('Exirel', create=True)
db.get_nick_id('MrEricPraline', create=True)

# assert you can't unalias a unique nick
with pytest.raises(ValueError):
db.unalias_nick('Exirel')
db.unalias_nick('MrEricPraline')

# and you can't either with a non-existing nick
with pytest.raises(ValueError):
db.unalias_nick('xnaas')
db.unalias_nick('gumbys')


def test_forget_nick_group(db: SopelDB):
session = db.ssession()
aliases = ['Embolalia', 'Embo']
aliases = ['MrEricPraline', 'Praline']
nick_id = 42
for alias in aliases:
nn = Nicknames(nick_id=nick_id, slug=Identifier(alias).lower(), canonical=alias)
Expand All @@ -374,7 +374,7 @@ def test_forget_nick_group(db: SopelDB):

def test_merge_nick_groups(db: SopelDB):
session = db.ssession()
aliases = ['Embolalia', 'Embo']
aliases = ['MrEricPraline', 'Praline']
for nick_id, alias in enumerate(aliases):
nn = Nicknames(nick_id=nick_id, slug=Identifier(alias).lower(), canonical=alias)
session.add(nn)
Expand Down

0 comments on commit d4189c2

Please sign in to comment.