Skip to content

Commit

Permalink
To make tests of each step clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
willianantunes committed Mar 7, 2019
1 parent aac1ad3 commit d8eafca
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 65 deletions.
66 changes: 1 addition & 65 deletions api/tests/integration/graphql/test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,14 @@
from graphene.test import Client

from api.graphql.schema import schema
from api.models import Category, Ingredient
from api.models import Category


@pytest.fixture
def client():
return Client(schema)


@pytest.fixture
def prepare_db():
fake_category_name = "fake-category-name"
fake_category = Category.objects.create(name=fake_category_name)
fake_ingredient_notes = "fake_ingredient_notes"
fake_ingredient_name = "fake_ingredient_name"
Ingredient.objects.create(name=fake_ingredient_name, notes=fake_ingredient_notes, category=fake_category)


@pytest.mark.django_db
def test_should_retrieve_all_categories(client, prepare_db):
query = """
query {
allCategories{
id
name
ingredients {
id
name
notes
}
}
}
"""
executed = client.execute(query)

assert len(executed["data"]["allCategories"]) == 1
created_category = executed["data"]["allCategories"][0]
assert created_category["id"] == "1"
assert created_category["name"] == "fake-category-name"
assert len(created_category["ingredients"]) == 1
created_ingredient = created_category["ingredients"][0]
assert created_ingredient["id"] == "1"
assert created_ingredient["name"] == "fake_ingredient_name"
assert created_ingredient["notes"] == "fake_ingredient_notes"


@pytest.mark.django_db
def test_should_retrieve_all_ingredients(client, prepare_db):
query = """
query {
allIngredients{
id
name
notes
category {
id
name
}
}
}
"""
executed = client.execute(query)

assert len(executed["data"]["allIngredients"]) == 1
created_ingredient = executed["data"]["allIngredients"][0]
assert created_ingredient["id"] == "1"
assert created_ingredient["name"] == "fake_ingredient_name"
assert created_ingredient["notes"] == "fake_ingredient_notes"
created_category = created_ingredient["category"]
assert created_category["id"] == "1"
assert created_category["name"] == "fake-category-name"


@pytest.mark.django_db
def test_should_create_category(client):
query = """
Expand Down
74 changes: 74 additions & 0 deletions api/tests/integration/graphql/test_resolvers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import pytest
from graphene.test import Client

from api.graphql.schema import schema
from api.models import Category, Ingredient


@pytest.fixture
def client():
return Client(schema)


@pytest.fixture
def prepare_db():
fake_category_name = "fake-category-name"
fake_category = Category.objects.create(name=fake_category_name)
fake_ingredient_notes = "fake_ingredient_notes"
fake_ingredient_name = "fake_ingredient_name"
Ingredient.objects.create(name=fake_ingredient_name, notes=fake_ingredient_notes, category=fake_category)


@pytest.mark.django_db
def test_should_retrieve_all_categories(client, prepare_db):
query = """
query {
allCategories{
id
name
ingredients {
id
name
notes
}
}
}
"""
executed = client.execute(query)

assert len(executed["data"]["allCategories"]) == 1
created_category = executed["data"]["allCategories"][0]
assert created_category["id"] == "1"
assert created_category["name"] == "fake-category-name"
assert len(created_category["ingredients"]) == 1
created_ingredient = created_category["ingredients"][0]
assert created_ingredient["id"] == "1"
assert created_ingredient["name"] == "fake_ingredient_name"
assert created_ingredient["notes"] == "fake_ingredient_notes"


@pytest.mark.django_db
def test_should_retrieve_all_ingredients(client, prepare_db):
query = """
query {
allIngredients{
id
name
notes
category {
id
name
}
}
}
"""
executed = client.execute(query)

assert len(executed["data"]["allIngredients"]) == 1
created_ingredient = executed["data"]["allIngredients"][0]
assert created_ingredient["id"] == "1"
assert created_ingredient["name"] == "fake_ingredient_name"
assert created_ingredient["notes"] == "fake_ingredient_notes"
created_category = created_ingredient["category"]
assert created_category["id"] == "1"
assert created_category["name"] == "fake-category-name"

0 comments on commit d8eafca

Please sign in to comment.