From 92849d8396fbb23077416b7b55bea9acd0fba05f Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 29 May 2021 16:53:27 -0700 Subject: [PATCH] Shorten superfluous names --- amanuensis/backend/lexicon.py | 2 +- amanuensis/backend/user.py | 2 +- tests/test_lexicon.py | 16 ++++++++-------- tests/test_user.py | 14 +++++++------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/amanuensis/backend/lexicon.py b/amanuensis/backend/lexicon.py index 089b8e3..187d50f 100644 --- a/amanuensis/backend/lexicon.py +++ b/amanuensis/backend/lexicon.py @@ -13,7 +13,7 @@ from amanuensis.errors import ArgumentError RE_ALPHANUM_DASH_UNDER = re.compile(r'^[A-Za-z0-9-_]*$') -def create_lexicon( +def create( db: DbContext, name: str, title: str, diff --git a/amanuensis/backend/user.py b/amanuensis/backend/user.py index 66b0e98..aa3df6d 100644 --- a/amanuensis/backend/user.py +++ b/amanuensis/backend/user.py @@ -15,7 +15,7 @@ RE_NO_LETTERS = re.compile(r'^[0-9-_]*$') RE_ALPHANUM_DASH_UNDER = re.compile(r'^[A-Za-z0-9-_]*$') -def create_user( +def create( db: DbContext, username: str, password: str, diff --git a/tests/test_lexicon.py b/tests/test_lexicon.py index 15c46c5..963c6c5 100644 --- a/tests/test_lexicon.py +++ b/tests/test_lexicon.py @@ -18,21 +18,21 @@ def test_create_lexicon(db): } # Test name constraints with pytest.raises(ArgumentError): - lexiq.create_lexicon(db, **{**kwargs, 'name': None}) + lexiq.create(db, **{**kwargs, 'name': None}) with pytest.raises(ArgumentError): - lexiq.create_lexicon(db, **{**kwargs, 'name': ''}) + lexiq.create(db, **{**kwargs, 'name': ''}) with pytest.raises(ArgumentError): - lexiq.create_lexicon(db, **{**kwargs, 'name': ' '}) + lexiq.create(db, **{**kwargs, 'name': ' '}) with pytest.raises(ArgumentError): - lexiq.create_lexicon(db, **{**kwargs, 'name': '..'}) + lexiq.create(db, **{**kwargs, 'name': '..'}) with pytest.raises(ArgumentError): - lexiq.create_lexicon(db, **{**kwargs, 'name': '\x00'}) + lexiq.create(db, **{**kwargs, 'name': '\x00'}) with pytest.raises(ArgumentError): - lexiq.create_lexicon(db, **{**kwargs, 'name': 'space in name'}) + lexiq.create(db, **{**kwargs, 'name': 'space in name'}) # Validate that creation populates fields, including timestamps before = datetime.datetime.utcnow() - datetime.timedelta(seconds=1) - new_lexicon = lexiq.create_lexicon(db, **kwargs) + new_lexicon = lexiq.create(db, **kwargs) after = datetime.datetime.utcnow() + datetime.timedelta(seconds=1) assert new_lexicon assert new_lexicon.id is not None @@ -42,4 +42,4 @@ def test_create_lexicon(db): # No duplicate lexicon names with pytest.raises(ArgumentError): - duplicate = lexiq.create_lexicon(db, **kwargs) + duplicate = lexiq.create(db, **kwargs) diff --git a/tests/test_user.py b/tests/test_user.py index 8c2b9c3..dc51173 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -27,27 +27,27 @@ def test_create_user(db): # Test length constraints with pytest.raises(ArgumentError): - userq.create_user(db, **{**kwargs, 'username': 'me'}) + userq.create(db, **{**kwargs, 'username': 'me'}) with pytest.raises(ArgumentError): - userq.create_user(db, **{**kwargs, 'username': 'the right honorable user-name, esquire'}) + userq.create(db, **{**kwargs, 'username': 'the right honorable user-name, esquire'}) # Test allowed characters with pytest.raises(ArgumentError): - userq.create_user(db, **{**kwargs, 'username': 'user name'}) + userq.create(db, **{**kwargs, 'username': 'user name'}) # No password with pytest.raises(ArgumentError): - userq.create_user(db, **{**kwargs, 'password': None}) + userq.create(db, **{**kwargs, 'password': None}) # Valid creation works and populates fields - new_user = userq.create_user(db, **kwargs) + new_user = userq.create(db, **kwargs) assert new_user assert new_user.id is not None assert new_user.created is not None # No duplicate usernames with pytest.raises(ArgumentError): - duplicate = userq.create_user(db, **kwargs) + duplicate = userq.create(db, **kwargs) # Missing display name populates with username user2_kw = {**kwargs, 'username': 'user2', 'display_name': None} - user2 = userq.create_user(db, **user2_kw) + user2 = userq.create(db, **user2_kw) assert user2.display_name is not None