Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_blogposts_not_exceed_MAX_POSTS(self):
'''Posting blog-posts should not result in more than MAX_POSTS items stored.'''
for post in range(models.MAX_POSTS + 5):
form_data = {'title': 'This is post #%s' % post, 'content': 'This is the content of post #%s' % post}
request = self.factory.post('/blog-post', data=form_data)
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
view(request)
self.assertEquals(len(models.BlogPost.objects.all()),models.MAX_POSTS)
def test_get_to_root(self):
'''Simple get to the *root* url of blogposts'''
request = self.factory.get('/blog-post')
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
response = view(request)
self.assertEqual(response.status_code, 200)
def test_fifo_behaviour(self):
'''It's fine that the Blogposts are capped off at MAX_POSTS. But we want to make sure we see FIFO behaviour.'''
for post in range(15):
form_data = {'title': '%s' % post, 'content': 'This is the content of post #%s' % post}
request = self.factory.post('/blog-post', data=form_data)
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
view(request)
request = self.factory.get('/blog-post')
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
response = view(request)
response_posts = json.loads(response.content)
response_titles = [d['title'] for d in response_posts]
response_titles.reverse()
self.assertEquals(response_titles, ['%s' % i for i in range(models.MAX_POSTS - 5, models.MAX_POSTS + 5)])
from django.conf.urls.defaults import patterns, url
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from .resources import ColorResource
urlpatterns = patterns('',
url(r'^colors/$',
ListOrCreateModelView.as_view(resource=ColorResource),
name='todo-resources'),
url(r'^colors/(?P[0-9]+)$',
InstanceModelView.as_view(resource=ColorResource)),
)
from django.conf.urls.defaults import patterns, url
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from handlers import ProductResource
urlpatterns = patterns('',
url(r'^products/$', ListOrCreateModelView.as_view(resource=ProductResource)),
url(r'^product/(?P[^/]+)/$', InstanceModelView.as_view(resource=ProductResource)),
)
#-*- coding: utf-8 -*-
from django.conf.urls.defaults import patterns, url
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from dploi_server.resources import ApplicationConfigResource
from .resources import ApplicationResource
urlpatterns = patterns('',
url(r'^applications/$', ListOrCreateModelView.as_view(resource=ApplicationResource), name='application-resource-root'),
url(r'^applications/(?P[a-z0-9_]+)/$', InstanceModelView.as_view(resource=ApplicationResource)),
url(r'^applications/(?P[a-z0-9_]+)/config/$', InstanceModelView.as_view(resource=ApplicationConfigResource)),
)
def comments(self, instance):
return reverse('comments', kwargs={'blogpost': instance.key})
class CommentResource(ModelResource):
"""
A Comment is associated with a given Blog Post and has a *username* and *comment*, and optionally a *rating*.
"""
model = Comment
fields = ('username', 'comment', 'created', 'rating', 'url', 'blogpost')
ordering = ('-created',)
urlpatterns = patterns('',
url(r'^$', ListOrCreateModelView.as_view(resource=BlogPostResource), name='blog-posts-root'),
url(r'^(?P[^/]+)/$', InstanceModelView.as_view(resource=BlogPostResource)),
url(r'^(?P[^/]+)/comments/$', ListOrCreateModelView.as_view(resource=CommentResource), name='comments'),
url(r'^(?P[^/]+)/comments/(?P[^/]+)/$', InstanceModelView.as_view(resource=CommentResource)),
)
ThreadInstanceView.as_view(resource=ThreadResource)),
(r"^post/$",
PostListOrCreateView.as_view(resource=PostResource)),
(r"^post/(?P\w+)/$",
PostListOrCreateView.as_view(resource=PostResource)),
(r"^post/(?P\w+)/first/$",
PostListOrCreateView.as_view(resource=PostResource),
{"is_op_post": True}),
(r"^post/(?P\d+)$",
PostInstanceView.as_view(resource=PostResource)),
(r"^post/(?P\w+)/(?P\d+)$",
PostInstanceView.as_view(resource=PostResource)),
(r"^section/$",
ListOrCreateModelView.as_view(resource=SectionResource)),
(r"^section/(?P\d+)$",
InstanceModelView.as_view(resource=SectionResource)),
(r"^section/(?P\w+)",
InstanceModelView.as_view(resource=SectionResource)),
(r"^sectiongroup/",
ListOrCreateModelView.as_view(resource=SectionGroupResource)),
(r"^sectiongroup/(?P\d+)",
InstanceModelView.as_view(resource=SectionGroupResource)),
(r"^file/$",
ListOrCreateModelView.as_view(resource=FileResource)),
(r"^file/(?P\d+)$",
FileInstanceView.as_view(resource=FileResource)),
(r"^file/random_image/(?P\d{1,2})",
RandomImageView.as_view(resource=FileResource)),
from django.conf.urls.defaults import patterns, url
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from modelresourceexample.resources import MyModelResource
urlpatterns = patterns('',
url(r'^$', ListOrCreateModelView.as_view(resource=MyModelResource), name='model-resource-root'),
url(r'^(?P[0-9]+)/$', InstanceModelView.as_view(resource=MyModelResource)),
)