Skip to content

Commit

Permalink
Merge 6f1b57d into 64a5740
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-gruszczyk committed Jun 8, 2018
2 parents 64a5740 + 6f1b57d commit 5e03b2e
Show file tree
Hide file tree
Showing 87 changed files with 2,584 additions and 1,395 deletions.
8 changes: 4 additions & 4 deletions requirements.txt
Expand Up @@ -2,18 +2,18 @@ graphql-core>=2<3
cached-property==1.4

# optional
django>=2.0<3
django==2.0
psycopg2-binary>=2.7<3

# development
# testing
pytest
pytest-cov
pytest-django

# QA
flake8
flake8-comprehensions
flake8-commas
flake8-quotes
black

# documentation
sphinx
Expand Down
65 changes: 37 additions & 28 deletions slothql/__init__.py
@@ -1,44 +1,53 @@
from graphql import ResolveInfo

from .types.fields import Field, Integer, Float, String, Boolean, ID, JsonString, DateTime, Date, Time
from .selections import Selection, ResolveInfo
from .types.fields import (
Field,
Integer,
Float,
String,
Boolean,
ID,
JsonString,
DateTime,
Date,
Time,
)
from .types import BaseType, Object, Enum, EnumValue, Union
from .schema import Schema
from .operation import Operation, InvalidOperation
from .query import gql, ExecutionResult

__all__ = (
# graphql
'ResolveInfo',

"Selection",
"ResolveInfo",
# fields
'Field',
'Integer',
'Float',
'String',
'Boolean',
'ID',
'JsonString',
'DateTime',
'Date',
'Time',

"Field",
"Integer",
"Float",
"String",
"Boolean",
"ID",
"JsonString",
"DateTime",
"Date",
"Time",
# types
'BaseType',
'Object',
'Enum',
'EnumValue',
'Union',

'Operation',
'InvalidOperation',
'Schema',
'gql',
'ExecutionResult',
"BaseType",
"Object",
"Enum",
"EnumValue",
"Union",
"Operation",
"InvalidOperation",
"Schema",
"gql",
"ExecutionResult",
)

try:
from slothql import django
__all__ += ('django',)

__all__ += ("django",)
except ImportError as e:
if str(e) != "No module named 'django'":
raise
62 changes: 0 additions & 62 deletions slothql/arguments/filters.py

This file was deleted.

Empty file.
30 changes: 0 additions & 30 deletions slothql/arguments/tests/integration.py

This file was deleted.

15 changes: 0 additions & 15 deletions slothql/arguments/utils.py

This file was deleted.

4 changes: 1 addition & 3 deletions slothql/config.py
@@ -1,6 +1,4 @@
import os

BASE_DIR = os.path.dirname(__file__)
TEMPLATE_DIRS = [
'templates/',
]
TEMPLATE_DIRS = ["templates/"]
37 changes: 25 additions & 12 deletions slothql/conftest.py
Expand Up @@ -6,7 +6,6 @@
from django.db import models

import graphql
from graphql.type.definition import GraphQLType

import slothql
from slothql.types.base import BaseType
Expand All @@ -19,23 +18,24 @@ def pytest_configure():

# setup for @pytest.mark.incremental


def pytest_runtest_makereport(item, call):
if 'incremental' in item.keywords:
if "incremental" in item.keywords:
if call.excinfo is not None and not item._skipped_by_mark:
parent = item.parent
parent._previousfailed = item


def pytest_runtest_setup(item):
if 'incremental' in item.keywords:
previousfailed = getattr(item.parent, '_previousfailed', None)
if "incremental" in item.keywords:
previousfailed = getattr(item.parent, "_previousfailed", None)
if previousfailed is not None:
pytest.xfail(f'previous test failed ({previousfailed.name})')
pytest.xfail(f"previous test failed ({previousfailed.name})")


@pytest.fixture()
def type_mock():
return lambda: BaseType(mock.Mock(spec=GraphQLType))
return lambda: BaseType


@pytest.fixture()
Expand All @@ -45,17 +45,28 @@ def info_mock():

@pytest.fixture()
def resolver_mock():
return mock.Mock(side_effect=lambda o, *_: o)
return mock.Mock(spec=staticmethod, side_effect=lambda o, *_: o)


@pytest.fixture()
def field_mock():
return mock.Mock(spec=slothql.Field)
def field_mock(resolver_mock):
return mock.Mock(
spec=slothql.Field,
_resolver=resolver_mock,
description=None,
source=None,
many=False,
filterable=False,
)


@pytest.fixture()
def partials_equal():
return lambda p1, p2: p1.func == p2.func and p1.args == p2.args and p1.keywords == p2.keywords
return (
lambda p1, p2: p1.func == p2.func
and p1.args == p2.args
and p1.keywords == p2.keywords
)


@pytest.fixture()
Expand All @@ -75,12 +86,14 @@ def schema_mock():

@pytest.fixture()
def operation_mock():
return mock.Mock(spec=slothql.Operation, query='foo', variables={}, operation_name='baz')
return mock.Mock(
spec=slothql.Operation, query="foo", variables={}, operation_name="baz"
)


@pytest.fixture()
def hello_schema():
class Query(slothql.Object):
hello = slothql.String(resolver=lambda: 'world')
hello = slothql.String(resolver=lambda: "world")

return slothql.Schema(query=Query)
7 changes: 2 additions & 5 deletions slothql/django/__init__.py
@@ -1,7 +1,4 @@
from .views import GraphQLView
from .types import Model
from .types import Model, DjangoFilter

__all__ = (
'GraphQLView',
'Model',
)
__all__ = ("GraphQLView", "Model", "DjangoFilter")
24 changes: 24 additions & 0 deletions slothql/django/conftest.py
@@ -0,0 +1,24 @@
import pytest
from unittest import mock

from django.db import models


@pytest.fixture()
def queryset(**kwargs):
queryset_instance = mock.Mock(
spec=models.QuerySet,
side_effect=queryset,
select_related=mock.Mock(side_effect=lambda *_: queryset_instance),
prefetch_related=mock.Mock(side_effect=lambda *_: queryset_instance),
filter=mock.Mock(side_effect=lambda **_: queryset_instance),
__iter__=lambda self: iter(()),
_iterable_class=models.query.ModelIterable,
**kwargs,
)
return queryset_instance


@pytest.fixture()
def queryset_factory():
return queryset

0 comments on commit 5e03b2e

Please sign in to comment.