Skip to content

Commit

Permalink
Added tests for serializer module
Browse files Browse the repository at this point in the history
  • Loading branch information
Relrin committed Nov 24, 2016
1 parent 20e17b1 commit 70d720d
Show file tree
Hide file tree
Showing 4 changed files with 780 additions and 9 deletions.
4 changes: 3 additions & 1 deletion aiorest_ws/db/orm/django/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def create(self, validated_data):
# Save many-to-many relationships after the instance is created.
if many_to_many:
for field_name, value in many_to_many.items():
setattr(instance, field_name, value)
field = getattr(instance, field_name)
field.add(*value)
instance.save()

return instance

Expand Down
8 changes: 4 additions & 4 deletions tests/db/orm/django/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ class CustomStringField(models.CharField):

class TestModelField(DjangoUnitTest):

class User(models.Model):
class Owner(models.Model):
name = CustomStringField(max_length=30)

class Meta:
Expand All @@ -845,7 +845,7 @@ class Car(models.Model):
name = models.CharField(max_length=30)
max_speed = models.FloatField(null=True, blank=True)
manufacturer = models.ForeignKey(
"test_django_model_field.User", related_name='cars'
"test_django_model_field.Owner", related_name='cars'
)

class Meta:
Expand All @@ -854,11 +854,11 @@ class Meta:
def __str__(self):
return '<Car(%s, %s)>' % (self.name, self.manufacturer)

models = (User, Car)
models = (Owner, Car)
apps = ('test_django_model_field', )

def test_to_internal_value(self):
model_field = self.User._meta.get_field('name')
model_field = self.Owner._meta.get_field('name')
instance = fields.ModelField(model_field, max_length=30)
self.assertEqual(instance.to_internal_value('data'), 'data')

Expand Down

0 comments on commit 70d720d

Please sign in to comment.