mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 09:57:41 +03:00 
			
		
		
		
	Completed Python3 Compatibility!
This commit is contained in:
		
							parent
							
								
									b58269ce72
								
							
						
					
					
						commit
						fe510dc686
					
				| 
						 | 
				
			
			@ -2,6 +2,10 @@ language: python
 | 
			
		|||
sudo: false
 | 
			
		||||
python:
 | 
			
		||||
- 2.7
 | 
			
		||||
- 3.3
 | 
			
		||||
- 3.4
 | 
			
		||||
- 3.5
 | 
			
		||||
- pypy
 | 
			
		||||
install:
 | 
			
		||||
- pip install pytest pytest-cov coveralls flake8 six blinker
 | 
			
		||||
# - pip install -e .[django]  # TODO: Commented until graphqllib is in pypi
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ class GraphQLView(View):
 | 
			
		|||
    def format_result(result):
 | 
			
		||||
        data = {'data': result.data}
 | 
			
		||||
        if result.errors:
 | 
			
		||||
            data['errors'] = map(form_error, result.errors)
 | 
			
		||||
            data['errors'] = list(map(form_error, result.errors))
 | 
			
		||||
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -42,7 +42,6 @@ class GraphQLView(View):
 | 
			
		|||
                if settings.DEBUG:
 | 
			
		||||
                    raise e
 | 
			
		||||
                return self.response_errors(e)
 | 
			
		||||
 | 
			
		||||
        return JsonResponse(data)
 | 
			
		||||
 | 
			
		||||
    def get(self, request, *args, **kwargs):
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +57,7 @@ class GraphQLView(View):
 | 
			
		|||
        content_type = self.get_content_type(request)
 | 
			
		||||
        if content_type == 'application/json':
 | 
			
		||||
            try:
 | 
			
		||||
                received_json_data = json.loads(request.body)
 | 
			
		||||
                received_json_data = json.loads(request.body.decode())
 | 
			
		||||
                query = received_json_data.get('query')
 | 
			
		||||
            except ValueError:
 | 
			
		||||
                return self.response_errors(ValueError("Malformed json body in the post data"))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -117,9 +117,6 @@ class BaseObjectType(object):
 | 
			
		|||
    def get_field(self, field):
 | 
			
		||||
        return getattr(self.instance, field, None)
 | 
			
		||||
 | 
			
		||||
    def __eq__(self, other):
 | 
			
		||||
        return self.instance.__eq__(other)
 | 
			
		||||
 | 
			
		||||
    def resolve(self, field_name, args, info):
 | 
			
		||||
        custom_resolve_fn = 'resolve_%s' % field_name
 | 
			
		||||
        if hasattr(self, custom_resolve_fn):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								setup.py
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -40,6 +40,12 @@ setup(
 | 
			
		|||
        'Intended Audience :: Developers',
 | 
			
		||||
        'Topic :: Software Development :: Libraries',
 | 
			
		||||
        'Programming Language :: Python :: 2',
 | 
			
		||||
        'Programming Language :: Python :: 2.7',
 | 
			
		||||
        'Programming Language :: Python :: 3',
 | 
			
		||||
        'Programming Language :: Python :: 3.3',
 | 
			
		||||
        'Programming Language :: Python :: 3.4',
 | 
			
		||||
        'Programming Language :: Python :: 3.5',
 | 
			
		||||
        'Programming Language :: Python :: Implementation :: PyPy',
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    keywords='api graphql protocol rest relay graphene',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,8 @@ from graphene.contrib.django import (
 | 
			
		|||
)
 | 
			
		||||
from .models import Reporter, Article
 | 
			
		||||
 | 
			
		||||
from tests.utils import assert_equal_lists
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_raise_if_no_model():
 | 
			
		||||
    with raises(Exception) as excinfo:
 | 
			
		||||
| 
						 | 
				
			
			@ -49,8 +51,10 @@ def test_should_map_fields_correctly():
 | 
			
		|||
 | 
			
		||||
        class Meta:
 | 
			
		||||
            model = Reporter
 | 
			
		||||
    assert ReporterType2._meta.fields_map.keys(
 | 
			
		||||
    ) == ['articles', 'first_name', 'last_name', 'email', 'pets', 'id']
 | 
			
		||||
    assert_equal_lists(
 | 
			
		||||
        ReporterType2._meta.fields_map.keys(),
 | 
			
		||||
        ['articles', 'first_name', 'last_name', 'email', 'pets', 'id']
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_map_fields():
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +97,10 @@ def test_should_map_only_few_fields():
 | 
			
		|||
        class Meta:
 | 
			
		||||
            model = Reporter
 | 
			
		||||
            only_fields = ('id', 'email')
 | 
			
		||||
    assert Reporter2._meta.fields_map.keys() == ['id', 'email']
 | 
			
		||||
    assert_equal_lists(
 | 
			
		||||
        Reporter2._meta.fields_map.keys(),
 | 
			
		||||
        ['id', 'email']
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_node():
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,8 @@ from graphene.contrib.django.types import (
 | 
			
		|||
 | 
			
		||||
from .models import Reporter, Article
 | 
			
		||||
 | 
			
		||||
from tests.utils import assert_equal_lists
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Character(DjangoInterface):
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -48,8 +50,10 @@ def test_pseudo_interface():
 | 
			
		|||
    assert Character._meta.interface is True
 | 
			
		||||
    assert isinstance(object_type, GraphQLInterfaceType)
 | 
			
		||||
    assert Character._meta.model == Reporter
 | 
			
		||||
    assert object_type.get_fields().keys() == [
 | 
			
		||||
        'articles', 'firstName', 'lastName', 'email', 'pets', 'id']
 | 
			
		||||
    assert_equal_lists(
 | 
			
		||||
        object_type.get_fields().keys(),
 | 
			
		||||
        ['articles', 'firstName', 'lastName', 'email', 'pets', 'id']
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_interface_resolve_type():
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ from graphene.contrib.django.types import (
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def format_response(response):
 | 
			
		||||
    return json.loads(response.content)
 | 
			
		||||
    return json.loads(response.content.decode())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_client_get_no_query(settings, client):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,7 @@ from graphene import (
 | 
			
		|||
    Schema
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from tests.utils import assert_equal_lists
 | 
			
		||||
 | 
			
		||||
schema = Schema(name='My own schema')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -104,5 +105,7 @@ def test_query_schema_execute():
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def test_schema_get_type_map():
 | 
			
		||||
    assert schema.schema.get_type_map().keys() == [
 | 
			
		||||
        '__Field', 'String', 'Pet', 'Character', '__InputValue', '__Directive', '__TypeKind', '__Schema', '__Type', 'Human', '__EnumValue', 'Boolean']
 | 
			
		||||
    assert_equal_lists(
 | 
			
		||||
        schema.schema.get_type_map().keys(),
 | 
			
		||||
        ['__Field', 'String', 'Pet', 'Character', '__InputValue', '__Directive', '__TypeKind', '__Schema', '__Type', 'Human', '__EnumValue', 'Boolean']
 | 
			
		||||
    )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								tests/utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/utils.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
 | 
			
		||||
def assert_equal_lists(l1, l2):
 | 
			
		||||
    assert sorted(l1) == sorted(l2)
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user