|
| 1 | +import pytest |
1 | 2 | from django.db import models
|
2 | 3 | from py.test import raises
|
3 | 4 |
|
4 | 5 | import graphene
|
5 |
| -from graphene.contrib.django.converter import ( |
| 6 | +from ..converter import ( |
6 | 7 | convert_django_field, convert_django_field_with_choices)
|
7 |
| -from graphene.contrib.django.fields import (ConnectionOrListField, |
8 |
| - DjangoModelField) |
| 8 | +from ..fields import (ConnectionOrListField, |
| 9 | + DjangoModelField) |
| 10 | +from ..compat import MissingType, ArrayField, HStoreField, JSONField |
9 | 11 |
|
10 | 12 | from .models import Article, Reporter
|
11 | 13 |
|
@@ -144,3 +146,32 @@ def test_should_onetoone_convert_model():
|
144 | 146 | def test_should_foreignkey_convert_model():
|
145 | 147 | field = assert_conversion(models.ForeignKey, DjangoModelField, Article)
|
146 | 148 | assert field.type.model == Article
|
| 149 | + |
| 150 | + |
| 151 | +@pytest.mark.skipif(ArrayField is MissingType, |
| 152 | + reason="ArrayField should exist") |
| 153 | +def test_should_postgres_array_convert_list(): |
| 154 | + field = assert_conversion(ArrayField, graphene.List, models.CharField(max_length=100)) |
| 155 | + assert isinstance(field.type, graphene.List) |
| 156 | + assert isinstance(field.type.of_type, graphene.String) |
| 157 | + |
| 158 | + |
| 159 | +@pytest.mark.skipif(ArrayField is MissingType, |
| 160 | + reason="ArrayField should exist") |
| 161 | +def test_should_postgres_array_multiple_convert_list(): |
| 162 | + field = assert_conversion(ArrayField, graphene.List, ArrayField(models.CharField(max_length=100))) |
| 163 | + assert isinstance(field.type, graphene.List) |
| 164 | + assert isinstance(field.type.of_type, graphene.List) |
| 165 | + assert isinstance(field.type.of_type.of_type, graphene.String) |
| 166 | + |
| 167 | + |
| 168 | +@pytest.mark.skipif(HStoreField is MissingType, |
| 169 | + reason="HStoreField should exist") |
| 170 | +def test_should_postgres_hstore_convert_string(): |
| 171 | + assert_conversion(HStoreField, graphene.String) |
| 172 | + |
| 173 | + |
| 174 | +@pytest.mark.skipif(JSONField is MissingType, |
| 175 | + reason="JSONField should exist") |
| 176 | +def test_should_postgres_json_convert_string(): |
| 177 | + assert_conversion(JSONField, graphene.String) |
0 commit comments