Ejemplo n.º 1
0
 def test_default(self):
     schema_dict = DjangoQLSchema(Book).as_dict()
     self.assertIsInstance(schema_dict, dict)
     self.assertEqual('core.book', schema_dict.get('current_model'))
     models = schema_dict.get('models')
     self.assertIsInstance(models, dict)
     all_model_labels = sorted([str(m._meta) for m in self.all_models()])
     session_model = all_model_labels.pop()
     self.assertEqual('sessions.session', session_model)
     self.assertListEqual(all_model_labels, sorted(models.keys()))
Ejemplo n.º 2
0
 def test_get_fields(self):
     default = DjangoQLSchema(Book).as_dict()['models']['core.book']
     custom = BookCustomFieldsSchema(Book).as_dict()['models']['core.book']
     self.assertListEqual(list(default.keys()), [
         'author',
         'content_type',
         'id',
         'is_published',
         'name',
         'object_id',
         'price',
         'rating',
         'written',
     ])
     self.assertListEqual(list(custom.keys()), ['name', 'is_published'])
Ejemplo n.º 3
0
 def test_circular_references(self):
     models = DjangoQLSchema(Book).as_dict()['models']
     # If Book references Author then Author shouldn't reference Book back
     book_author_field = models['core.book'].get('author')
     self.assertIsNotNone(book_author_field)
     self.assertEqual('relation', book_author_field['type'])
     self.assertEqual('auth.user', book_author_field['relation'])
     self.assertNotIn('book', models['auth.user'])
Ejemplo n.º 4
0
 def test_get_fields(self):
     default_schema = DjangoQLSchema(Book)
     default = serializer.serialize(default_schema)['models']['core.book']
     custom_schema = BookCustomFieldsSchema(Book)
     custom = serializer.serialize(custom_schema)['models']['core.book']
     self.assertListEqual(list(default.keys()), [
         'author',
         'content_type',
         'genre',
         'id',
         'is_published',
         'name',
         'object_id',
         'price',
         'rating',
         'similar_books',
         'written',
     ])
     self.assertListEqual(list(custom.keys()), ['name', 'is_published'])
Ejemplo n.º 5
0
 def introspections(context):
     return json.dumps(DjangoQLSchemaSerializer().serialize(
         DjangoQLSchema(
             hg.resolve_lazy(boundfield,
                             context).value().queryset.model)))