diff --git a/cookbook/tests/api/test_api_ingredient.py b/cookbook/tests/api/test_api_ingredient.py index 2fbacbed3..061994914 100644 --- a/cookbook/tests/api/test_api_ingredient.py +++ b/cookbook/tests/api/test_api_ingredient.py @@ -4,7 +4,7 @@ import pytest from django.urls import reverse from django_scopes import scopes_disabled -from cookbook.models import Food, Ingredient +from cookbook.models import Ingredient LIST_URL = 'api:ingredient-list' DETAIL_URL = 'api:ingredient-detail' @@ -77,7 +77,8 @@ def test_add(arg, request, u1_s2): print(r) assert r.status_code == arg[1] if r.status_code == 201: - assert response['id'] == 1 + # id can change when running multiple tests - changed to look at the name of the food + assert response['food']['name'] == 'test' r = c.get(reverse(DETAIL_URL, args={response['id']})) assert r.status_code == 404 # ingredient is not linked to a recipe and therefore cannot be accessed r = u1_s2.get(reverse(DETAIL_URL, args={response['id']})) diff --git a/cookbook/tests/api/test_api_recipe.py b/cookbook/tests/api/test_api_recipe.py index c1b103ca6..7506d8ef4 100644 --- a/cookbook/tests/api/test_api_recipe.py +++ b/cookbook/tests/api/test_api_recipe.py @@ -76,7 +76,8 @@ def test_add(arg, request, u1_s2): print(r.content) assert r.status_code == arg[1] if r.status_code == 201: - assert response['id'] == 1 + # id can change when running multiple tests, changed to validate name + assert response['name'] == 'test' r = c.get(reverse(DETAIL_URL, args={response['id']})) assert r.status_code == 200 r = u1_s2.get(reverse(DETAIL_URL, args={response['id']})) diff --git a/cookbook/tests/api/test_api_recipe_book.py b/cookbook/tests/api/test_api_recipe_book.py index 3c5f4726a..3d5513298 100644 --- a/cookbook/tests/api/test_api_recipe_book.py +++ b/cookbook/tests/api/test_api_recipe_book.py @@ -48,7 +48,8 @@ def test_list_filter(obj_1, obj_2, u1_s1): assert r.status_code == 200 response = json.loads(r.content) assert len(response) == 2 - assert response[0]['name'] == obj_1.name + # RecipeBooks model is unsorted - this isn't a reliable test + # assert response[0]['name'] == obj_1.name response = json.loads(u1_s1.get(f'{reverse(LIST_URL)}?limit=1').content) assert len(response) == 1 @@ -58,6 +59,7 @@ def test_list_filter(obj_1, obj_2, u1_s1): response = json.loads(u1_s1.get(f'{reverse(LIST_URL)}?query={obj_1.name[4:]}').content) assert len(response) == 1 + assert response[0]['name'] == obj_1.name @pytest.mark.parametrize("arg", [ diff --git a/cookbook/tests/api/test_api_step.py b/cookbook/tests/api/test_api_step.py index 8d01a0ea9..e1f211e5c 100644 --- a/cookbook/tests/api/test_api_step.py +++ b/cookbook/tests/api/test_api_step.py @@ -77,7 +77,8 @@ def test_add(arg, request, u1_s2): print(r.content) assert r.status_code == arg[1] if r.status_code == 201: - assert response['id'] == 1 + # ids can change when running multiple tests - changed assert to instruction + assert response['instruction'] == 'test' r = c.get(reverse(DETAIL_URL, args={response['id']})) assert r.status_code == 404 # ingredient is not linked to a recipe and therefore cannot be accessed r = u1_s2.get(reverse(DETAIL_URL, args={response['id']})) diff --git a/cookbook/tests/api/test_api_unit.py b/cookbook/tests/api/test_api_unit.py index f0a131ed4..2a97a39b3 100644 --- a/cookbook/tests/api/test_api_unit.py +++ b/cookbook/tests/api/test_api_unit.py @@ -47,7 +47,8 @@ def test_list_filter(obj_1, obj_2, u1_s1): assert r.status_code == 200 response = json.loads(r.content) assert len(response) == 2 - assert response[0]['name'] == obj_1.name + # unit model isn't sorted - this isn't a stable test + # assert response[0]['name'] == obj_1.name response = json.loads(u1_s1.get(f'{reverse(LIST_URL)}?limit=1').content) assert len(response) == 1 @@ -57,6 +58,7 @@ def test_list_filter(obj_1, obj_2, u1_s1): response = json.loads(u1_s1.get(f'{reverse(LIST_URL)}?query={obj_1.name[4:]}').content) assert len(response) == 1 + assert response[0]['name'] == obj_1.name @pytest.mark.parametrize("arg", [