1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 13:35:23 +02:00

feat: add unit abbreviation support (#1332)

* add 'use-abbreviation' db column

* type generation

* add view and edit elements

* check for use_abbreviation to display

* fix: alembic version check

* test: add use_abbreviation prop tests
This commit is contained in:
Hayden 2022-06-01 11:59:50 -08:00 committed by GitHub
parent 592b1de39d
commit 52fbf6b833
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 77 additions and 9 deletions

View file

@ -9,17 +9,19 @@ from tests.utils.fixture_schemas import TestUser
class Routes:
base = "/api/units"
@staticmethod
def item(item_id: int) -> str:
return f"{Routes.base}/{item_id}"
@pytest.fixture(scope="function")
def unit(api_client: TestClient, unique_user: TestUser) -> dict:
def unit(api_client: TestClient, unique_user: TestUser):
data = CreateIngredientUnit(
name=random_string(10),
description=random_string(10),
fraction=random_bool(),
abbreviation=random_string(3) + ".",
abbreviation=f"{random_string(3)}.",
use_abbreviation=random_bool(),
).dict(by_alias=True)
response = api_client.post(Routes.base, json=data, headers=unique_user.token)
@ -52,6 +54,7 @@ def test_read_unit(api_client: TestClient, unit: dict, unique_user: TestUser):
assert as_json["description"] == unit["description"]
assert as_json["fraction"] == unit["fraction"]
assert as_json["abbreviation"] == unit["abbreviation"]
assert as_json["useAbbreviation"] == unit["useAbbreviation"]
def test_update_unit(api_client: TestClient, unit: dict, unique_user: TestUser):
@ -60,8 +63,10 @@ def test_update_unit(api_client: TestClient, unit: dict, unique_user: TestUser):
"name": random_string(10),
"description": random_string(10),
"fraction": not unit["fraction"],
"abbreviation": random_string(3) + ".",
"abbreviation": f"{random_string(3)}.",
"useAbbreviation": not unit["useAbbreviation"],
}
response = api_client.put(Routes.item(unit["id"]), json=update_data, headers=unique_user.token)
assert response.status_code == 200
as_json = response.json()
@ -71,14 +76,15 @@ def test_update_unit(api_client: TestClient, unit: dict, unique_user: TestUser):
assert as_json["description"] == update_data["description"]
assert as_json["fraction"] == update_data["fraction"]
assert as_json["abbreviation"] == update_data["abbreviation"]
assert as_json["useAbbreviation"] == update_data["useAbbreviation"]
def test_delete_unit(api_client: TestClient, unit: dict, unique_user: TestUser):
id = unit["id"]
item_id = unit["id"]
response = api_client.delete(Routes.item(id), headers=unique_user.token)
response = api_client.delete(Routes.item(item_id), headers=unique_user.token)
assert response.status_code == 200
response = api_client.get(Routes.item(id), headers=unique_user.token)
response = api_client.get(Routes.item(item_id), headers=unique_user.token)
assert response.status_code == 404