Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
9e291879
Commit
9e291879
authored
Mar 06, 2014
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an optional unique field to Album and checked that duplicates are detected.
parent
ef94861c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
3 deletions
+6
-3
rest_framework/tests/models.py
+1
-1
rest_framework/tests/test_serializer.py
+5
-2
No files found.
rest_framework/tests/models.py
View file @
9e291879
...
...
@@ -103,7 +103,7 @@ class BlogPostComment(RESTFrameworkModel):
class
Album
(
RESTFrameworkModel
):
title
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
ref
=
models
.
CharField
(
max_length
=
10
,
unique
=
True
,
null
=
True
,
blank
=
True
)
class
Photo
(
RESTFrameworkModel
):
description
=
models
.
TextField
()
...
...
rest_framework/tests/test_serializer.py
View file @
9e291879
...
...
@@ -611,12 +611,15 @@ class ModelValidationTests(TestCase):
"""
Just check if serializers.ModelSerializer handles unique checks via .full_clean()
"""
serializer
=
AlbumsSerializer
(
data
=
{
'title'
:
'a'
})
serializer
=
AlbumsSerializer
(
data
=
{
'title'
:
'a'
,
'ref'
:
'1'
})
serializer
.
is_valid
()
serializer
.
save
()
second_serializer
=
AlbumsSerializer
(
data
=
{
'title'
:
'a'
})
self
.
assertFalse
(
second_serializer
.
is_valid
())
self
.
assertEqual
(
second_serializer
.
errors
,
{
'title'
:
[
'Album with this Title already exists.'
]})
self
.
assertEqual
(
second_serializer
.
errors
,
{
'title'
:
[
'Album with this Title already exists.'
],})
third_serializer
=
AlbumsSerializer
(
data
=
{
'title'
:
'b'
,
'ref'
:
'1'
})
self
.
assertFalse
(
third_serializer
.
is_valid
())
self
.
assertEqual
(
third_serializer
.
errors
,
{
'ref'
:
[
'Album with this Ref already exists.'
],})
def
test_foreign_key_is_null_with_partial
(
self
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment