mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Skip UUID tests for Django 1.7
This commit is contained in:
parent
14e52ca974
commit
363bc4fbcc
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import uuid
|
||||
|
||||
import django
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -47,10 +48,10 @@ class ManyToManySource(RESTFrameworkModel):
|
|||
class ForeignKeyTarget(RESTFrameworkModel):
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
|
||||
class UUIDForeignKeyTarget(RESTFrameworkModel):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
||||
name = models.CharField(max_length=100)
|
||||
if django.VERSION > (1, 7):
|
||||
class UUIDForeignKeyTarget(RESTFrameworkModel):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
|
||||
class ForeignKeySource(RESTFrameworkModel):
|
||||
|
@ -68,13 +69,13 @@ class NullableForeignKeySource(RESTFrameworkModel):
|
|||
verbose_name='Optional target object',
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class NullableUUIDForeignKeySource(RESTFrameworkModel):
|
||||
name = models.CharField(max_length=100)
|
||||
target = models.ForeignKey(ForeignKeyTarget, null=True, blank=True,
|
||||
related_name='nullable_sources',
|
||||
verbose_name='Optional target object',
|
||||
on_delete=models.CASCADE)
|
||||
if django.VERSION > (1, 7):
|
||||
class NullableUUIDForeignKeySource(RESTFrameworkModel):
|
||||
name = models.CharField(max_length=100)
|
||||
target = models.ForeignKey(UUIDForeignKeyTarget, null=True, blank=True,
|
||||
related_name='nullable_sources',
|
||||
verbose_name='Optional target object',
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
|
||||
# OneToOne
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import django
|
||||
import pytest
|
||||
from django.test import TestCase
|
||||
from django.utils import six
|
||||
|
||||
from rest_framework import serializers
|
||||
from tests.models import (
|
||||
ForeignKeySource, ForeignKeyTarget, ManyToManySource, ManyToManyTarget,
|
||||
NullableForeignKeySource, NullableOneToOneSource,
|
||||
NullableUUIDForeignKeySource, OneToOneTarget, UUIDForeignKeyTarget
|
||||
NullableForeignKeySource, NullableOneToOneSource, OneToOneTarget
|
||||
)
|
||||
|
||||
if django.VERSION > (1, 7):
|
||||
from tests.models import (
|
||||
NullableUUIDForeignKeySource,
|
||||
UUIDForeignKeyTarget
|
||||
)
|
||||
|
||||
|
||||
# ManyToMany
|
||||
class ManyToManyTargetSerializer(serializers.ModelSerializer):
|
||||
|
@ -44,16 +51,17 @@ class NullableForeignKeySourceSerializer(serializers.ModelSerializer):
|
|||
fields = ('id', 'name', 'target')
|
||||
|
||||
|
||||
# Nullable UUIDForeignKey
|
||||
class NullableUUIDForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||
target = serializers.PrimaryKeyRelatedField(
|
||||
pk_field=serializers.UUIDField(),
|
||||
queryset=UUIDForeignKeyTarget.objects.all(),
|
||||
allow_null=True)
|
||||
if django.VERSION > (1, 7):
|
||||
# Nullable UUIDForeignKey
|
||||
class NullableUUIDForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||
target = serializers.PrimaryKeyRelatedField(
|
||||
pk_field=serializers.UUIDField(),
|
||||
queryset=UUIDForeignKeyTarget.objects.all(),
|
||||
allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = NullableUUIDForeignKeySource
|
||||
fields = ('id', 'name', 'target')
|
||||
class Meta:
|
||||
model = NullableUUIDForeignKeySource
|
||||
fields = ('id', 'name', 'target')
|
||||
|
||||
|
||||
# Nullable OneToOne
|
||||
|
@ -445,12 +453,14 @@ class PKNullableForeignKeyTests(TestCase):
|
|||
]
|
||||
self.assertEqual(serializer.data, expected)
|
||||
|
||||
@pytest.mark.skipif(django.VERSION < (1, 8), reason="UUIDField not available")
|
||||
def test_null_uuid_foreign_key_serializes_as_none(self):
|
||||
source = NullableUUIDForeignKeySource(name='Source')
|
||||
serializer = NullableUUIDForeignKeySourceSerializer(source)
|
||||
data = serializer.data
|
||||
self.assertEqual(data["target"], None)
|
||||
|
||||
@pytest.mark.skipif(django.VERSION < (1, 8), reason="UUIDField not available")
|
||||
def test_nullable_uuid_foreign_key_is_valid_when_none(self):
|
||||
data = {"name": "Source", "target": None}
|
||||
serializer = NullableUUIDForeignKeySourceSerializer(data=data)
|
||||
|
|
Loading…
Reference in New Issue
Block a user