Merge pull request #552 from smilerz/main_fork

fixed tests to work in batch mode
This commit is contained in:
vabene1111 2021-04-15 18:43:34 +02:00 committed by GitHub
commit 48f63b4d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 6 deletions

View File

@ -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']}))

View File

@ -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']}))

View File

@ -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", [

View File

@ -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']}))

View File

@ -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", [