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
b361c54c
Commit
b361c54c
authored
Sep 19, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test rejigging
parent
c0150e61
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
71 deletions
+75
-71
tests/test_model_serializer.py
+5
-0
tests/test_modelinfo.py
+0
-31
tests/test_templatetags.py
+35
-0
tests/test_urlizer.py
+0
-37
tests/test_utils.py
+35
-3
No files found.
tests/test_model_serializer.py
View file @
b361c54c
...
@@ -24,6 +24,9 @@ class CustomField(models.Field):
...
@@ -24,6 +24,9 @@ class CustomField(models.Field):
pass
pass
COLOR_CHOICES
=
((
'red'
,
'Red'
),
(
'blue'
,
'Blue'
),
(
'green'
,
'Green'
))
class
RegularFieldsModel
(
models
.
Model
):
class
RegularFieldsModel
(
models
.
Model
):
"""
"""
A model class for testing regular flat fields.
A model class for testing regular flat fields.
...
@@ -32,6 +35,7 @@ class RegularFieldsModel(models.Model):
...
@@ -32,6 +35,7 @@ class RegularFieldsModel(models.Model):
big_integer_field
=
models
.
BigIntegerField
()
big_integer_field
=
models
.
BigIntegerField
()
boolean_field
=
models
.
BooleanField
(
default
=
False
)
boolean_field
=
models
.
BooleanField
(
default
=
False
)
char_field
=
models
.
CharField
(
max_length
=
100
)
char_field
=
models
.
CharField
(
max_length
=
100
)
choices_field
=
models
.
CharField
(
max_length
=
100
,
choices
=
COLOR_CHOICES
)
comma_seperated_integer_field
=
models
.
CommaSeparatedIntegerField
(
max_length
=
100
)
comma_seperated_integer_field
=
models
.
CommaSeparatedIntegerField
(
max_length
=
100
)
date_field
=
models
.
DateField
()
date_field
=
models
.
DateField
()
datetime_field
=
models
.
DateTimeField
()
datetime_field
=
models
.
DateTimeField
()
...
@@ -68,6 +72,7 @@ class TestRegularFieldMappings(TestCase):
...
@@ -68,6 +72,7 @@ class TestRegularFieldMappings(TestCase):
big_integer_field = IntegerField()
big_integer_field = IntegerField()
boolean_field = BooleanField(default=False)
boolean_field = BooleanField(default=False)
char_field = CharField(max_length=100)
char_field = CharField(max_length=100)
choices_field = ChoiceField(choices=[('red', 'Red'), ('blue', 'Blue'), ('green', 'Green')])
comma_seperated_integer_field = CharField(max_length=100, validators=[<django.core.validators.RegexValidator object>])
comma_seperated_integer_field = CharField(max_length=100, validators=[<django.core.validators.RegexValidator object>])
date_field = DateField()
date_field = DateField()
datetime_field = DateTimeField()
datetime_field = DateTimeField()
...
...
tests/test_modelinfo.py
deleted
100644 → 0
View file @
c0150e61
from
django.test
import
TestCase
from
django.utils
import
six
from
rest_framework.utils.model_meta
import
_resolve_model
from
tests.models
import
BasicModel
class
ResolveModelTests
(
TestCase
):
"""
`_resolve_model` should return a Django model class given the
provided argument is a Django model class itself, or a properly
formatted string representation of one.
"""
def
test_resolve_django_model
(
self
):
resolved_model
=
_resolve_model
(
BasicModel
)
self
.
assertEqual
(
resolved_model
,
BasicModel
)
def
test_resolve_string_representation
(
self
):
resolved_model
=
_resolve_model
(
'tests.BasicModel'
)
self
.
assertEqual
(
resolved_model
,
BasicModel
)
def
test_resolve_unicode_representation
(
self
):
resolved_model
=
_resolve_model
(
six
.
text_type
(
'tests.BasicModel'
))
self
.
assertEqual
(
resolved_model
,
BasicModel
)
def
test_resolve_non_django_model
(
self
):
with
self
.
assertRaises
(
ValueError
):
_resolve_model
(
TestCase
)
def
test_resolve_improper_string_representation
(
self
):
with
self
.
assertRaises
(
ValueError
):
_resolve_model
(
'BasicModel'
)
tests/test_templatetags.py
View file @
b361c54c
...
@@ -4,6 +4,7 @@ from django.test import TestCase
...
@@ -4,6 +4,7 @@ from django.test import TestCase
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.templatetags.rest_framework
import
add_query_param
,
urlize_quoted_links
from
rest_framework.templatetags.rest_framework
import
add_query_param
,
urlize_quoted_links
factory
=
APIRequestFactory
()
factory
=
APIRequestFactory
()
...
@@ -49,3 +50,37 @@ class Issue1386Tests(TestCase):
...
@@ -49,3 +50,37 @@ class Issue1386Tests(TestCase):
# example from issue #1386, this shouldn't raise an exception
# example from issue #1386, this shouldn't raise an exception
urlize_quoted_links
(
"asdf:[/p]zxcv.com"
)
urlize_quoted_links
(
"asdf:[/p]zxcv.com"
)
class
URLizerTests
(
TestCase
):
"""
Test if both JSON and YAML URLs are transformed into links well
"""
def
_urlize_dict_check
(
self
,
data
):
"""
For all items in dict test assert that the value is urlized key
"""
for
original
,
urlized
in
data
.
items
():
assert
urlize_quoted_links
(
original
,
nofollow
=
False
)
==
urlized
def
test_json_with_url
(
self
):
"""
Test if JSON URLs are transformed into links well
"""
data
=
{}
data
[
'"url": "http://api/users/1/", '
]
=
\
'"url": "<a href="http://api/users/1/">http://api/users/1/</a>", '
data
[
'"foo_set": [
\n
"http://api/foos/1/"
\n
], '
]
=
\
'"foo_set": [
\n
"<a href="http://api/foos/1/">http://api/foos/1/</a>"
\n
], '
self
.
_urlize_dict_check
(
data
)
def
test_yaml_with_url
(
self
):
"""
Test if YAML URLs are transformed into links well
"""
data
=
{}
data
[
'''{users: 'http://api/users/'}'''
]
=
\
'''{users: '<a href="http://api/users/">http://api/users/</a>'}'''
data
[
'''foo_set: ['http://api/foos/1/']'''
]
=
\
'''foo_set: ['<a href="http://api/foos/1/">http://api/foos/1/</a>']'''
self
.
_urlize_dict_check
(
data
)
tests/test_urlizer.py
deleted
100644 → 0
View file @
c0150e61
from
__future__
import
unicode_literals
from
django.test
import
TestCase
from
rest_framework.templatetags.rest_framework
import
urlize_quoted_links
class
URLizerTests
(
TestCase
):
"""
Test if both JSON and YAML URLs are transformed into links well
"""
def
_urlize_dict_check
(
self
,
data
):
"""
For all items in dict test assert that the value is urlized key
"""
for
original
,
urlized
in
data
.
items
():
assert
urlize_quoted_links
(
original
,
nofollow
=
False
)
==
urlized
def
test_json_with_url
(
self
):
"""
Test if JSON URLs are transformed into links well
"""
data
=
{}
data
[
'"url": "http://api/users/1/", '
]
=
\
'"url": "<a href="http://api/users/1/">http://api/users/1/</a>", '
data
[
'"foo_set": [
\n
"http://api/foos/1/"
\n
], '
]
=
\
'"foo_set": [
\n
"<a href="http://api/foos/1/">http://api/foos/1/</a>"
\n
], '
self
.
_urlize_dict_check
(
data
)
def
test_yaml_with_url
(
self
):
"""
Test if YAML URLs are transformed into links well
"""
data
=
{}
data
[
'''{users: 'http://api/users/'}'''
]
=
\
'''{users: '<a href="http://api/users/">http://api/users/</a>'}'''
data
[
'''foo_set: ['http://api/foos/1/']'''
]
=
\
'''foo_set: ['<a href="http://api/foos/1/">http://api/foos/1/</a>']'''
self
.
_urlize_dict_check
(
data
)
tests/test_
breadcrumb
s.py
→
tests/test_
util
s.py
View file @
b361c54c
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.conf.urls
import
patterns
,
url
from
django.conf.urls
import
patterns
,
url
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.utils
import
six
from
rest_framework.utils.model_meta
import
_resolve_model
from
rest_framework.utils.breadcrumbs
import
get_breadcrumbs
from
rest_framework.utils.breadcrumbs
import
get_breadcrumbs
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
tests.models
import
BasicModel
class
Root
(
APIView
):
class
Root
(
APIView
):
...
@@ -24,6 +27,7 @@ class NestedResourceRoot(APIView):
...
@@ -24,6 +27,7 @@ class NestedResourceRoot(APIView):
class
NestedResourceInstance
(
APIView
):
class
NestedResourceInstance
(
APIView
):
pass
pass
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
''
,
''
,
url
(
r'^$'
,
Root
.
as_view
()),
url
(
r'^$'
,
Root
.
as_view
()),
...
@@ -35,9 +39,10 @@ urlpatterns = patterns(
...
@@ -35,9 +39,10 @@ urlpatterns = patterns(
class
BreadcrumbTests
(
TestCase
):
class
BreadcrumbTests
(
TestCase
):
"""Tests the breadcrumb functionality used by the HTML renderer."""
"""
Tests the breadcrumb functionality used by the HTML renderer.
urls
=
'tests.test_breadcrumbs'
"""
urls
=
'tests.test_utils'
def
test_root_breadcrumbs
(
self
):
def
test_root_breadcrumbs
(
self
):
url
=
'/'
url
=
'/'
...
@@ -98,3 +103,30 @@ class BreadcrumbTests(TestCase):
...
@@ -98,3 +103,30 @@ class BreadcrumbTests(TestCase):
get_breadcrumbs
(
url
),
get_breadcrumbs
(
url
),
[(
'Root'
,
'/'
)]
[(
'Root'
,
'/'
)]
)
)
class
ResolveModelTests
(
TestCase
):
"""
`_resolve_model` should return a Django model class given the
provided argument is a Django model class itself, or a properly
formatted string representation of one.
"""
def
test_resolve_django_model
(
self
):
resolved_model
=
_resolve_model
(
BasicModel
)
self
.
assertEqual
(
resolved_model
,
BasicModel
)
def
test_resolve_string_representation
(
self
):
resolved_model
=
_resolve_model
(
'tests.BasicModel'
)
self
.
assertEqual
(
resolved_model
,
BasicModel
)
def
test_resolve_unicode_representation
(
self
):
resolved_model
=
_resolve_model
(
six
.
text_type
(
'tests.BasicModel'
))
self
.
assertEqual
(
resolved_model
,
BasicModel
)
def
test_resolve_non_django_model
(
self
):
with
self
.
assertRaises
(
ValueError
):
_resolve_model
(
TestCase
)
def
test_resolve_improper_string_representation
(
self
):
with
self
.
assertRaises
(
ValueError
):
_resolve_model
(
'BasicModel'
)
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