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
3e6f99e2
Commit
3e6f99e2
authored
Feb 25, 2013
by
Danilo Bargen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved exception message for missing serializer model meta option
parent
8da83f0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
rest_framework/serializers.py
+2
-0
rest_framework/tests/serializer.py
+17
-0
No files found.
rest_framework/serializers.py
View file @
3e6f99e2
...
...
@@ -424,6 +424,8 @@ class ModelSerializer(Serializer):
"""
cls
=
self
.
opts
.
model
if
cls
is
None
:
raise
AttributeError
(
"Serializer class is missing 'model' Meta option"
)
opts
=
get_concrete_model
(
cls
)
.
_meta
pk_field
=
opts
.
pk
# while pk_field.rel:
...
...
rest_framework/tests/serializer.py
View file @
3e6f99e2
...
...
@@ -91,6 +91,11 @@ class PositiveIntegerAsChoiceSerializer(serializers.ModelSerializer):
fields
=
[
'some_integer'
]
class
BrokenModelSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
fields
=
[
'some_field'
]
class
BasicTests
(
TestCase
):
def
setUp
(
self
):
self
.
comment
=
Comment
(
...
...
@@ -353,6 +358,18 @@ class ValidationTests(TestCase):
self
.
assertIn
(
'created'
,
serializer
.
errors
)
def
test_missing_model_field_exception_msg
(
self
):
"""
Assert that a meaningful exception message is outputted when the model
field is missing (e.g. when mistyping ``model``).
"""
try
:
serializer
=
BrokenModelSerializer
()
except
AttributeError
as
e
:
self
.
assertEquals
(
e
.
args
[
0
],
"Serializer class is missing 'model' Meta option"
)
except
:
self
.
fail
(
'Wrong exception type thrown.'
)
class
CustomValidationTests
(
TestCase
):
class
CommentSerializerWithFieldValidator
(
CommentSerializer
):
...
...
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