From 858ffd4fbb24c83a854f1b7126c1d636bc2985d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=CC=88lgen=20Sar=C4=B1kavak?= Date: Thu, 18 Aug 2022 14:28:38 +0300 Subject: [PATCH 1/2] Call black via pre-commit --- .pre-commit-config.yaml | 6 ++++++ Makefile | 6 +----- setup.py | 2 +- tox.ini | 6 ------ 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 08aa27684..021d38b92 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,14 @@ default_language_version: python: python3.10 + repos: - repo: https://github.com/PyCQA/flake8 rev: 5.0.4 hooks: - id: flake8 additional_dependencies: [flake8-bugbear==22.7.1] + +- repo: https://github.com/psf/black + rev: 22.6.0 + hooks: + - id: black diff --git a/Makefile b/Makefile index b850ae899..8f7ea0d47 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,7 @@ test: tests # Alias test -> tests .PHONY: format format: - black --exclude "/migrations/" graphene_django examples setup.py - -.PHONY: lint -lint: - flake8 graphene_django examples + pre-commit run --all-files .PHONY: docs ## Generate docs docs: dev-setup diff --git a/setup.py b/setup.py index 974332890..cadf9700e 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ dev_requires = [ - "black==19.10b0", + "black==22.6.0", "flake8>=5,<6", "flake8-black==0.3.3", "flake8-bugbear==22.7.1", diff --git a/tox.ini b/tox.ini index afe79c681..952ba6834 100644 --- a/tox.ini +++ b/tox.ini @@ -39,12 +39,6 @@ deps = djangomaster: https://github.com/django/django/archive/master.zip commands = {posargs:py.test --cov=graphene_django graphene_django examples} -[testenv:black] -basepython = python3.10 -deps = -e.[dev] -commands = - black --exclude "/migrations/" graphene_django examples setup.py --check - [testenv:pre-commit] basepython = python3.10 skip_install = true From 96c07d803444684c4bc37b383e34d7f1051a94d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=CC=88lgen=20Sar=C4=B1kavak?= Date: Thu, 18 Aug 2022 14:31:40 +0300 Subject: [PATCH 2/2] Apply black --- docs/conf.py | 16 ++-- docs/schema.py | 75 +++++++++---------- .../ingredients/migrations/0001_initial.py | 42 ++++++++--- .../migrations/0002_auto_20161104_0050.py | 6 +- .../migrations/0003_auto_20181018_1746.py | 6 +- .../recipes/migrations/0001_initial.py | 58 +++++++++++--- .../migrations/0002_auto_20161104_0106.py | 22 ++++-- .../migrations/0003_auto_20181018_1728.py | 16 +++- .../ingredients/migrations/0001_initial.py | 42 ++++++++--- .../migrations/0002_auto_20161104_0050.py | 6 +- .../recipes/migrations/0001_initial.py | 58 +++++++++++--- .../migrations/0002_auto_20161104_0106.py | 22 ++++-- graphene_django/fields.py | 5 +- .../filter/filters/global_id_filter.py | 2 +- graphene_django/filter/filterset.py | 10 +-- graphene_django/filter/tests/conftest.py | 20 ++++- .../filter/tests/test_enum_filtering.py | 23 +++++- graphene_django/filter/tests/test_fields.py | 14 +++- .../filter/tests/test_in_filter.py | 20 ++++- .../filter/tests/test_typed_filter.py | 15 +++- graphene_django/filter/utils.py | 4 +- graphene_django/tests/models.py | 4 +- graphene_django/tests/test_query.py | 16 +++- .../utils/tests/test_str_converters.py | 2 +- 24 files changed, 356 insertions(+), 148 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a485d5be7..b83e0f061 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,18 +60,18 @@ master_doc = "index" # General information about the project. -project = u"Graphene Django" -copyright = u"Graphene 2017" -author = u"Syrus Akbary" +project = "Graphene Django" +copyright = "Graphene 2017" +author = "Syrus Akbary" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u"1.0" +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u"1.0.dev" +release = "1.0.dev" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -276,7 +276,7 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual") + (master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual") ] # The name of an image file (relative to this directory) to place at the top of @@ -317,7 +317,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, "graphene_django", u"Graphene Django Documentation", [author], 1) + (master_doc, "graphene_django", "Graphene Django Documentation", [author], 1) ] # If true, show URL addresses after external links. @@ -334,7 +334,7 @@ ( master_doc, "Graphene-Django", - u"Graphene Django Documentation", + "Graphene Django Documentation", author, "Graphene Django", "One line description of project.", diff --git a/docs/schema.py b/docs/schema.py index 3d9b2fa90..914b656db 100644 --- a/docs/schema.py +++ b/docs/schema.py @@ -1,58 +1,55 @@ - import graphene +import graphene - from graphene_django.types import DjangoObjectType +from graphene_django.types import DjangoObjectType - from cookbook.ingredients.models import Category, Ingredient +from cookbook.ingredients.models import Category, Ingredient - class CategoryType(DjangoObjectType): - class Meta: - model = Category +class CategoryType(DjangoObjectType): + class Meta: + model = Category - class IngredientType(DjangoObjectType): - class Meta: - model = Ingredient +class IngredientType(DjangoObjectType): + class Meta: + model = Ingredient - class Query(object): - category = graphene.Field(CategoryType, - id=graphene.Int(), - name=graphene.String()) - all_categories = graphene.List(CategoryType) +class Query(object): + category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String()) + all_categories = graphene.List(CategoryType) + ingredient = graphene.Field( + IngredientType, id=graphene.Int(), name=graphene.String() + ) + all_ingredients = graphene.List(IngredientType) - ingredient = graphene.Field(IngredientType, - id=graphene.Int(), - name=graphene.String()) - all_ingredients = graphene.List(IngredientType) + def resolve_all_categories(self, info, **kwargs): + return Category.objects.all() - def resolve_all_categories(self, info, **kwargs): - return Category.objects.all() + def resolve_all_ingredients(self, info, **kwargs): + return Ingredient.objects.all() - def resolve_all_ingredients(self, info, **kwargs): - return Ingredient.objects.all() + def resolve_category(self, info, **kwargs): + id = kwargs.get("id") + name = kwargs.get("name") - def resolve_category(self, info, **kwargs): - id = kwargs.get('id') - name = kwargs.get('name') + if id is not None: + return Category.objects.get(pk=id) - if id is not None: - return Category.objects.get(pk=id) + if name is not None: + return Category.objects.get(name=name) - if name is not None: - return Category.objects.get(name=name) + return None - return None + def resolve_ingredient(self, info, **kwargs): + id = kwargs.get("id") + name = kwargs.get("name") - def resolve_ingredient(self, info, **kwargs): - id = kwargs.get('id') - name = kwargs.get('name') + if id is not None: + return Ingredient.objects.get(pk=id) - if id is not None: - return Ingredient.objects.get(pk=id) + if name is not None: + return Ingredient.objects.get(name=name) - if name is not None: - return Ingredient.objects.get(name=name) - - return None \ No newline at end of file + return None diff --git a/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py b/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py index 04949239f..ee8cadd42 100644 --- a/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py +++ b/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py @@ -10,24 +10,46 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Category', + name="Category", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), ], ), migrations.CreateModel( - name='Ingredient', + name="Ingredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('notes', models.TextField()), - ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("notes", models.TextField()), + ( + "category", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="ingredients", + to="ingredients.Category", + ), + ), ], ), ] diff --git a/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py b/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py index 359d4fc4c..0f3cab59d 100644 --- a/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py +++ b/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py @@ -8,13 +8,13 @@ class Migration(migrations.Migration): dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.AlterField( - model_name='ingredient', - name='notes', + model_name="ingredient", + name="notes", field=models.TextField(blank=True, null=True), ), ] diff --git a/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py b/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py index 184e79e4f..8015d1f72 100644 --- a/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py +++ b/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py @@ -6,12 +6,12 @@ class Migration(migrations.Migration): dependencies = [ - ('ingredients', '0002_auto_20161104_0050'), + ("ingredients", "0002_auto_20161104_0050"), ] operations = [ migrations.AlterModelOptions( - name='category', - options={'verbose_name_plural': 'Categories'}, + name="category", + options={"verbose_name_plural": "Categories"}, ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py b/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py index 338c71a1b..a43fa7d70 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py @@ -11,26 +11,62 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.CreateModel( - name='Recipe', + name="Recipe", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('instructions', models.TextField()), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("instructions", models.TextField()), ], ), migrations.CreateModel( - name='RecipeIngredient', + name="RecipeIngredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('amount', models.FloatField()), - ('unit', models.CharField(choices=[('kg', 'Kilograms'), ('l', 'Litres'), ('', 'Units')], max_length=20)), - ('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to='ingredients.Ingredient')), - ('recipes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='amounts', to='recipes.Recipe')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("amount", models.FloatField()), + ( + "unit", + models.CharField( + choices=[("kg", "Kilograms"), ("l", "Litres"), ("", "Units")], + max_length=20, + ), + ), + ( + "ingredient", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="used_by", + to="ingredients.Ingredient", + ), + ), + ( + "recipes", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="amounts", + to="recipes.Recipe", + ), + ), ], ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py index f13539265..6a8d1bf80 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -8,18 +8,26 @@ class Migration(migrations.Migration): dependencies = [ - ('recipes', '0001_initial'), + ("recipes", "0001_initial"), ] operations = [ migrations.RenameField( - model_name='recipeingredient', - old_name='recipes', - new_name='recipe', + model_name="recipeingredient", + old_name="recipes", + new_name="recipe", ), migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), + model_name="recipeingredient", + name="unit", + field=models.CharField( + choices=[ + (b"unit", b"Units"), + (b"kg", b"Kilograms"), + (b"l", b"Litres"), + (b"st", b"Shots"), + ], + max_length=20, + ), ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py b/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py index 7a8df493b..c54855b82 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py @@ -6,13 +6,21 @@ class Migration(migrations.Migration): dependencies = [ - ('recipes', '0002_auto_20161104_0106'), + ("recipes", "0002_auto_20161104_0106"), ] operations = [ migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[('unit', 'Units'), ('kg', 'Kilograms'), ('l', 'Litres'), ('st', 'Shots')], max_length=20), + model_name="recipeingredient", + name="unit", + field=models.CharField( + choices=[ + ("unit", "Units"), + ("kg", "Kilograms"), + ("l", "Litres"), + ("st", "Shots"), + ], + max_length=20, + ), ), ] diff --git a/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py b/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py index 04949239f..ee8cadd42 100644 --- a/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py +++ b/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py @@ -10,24 +10,46 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Category', + name="Category", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), ], ), migrations.CreateModel( - name='Ingredient', + name="Ingredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('notes', models.TextField()), - ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("notes", models.TextField()), + ( + "category", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="ingredients", + to="ingredients.Category", + ), + ), ], ), ] diff --git a/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py b/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py index 359d4fc4c..0f3cab59d 100644 --- a/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py +++ b/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py @@ -8,13 +8,13 @@ class Migration(migrations.Migration): dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.AlterField( - model_name='ingredient', - name='notes', + model_name="ingredient", + name="notes", field=models.TextField(blank=True, null=True), ), ] diff --git a/examples/cookbook/cookbook/recipes/migrations/0001_initial.py b/examples/cookbook/cookbook/recipes/migrations/0001_initial.py index 338c71a1b..a43fa7d70 100644 --- a/examples/cookbook/cookbook/recipes/migrations/0001_initial.py +++ b/examples/cookbook/cookbook/recipes/migrations/0001_initial.py @@ -11,26 +11,62 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.CreateModel( - name='Recipe', + name="Recipe", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('instructions', models.TextField()), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("instructions", models.TextField()), ], ), migrations.CreateModel( - name='RecipeIngredient', + name="RecipeIngredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('amount', models.FloatField()), - ('unit', models.CharField(choices=[('kg', 'Kilograms'), ('l', 'Litres'), ('', 'Units')], max_length=20)), - ('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to='ingredients.Ingredient')), - ('recipes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='amounts', to='recipes.Recipe')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("amount", models.FloatField()), + ( + "unit", + models.CharField( + choices=[("kg", "Kilograms"), ("l", "Litres"), ("", "Units")], + max_length=20, + ), + ), + ( + "ingredient", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="used_by", + to="ingredients.Ingredient", + ), + ), + ( + "recipes", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="amounts", + to="recipes.Recipe", + ), + ), ], ), ] diff --git a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py index f13539265..6a8d1bf80 100644 --- a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -8,18 +8,26 @@ class Migration(migrations.Migration): dependencies = [ - ('recipes', '0001_initial'), + ("recipes", "0001_initial"), ] operations = [ migrations.RenameField( - model_name='recipeingredient', - old_name='recipes', - new_name='recipe', + model_name="recipeingredient", + old_name="recipes", + new_name="recipe", ), migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), + model_name="recipeingredient", + name="unit", + field=models.CharField( + choices=[ + (b"unit", b"Units"), + (b"kg", b"Kilograms"), + (b"l", b"Litres"), + (b"st", b"Shots"), + ], + max_length=20, + ), ), ] diff --git a/graphene_django/fields.py b/graphene_django/fields.py index fdf95aa52..eead5b3ae 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -66,7 +66,10 @@ def get_resolver(self, parent_resolver): _type = _type.of_type django_object_type = _type.of_type.of_type return partial( - self.list_resolver, django_object_type, parent_resolver, self.get_manager(), + self.list_resolver, + django_object_type, + parent_resolver, + self.get_manager(), ) diff --git a/graphene_django/filter/filters/global_id_filter.py b/graphene_django/filter/filters/global_id_filter.py index a612a8a2a..da16585ee 100644 --- a/graphene_django/filter/filters/global_id_filter.py +++ b/graphene_django/filter/filters/global_id_filter.py @@ -13,7 +13,7 @@ class GlobalIDFilter(Filter): field_class = GlobalIDFormField def filter(self, qs, value): - """ Convert the filter value to a primary key before filtering """ + """Convert the filter value to a primary key before filtering""" _id = None if value is not None: _, _id = from_global_id(value) diff --git a/graphene_django/filter/filterset.py b/graphene_django/filter/filterset.py index 0fd0a82eb..8ffb0b518 100644 --- a/graphene_django/filter/filterset.py +++ b/graphene_django/filter/filterset.py @@ -19,8 +19,8 @@ class GrapheneFilterSetMixin(BaseFilterSet): - """ A django_filters.filterset.BaseFilterSet with default filter overrides - to handle global IDs """ + """A django_filters.filterset.BaseFilterSet with default filter overrides + to handle global IDs""" FILTER_DEFAULTS = dict( itertools.chain( @@ -60,8 +60,7 @@ def filter_for_reverse_field(cls, f, name): def setup_filterset(filterset_class): - """ Wrap a provided filterset in Graphene-specific functionality - """ + """Wrap a provided filterset in Graphene-specific functionality""" return type( "Graphene{}".format(filterset_class.__name__), (filterset_class, GrapheneFilterSetMixin), @@ -70,8 +69,7 @@ def setup_filterset(filterset_class): def custom_filterset_factory(model, filterset_base_class=FilterSet, **meta): - """ Create a filterset for the given model using the provided meta data - """ + """Create a filterset for the given model using the provided meta data""" meta.update({"model": model}) meta_class = type(str("Meta"), (object,), meta) filterset = type( diff --git a/graphene_django/filter/tests/conftest.py b/graphene_django/filter/tests/conftest.py index 710234ff1..4d5b8105a 100644 --- a/graphene_django/filter/tests/conftest.py +++ b/graphene_django/filter/tests/conftest.py @@ -92,10 +92,22 @@ class Query(graphene.ObjectType): def resolve_events(self, info, **kwargs): events = [ - Event(name="Live Show", tags=["concert", "music", "rock"],), - Event(name="Musical", tags=["movie", "music"],), - Event(name="Ballet", tags=["concert", "dance"],), - Event(name="Speech", tags=[],), + Event( + name="Live Show", + tags=["concert", "music", "rock"], + ), + Event( + name="Musical", + tags=["movie", "music"], + ), + Event( + name="Ballet", + tags=["concert", "dance"], + ), + Event( + name="Speech", + tags=[], + ), ] STORE["events"] = events diff --git a/graphene_django/filter/tests/test_enum_filtering.py b/graphene_django/filter/tests/test_enum_filtering.py index 0fe572ca2..73b628b0f 100644 --- a/graphene_django/filter/tests/test_enum_filtering.py +++ b/graphene_django/filter/tests/test_enum_filtering.py @@ -52,13 +52,22 @@ def reporter_article_data(): first_name="Jane", last_name="Doe", email="janedoe@example.com", a_choice=2 ) Article.objects.create( - headline="Article Node 1", reporter=john, editor=john, lang="es", + headline="Article Node 1", + reporter=john, + editor=john, + lang="es", ) Article.objects.create( - headline="Article Node 2", reporter=john, editor=john, lang="en", + headline="Article Node 2", + reporter=john, + editor=john, + lang="en", ) Article.objects.create( - headline="Article Node 3", reporter=jane, editor=jane, lang="en", + headline="Article Node 3", + reporter=jane, + editor=jane, + lang="en", ) @@ -78,7 +87,13 @@ def test_filter_enum_on_connection(schema, reporter_article_data): } """ - expected = {"allArticles": {"edges": [{"node": {"headline": "Article Node 1"}},]}} + expected = { + "allArticles": { + "edges": [ + {"node": {"headline": "Article Node 1"}}, + ] + } + } result = schema.execute(query) assert not result.errors diff --git a/graphene_django/filter/tests/test_fields.py b/graphene_django/filter/tests/test_fields.py index 86b377adb..61e65482e 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -1208,13 +1208,23 @@ class Query(ObjectType): result = schema.execute(query, variables={"filter": "Ja"}) assert not result.errors assert result.data == { - "people": {"edges": [{"node": {"name": "Jack"}}, {"node": {"name": "Jane"}},]} + "people": { + "edges": [ + {"node": {"name": "Jack"}}, + {"node": {"name": "Jane"}}, + ] + } } result = schema.execute(query, variables={"filter": "o"}) assert not result.errors assert result.data == { - "people": {"edges": [{"node": {"name": "Joe"}}, {"node": {"name": "Bob"}},]} + "people": { + "edges": [ + {"node": {"name": "Joe"}}, + {"node": {"name": "Bob"}}, + ] + } } diff --git a/graphene_django/filter/tests/test_in_filter.py b/graphene_django/filter/tests/test_in_filter.py index f0015b69f..f022aa055 100644 --- a/graphene_django/filter/tests/test_in_filter.py +++ b/graphene_django/filter/tests/test_in_filter.py @@ -374,16 +374,28 @@ def test_enum_in_filter(query): """ Reporter.objects.create( - first_name="John", last_name="Doe", email="john@doe.com", reporter_type=1 + first_name="John", + last_name="Doe", + email="john@doe.com", + reporter_type=1, ) Reporter.objects.create( - first_name="Jean", last_name="Bon", email="jean@bon.com", reporter_type=2 + first_name="Jean", + last_name="Bon", + email="jean@bon.com", + reporter_type=2, ) Reporter.objects.create( - first_name="Jane", last_name="Doe", email="jane@doe.com", reporter_type=2 + first_name="Jane", + last_name="Doe", + email="jane@doe.com", + reporter_type=2, ) Reporter.objects.create( - first_name="Jack", last_name="Black", email="jack@black.com", reporter_type=None + first_name="Jack", + last_name="Black", + email="jack@black.com", + reporter_type=None, ) schema = Schema(query=query) diff --git a/graphene_django/filter/tests/test_typed_filter.py b/graphene_django/filter/tests/test_typed_filter.py index 65f025a76..051144d04 100644 --- a/graphene_django/filter/tests/test_typed_filter.py +++ b/graphene_django/filter/tests/test_typed_filter.py @@ -103,13 +103,22 @@ def test_typed_filter_schema(schema): def test_typed_filters_work(schema): reporter = Reporter.objects.create(first_name="John", last_name="Doe", email="") Article.objects.create( - headline="A", reporter=reporter, editor=reporter, lang="es", + headline="A", + reporter=reporter, + editor=reporter, + lang="es", ) Article.objects.create( - headline="B", reporter=reporter, editor=reporter, lang="es", + headline="B", + reporter=reporter, + editor=reporter, + lang="es", ) Article.objects.create( - headline="C", reporter=reporter, editor=reporter, lang="en", + headline="C", + reporter=reporter, + editor=reporter, + lang="en", ) query = "query { articles (lang_In: [ES]) { edges { node { headline } } } }" diff --git a/graphene_django/filter/utils.py b/graphene_django/filter/utils.py index c7aa959d5..07437737a 100644 --- a/graphene_django/filter/utils.py +++ b/graphene_django/filter/utils.py @@ -99,7 +99,9 @@ def get_filtering_args_from_filterset(filterset_class, type): field_type = graphene.List(field_type) args[name] = graphene.Argument( - type=field_type, description=filter_field.label, required=required, + type=field_type, + description=filter_field.label, + required=required, ) return args diff --git a/graphene_django/tests/models.py b/graphene_django/tests/models.py index 659cf6df4..7b76cd378 100644 --- a/graphene_django/tests/models.py +++ b/graphene_django/tests/models.py @@ -50,7 +50,7 @@ class Reporter(models.Model): "Reporter Type", null=True, blank=True, - choices=[(1, u"Regular"), (2, u"CNN Reporter")], + choices=[(1, "Regular"), (2, "CNN Reporter")], ) def __str__(self): # __unicode__ on Python 2 @@ -109,7 +109,7 @@ class Article(models.Model): "Importance", null=True, blank=True, - choices=[(1, u"Very important"), (2, u"Not as important")], + choices=[(1, "Very important"), (2, "Not as important")], ) def __str__(self): # __unicode__ on Python 2 diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 9d83f3f6f..fd43fb0c9 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1444,7 +1444,11 @@ class Query(graphene.ObjectType): result = schema.execute(query) assert not result.errors expected = { - "allReporters": {"edges": [{"node": {"firstName": "Some", "lastName": "Guy"}},]} + "allReporters": { + "edges": [ + {"node": {"firstName": "Some", "lastName": "Guy"}}, + ] + } } assert result.data == expected @@ -1484,7 +1488,9 @@ class Query(graphene.ObjectType): assert not result.errors expected = { "allReporters": { - "edges": [{"node": {"firstName": "Some", "lastName": "Lady"}},] + "edges": [ + {"node": {"firstName": "Some", "lastName": "Lady"}}, + ] } } assert result.data == expected @@ -1551,6 +1557,10 @@ class Query(graphene.ObjectType): result = schema.execute(query, variable_values=dict(after=after)) assert not result.errors expected = { - "allReporters": {"edges": [{"node": {"firstName": "Jane", "lastName": "Roe"}},]} + "allReporters": { + "edges": [ + {"node": {"firstName": "Jane", "lastName": "Roe"}}, + ] + } } assert result.data == expected diff --git a/graphene_django/utils/tests/test_str_converters.py b/graphene_django/utils/tests/test_str_converters.py index 24064b29f..fc466f6cc 100644 --- a/graphene_django/utils/tests/test_str_converters.py +++ b/graphene_django/utils/tests/test_str_converters.py @@ -7,4 +7,4 @@ def test_to_const(): def test_to_const_unicode(): - assert to_const(u"Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF" + assert to_const("Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"