fixed a potential bug (#337)

* fixed a potential bug

Signed-off-by: wiseaidev <business@wiseai.dev>

* add unit tests

Signed-off-by: wiseaidev <business@wiseai.dev>

* remove unnecessary logic related to six module

Signed-off-by: wiseaidev <business@wiseai.dev>

* remove six from dependencies

Signed-off-by: wiseaidev <business@wiseai.dev>

* pass "ignore" as a kwarg

Signed-off-by: wiseaidev <business@wiseai.dev>

* get rid of try catch and simplify logic

Signed-off-by: wiseaidev <business@wiseai.dev>

* rm poetry.lock

Signed-off-by: wiseaidev <business@wiseai.dev>

* rm poetry.lock

Signed-off-by: wiseaidev <business@wiseai.dev>

* run black

Signed-off-by: wiseaidev <business@wiseai.dev>

* fix mypy issue

Signed-off-by: wiseaidev <business@wiseai.dev>

* adjust other tests accordingly

Signed-off-by: wiseaidev <business@wiseai.dev>
This commit is contained in:
Mahmoud Harmouch 2022-08-09 17:40:27 +03:00 committed by GitHub
parent b103adbe6d
commit ac6a75be19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 32 deletions

View file

@ -43,6 +43,7 @@ async def m(key_prefix, redis):
created_on: datetime.datetime
class Member(BaseHashModel):
id: int = Field(index=True)
first_name: str = Field(index=True)
last_name: str = Field(index=True)
email: str = Field(index=True)
@ -64,6 +65,7 @@ async def m(key_prefix, redis):
@pytest_asyncio.fixture
async def members(m):
member1 = m.Member(
id=0,
first_name="Andrew",
last_name="Brookins",
email="a@example.com",
@ -73,6 +75,7 @@ async def members(m):
)
member2 = m.Member(
id=1,
first_name="Kim",
last_name="Brookins",
email="k@example.com",
@ -82,6 +85,7 @@ async def members(m):
)
member3 = m.Member(
id=2,
first_name="Andrew",
last_name="Smith",
email="as@example.com",
@ -129,6 +133,9 @@ async def test_exact_match_queries(members, m):
).all()
assert actual == [member2]
actual = await m.Member.find(m.Member.id == 0).all()
assert actual == [member1]
@py_test_mark_asyncio
async def test_full_text_search_queries(members, m):
@ -176,6 +183,7 @@ async def test_tag_queries_boolean_logic(members, m):
@py_test_mark_asyncio
async def test_tag_queries_punctuation(m):
member1 = m.Member(
id=0,
first_name="Andrew, the Michael",
last_name="St. Brookins-on-Pier",
email="a|b@example.com", # NOTE: This string uses the TAG field separator.
@ -186,6 +194,7 @@ async def test_tag_queries_punctuation(m):
await member1.save()
member2 = m.Member(
id=1,
first_name="Bob",
last_name="the Villain",
email="a|villain@example.com", # NOTE: This string uses the TAG field separator.
@ -337,18 +346,19 @@ def test_validates_required_fields(m):
# Raises ValidationError: last_name is required
# TODO: Test the error value
with pytest.raises(ValidationError):
m.Member(first_name="Andrew", zipcode="97086", join_date=today)
m.Member(id=0, first_name="Andrew", zipcode="97086", join_date=today)
def test_validates_field(m):
# Raises ValidationError: join_date is not a date
# TODO: Test the error value
with pytest.raises(ValidationError):
m.Member(first_name="Andrew", last_name="Brookins", join_date="yesterday")
m.Member(id=0, first_name="Andrew", last_name="Brookins", join_date="yesterday")
def test_validation_passes(m):
member = m.Member(
id=0,
first_name="Andrew",
last_name="Brookins",
email="a@example.com",
@ -362,6 +372,7 @@ def test_validation_passes(m):
@py_test_mark_asyncio
async def test_retrieve_first(m):
member = m.Member(
id=0,
first_name="Simon",
last_name="Prickett",
email="s@example.com",
@ -373,6 +384,7 @@ async def test_retrieve_first(m):
await member.save()
member2 = m.Member(
id=1,
first_name="Another",
last_name="Member",
email="m@example.com",
@ -384,6 +396,7 @@ async def test_retrieve_first(m):
await member2.save()
member3 = m.Member(
id=2,
first_name="Third",
last_name="Member",
email="t@example.com",
@ -401,6 +414,7 @@ async def test_retrieve_first(m):
@py_test_mark_asyncio
async def test_saves_model_and_creates_pk(m):
member = m.Member(
id=0,
first_name="Andrew",
last_name="Brookins",
email="a@example.com",
@ -418,6 +432,7 @@ async def test_saves_model_and_creates_pk(m):
@py_test_mark_asyncio
async def test_all_pks(m):
member = m.Member(
id=0,
first_name="Simon",
last_name="Prickett",
email="s@example.com",
@ -429,6 +444,7 @@ async def test_all_pks(m):
await member.save()
member1 = m.Member(
id=1,
first_name="Andrew",
last_name="Brookins",
email="a@example.com",
@ -449,6 +465,7 @@ async def test_all_pks(m):
@py_test_mark_asyncio
async def test_delete(m):
member = m.Member(
id=0,
first_name="Simon",
last_name="Prickett",
email="s@example.com",
@ -465,6 +482,7 @@ async def test_delete(m):
@py_test_mark_asyncio
async def test_expire(m):
member = m.Member(
id=0,
first_name="Expire",
last_name="Test",
email="e@example.com",
@ -529,6 +547,7 @@ def test_raises_error_with_lists(m):
@py_test_mark_asyncio
async def test_saves_many(m):
member1 = m.Member(
id=0,
first_name="Andrew",
last_name="Brookins",
email="a@example.com",
@ -537,6 +556,7 @@ async def test_saves_many(m):
bio="This is the user bio.",
)
member2 = m.Member(
id=1,
first_name="Kim",
last_name="Brookins",
email="k@example.com",