Skip to content

Commit

Permalink
change some fields of the sample publisher model to nullable; add mig…
Browse files Browse the repository at this point in the history
…rations; add test which reproduces the issue raised by peter uittenbroek; issue to be solved later
  • Loading branch information
barseghyanartur committed Jul 14, 2017
1 parent d1f06b6 commit 3fc089b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
35 changes: 35 additions & 0 deletions examples/simple/books/migrations/0016_auto_20170714_1020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-07-14 15:20
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('books', '0015_auto_20170713_0418'),
]

operations = [
migrations.AlterField(
model_name='publisher',
name='address',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='publisher',
name='city',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='publisher',
name='country',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='publisher',
name='state_province',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
8 changes: 4 additions & 4 deletions examples/simple/books/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class Publisher(models.Model):

name = models.CharField(max_length=30)
info = models.TextField(null=True, blank=True)
address = models.CharField(max_length=255)
city = models.CharField(max_length=255)
state_province = models.CharField(max_length=255)
country = models.CharField(max_length=255)
address = models.CharField(max_length=255, null=True, blank=True)
city = models.CharField(max_length=255, null=True, blank=True)
state_province = models.CharField(max_length=255, null=True, blank=True)
country = models.CharField(max_length=255, null=True, blank=True)
website = models.URLField()

# This does not cause a model change
Expand Down
56 changes: 54 additions & 2 deletions src/rest_framework_tricks/tests/test_nested_proxy_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,40 @@ def _nested_proxy_field_model_serializer(self, url=None):
data['address_information'].get(__key)
)

def _nested_proxy_field_model_serializer_missing_all_nested_fields(
self, url=None
):
"""Test NestedProxyField and ModelSerializer.
All nested fields are missing.
"""
# TODO: At the moment, if `address_information` is totally missing,
# it fails. Adding even empty `address_information` helps.
# This needs to be solved.
data = {
'name': self.faker.text(max_nb_chars=30),
'info': self.faker.text(),
'website': self.faker.url(),
# 'address_information': {
# 'address': self.faker.address(),
# 'city': self.faker.city(),
# 'state_province': self.faker.state(),
# 'country': self.faker.country()
# }
}

response = self.get_client_action()(url, data, format='json')

self.assertEqual(response.status_code, self.get_status_code())
for __key in ('name', 'info', 'website'):
self.assertEqual(response.data.get(__key), data.get(__key))

# for __key in ('address', 'city', 'state_province', 'country'):
# self.assertEqual(
# response.data['address_information'].get(__key),
# data['address_information'].get(__key)
# )

def _nested_proxy_field_model_serializer_depth(self, url=None):
"""Test NestedProxyField and ModelSerializer with more depth."""
data = {
Expand Down Expand Up @@ -503,6 +537,14 @@ def test_nested_proxy_field_model_serializer(self):
self.publisher_listing_url
)

def test_nested_proxy_field_model_serializer_missing_all_nested_fields(
self
):
"""Test NestedProxyField and ModelSerializer."""
self._nested_proxy_field_model_serializer_missing_all_nested_fields(
self.publisher_listing_url
)


@pytest.mark.django_db
class TestNestedProxyFieldUpdateAction(TestNestedProxyFieldActionBase):
Expand Down Expand Up @@ -569,6 +611,14 @@ def test_nested_proxy_field_model_serializer(self):
self.publisher_detail_url
)

def test_nested_proxy_field_model_serializer_missing_all_nested_fields(
self
):
"""Test NestedProxyField and ModelSerializer."""
self._nested_proxy_field_model_serializer_missing_all_nested_fields(
self.publisher_detail_url
)

def test_nested_proxy_field_model_serializer_depth(self):
"""Test NestedProxyField and ModelSerializer with more depth."""
self._nested_proxy_field_model_serializer_depth(
Expand Down Expand Up @@ -613,9 +663,11 @@ def test_nested_proxy_field_model_serializer_depth_more_missing_fields(
self.profile_detail_url
)

def test_nested_proxy_field_model_serializer(self):
def test_nested_proxy_field_model_serializer_missing_all_nested_fields(
self
):
"""Test NestedProxyField and ModelSerializer."""
self._nested_proxy_field_model_serializer(
self._nested_proxy_field_model_serializer_missing_all_nested_fields(
self.publisher_detail_url
)

Expand Down

0 comments on commit 3fc089b

Please sign in to comment.