Skip to content

Commit

Permalink
Fix test to match new error format in HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehor Komarov committed Apr 29, 2024
1 parent 649f83a commit 3a637f5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 50 deletions.
4 changes: 2 additions & 2 deletions tests/mongoengine/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def test_render_create(self, client, user_session, expected_value):
"/admin/post/create", cookies={"session": user_session}
)
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down Expand Up @@ -104,7 +104,7 @@ async def test_render_edit(self, client, user_session, expected_value):
f"/admin/post/edit/{post.id}", cookies={"session": user_session}
)
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down
10 changes: 2 additions & 8 deletions tests/mongoengine/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ def test_create_validation_error(self, client):
},
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">String value is too short</div>'
in response.text
)
assert 'class="invalid-feedback">String value is too short' in response.text
assert Product.objects.count() == 5
with pytest.raises(me.DoesNotExist):
Product.objects(brand="Infinix").get()
Expand Down Expand Up @@ -264,10 +261,7 @@ def test_edit_validation_error(self, client):
},
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">String value is too short</div>'
in response.text
)
assert 'class="invalid-feedback">String value is too short' in response.text
assert Product.objects.count() == 5
with pytest.raises(me.DoesNotExist):
Product.objects(brand="Infinix").get()
Expand Down
4 changes: 2 additions & 2 deletions tests/odmantic/test_async_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async def test_create_validation_error(client: AsyncClient, aio_engine: AIOEngin
},
follow_redirects=False,
)
assert response.text.count('<div class="invalid-feedback">') == 3
assert response.text.count('class="invalid-feedback">') == 3
assert response.text.count("ensure this value has at least 3 characters") == 1
assert response.text.count("ensure this value has at least 5 characters") == 1
assert response.text.count("ensure this value has at most 10 characters") == 1
Expand Down Expand Up @@ -264,7 +264,7 @@ async def test_edit_validation_error(client: AsyncClient, aio_engine: AIOEngine)
},
follow_redirects=False,
)
assert response.text.count('<div class="invalid-feedback">') == 3
assert response.text.count('class="invalid-feedback">') == 3
assert response.text.count("ensure this value has at least 3 characters") == 1
assert response.text.count("ensure this value has at least 5 characters") == 1
assert response.text.count("ensure this value has at most 10 characters") == 1
Expand Down
4 changes: 2 additions & 2 deletions tests/odmantic/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def test_render_create(self, client, user_session, expected_value):
"/admin/post/create", cookies={"session": user_session}
)
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down Expand Up @@ -102,7 +102,7 @@ async def test_render_edit(
f"/admin/post/edit/{post.id}", cookies={"session": user_session}
)
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/sqla/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def test_render_create(self, client, user_session, expected_value):
"/admin/post/create", cookies={"session": user_session}
)
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down Expand Up @@ -114,7 +114,7 @@ async def test_render_edit(self, client, session, user_session, expected_value):
"/admin/post/edit/1", cookies={"session": user_session}
)
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down
28 changes: 13 additions & 15 deletions tests/sqla/test_sqla_and_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ async def test_create_validation_error(client: AsyncClient, session: Session):
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">ensure this value has at least 10'
" characters</div>" in response.text
or '<div class="invalid-feedback">String should have at least 10' # pydantic v2
" characters</div>" in response.text
'class="invalid-feedback">ensure this value has at least 10 characters'
in response.text
or 'class="invalid-feedback">String should have at least 10 characters'
in response.text # pydantic v2
)
assert (
'<div class="invalid-feedback">none is not an allowed value</div>'
in response.text
or '<div class="invalid-feedback">Input should be a valid datetime</div>' # pydantic v2
'class="invalid-feedback">none is not an allowed value' in response.text
or 'class="invalid-feedback">Input should be a valid datetime' # pydantic v2
in response.text
)

Expand Down Expand Up @@ -180,16 +179,15 @@ async def test_edit_validation_error(client: AsyncClient, session: Session):
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">ensure this value has at least 10'
" characters</div>" in response.text
or '<div class="invalid-feedback">String should have at least 10' # pydantic v2
" characters</div>" in response.text
'class="invalid-feedback">ensure this value has at least 10 characters'
in response.text
or 'class="invalid-feedback">String should have at least 10 characters'
in response.text # pydantic v2
)
assert (
'<div class="invalid-feedback">none is not an allowed value</div>'
in response.text
or '<div class="invalid-feedback">Input should be a valid datetime</div>' # pydantic v2
in response.text
'class="invalid-feedback">none is not an allowed value' in response.text
or 'class="invalid-feedback">Input should be a valid datetime'
in response.text # pydantic v2
)


Expand Down
26 changes: 12 additions & 14 deletions tests/sqla/test_sqlmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ async def test_create_validation_error(client: AsyncClient, session: Session):
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">ensure this value has at least 10'
" characters</div>" in response.text
or '<div class="invalid-feedback">String should have at least 10' # pydantic v2
" characters</div>" in response.text
'class="invalid-feedback">ensure this value has at least 10 characters'
in response.text
or 'class="invalid-feedback">String should have at least 10 characters'
in response.text # pydantic v2
)
assert (
'<div class="invalid-feedback">none is not an allowed value</div>'
in response.text
or '<div class="invalid-feedback">Input should be a valid datetime</div>' # pydantic v2
'class="invalid-feedback">none is not an allowed value' in response.text
or 'class="invalid-feedback">Input should be a valid datetime' # pydantic v2
in response.text
)

Expand Down Expand Up @@ -145,15 +144,14 @@ async def test_edit_validation_error(client: AsyncClient, session: Session):
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">ensure this value has at least 10'
" characters</div>" in response.text
or '<div class="invalid-feedback">String should have at least 10' # pydantic v2
" characters</div>" in response.text
'class="invalid-feedback">ensure this value has at least 10 characters'
in response.text
or 'class="invalid-feedback">String should have at least 10 characters'
in response.text # pydantic v2
)
assert (
'<div class="invalid-feedback">none is not an allowed value</div>'
in response.text
or '<div class="invalid-feedback">Input should be a valid datetime</div>' # pydantic v2
'class="invalid-feedback">none is not an allowed value' in response.text
or 'class="invalid-feedback">Input should be a valid datetime' # pydantic v2
in response.text
)

Expand Down
4 changes: 1 addition & 3 deletions tests/sqla/test_sync_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,7 @@ async def test_file_validation_error(client: AsyncClient, fake_invalid_image):
files={"image": ("image.png", fake_invalid_image, "image/png")},
)
assert response.status_code == 422
assert (
'<div class="invalid-feedback">Provide valid image file</div>' in response.text
)
assert 'class="invalid-feedback">Provide valid image file' in response.text


async def test_create_with_empty_file(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def client(self):
async def test_render_create(self, client, session, expected_value):
response = await client.get("/admin/post/create", cookies={"session": session})
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down Expand Up @@ -367,7 +367,7 @@ async def test_create(self, client, session, expected_value):
async def test_render_edit(self, client, session, expected_value):
response = await client.get("/admin/post/edit/1", cookies={"session": session})
assert response.status_code == 200
assert response.text.count('name="super_admin_only_field"') == expected_value
assert response.text.count(' name="super_admin_only_field"') == expected_value

@pytest.mark.asyncio
@pytest.mark.parametrize(
Expand Down

0 comments on commit 3a637f5

Please sign in to comment.