-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix register_singular_query_field for non-page models
- Loading branch information
Showing
6 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 3.1.3 on 2020-12-08 18:50 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("home", "0018_add_pagechooserblock"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SimpleModel", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from example.tests.test_grapple import BaseGrappleTest | ||
|
||
from home.factories import BlogPageFactory, SimpleModelFactory | ||
|
||
|
||
class TestRegisterSingularQueryField(BaseGrappleTest): | ||
def test_singular_blog_page_query(self): | ||
def query(): | ||
return """ | ||
{ | ||
firstPost { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
blog_post = BlogPageFactory() | ||
another_post = BlogPageFactory() | ||
results = self.client.execute(query()) | ||
|
||
self.assertTrue("firstPost" in results["data"]) | ||
self.assertEqual(int(results["data"]["firstPost"]["id"]), blog_post.id) | ||
|
||
results = self.client.execute( | ||
""" | ||
{ | ||
firstPost(order: "-id") { | ||
id | ||
} | ||
} | ||
""" | ||
) | ||
|
||
self.assertTrue("firstPost" in results["data"]) | ||
self.assertEqual(int(results["data"]["firstPost"]["id"]), another_post.id) | ||
|
||
def test_singular_django_model_query(self): | ||
def query(): | ||
return """ | ||
{ | ||
simpleModel { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
results = self.client.execute(query()) | ||
self.assertTrue("simpleModel" in results["data"]) | ||
self.assertIsNone(results["data"]["simpleModel"]) | ||
|
||
instance = SimpleModelFactory() | ||
results = self.client.execute(query()) | ||
|
||
self.assertEqual(int(results["data"]["simpleModel"]["id"]), instance.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters