Esempio n. 1
0
 def test_get(self):
     """
     Test GET requests
     """
     request = self.factory.get(reverse('snippet_create'))
     request.user = self.user
     response = SnippetCreateView.as_view()(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context_data['user'], self.user)
     self.assertEqual(response.context_data['request'], request)
Esempio n. 2
0
    def test_post(self):
        """
        Test post requests
        """
        # Create the request
        data = {
            'title': 'My snippet',
            'content': 'This is my snippet'
        }
        request = self.factory.post(reverse('snippet_create'), data)
        request.user = self.user

        # Get the response
        response = SnippetCreateView.as_view()(request)
        self.assertEqual(response.status_code, 302)

        # Check save was called
        self.assertTrue(Snippet.save.called)
        self.assertEqual(Snippet.save.call_count, 1)
Esempio n. 3
0
from django.conf.urls import patterns, url

from snippets.views import SnippetListView, SnippetCreateView, SnippetUpdateView, SnippetDetailView


# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('snippets.views',
    url('^$', SnippetCreateView.as_view(), name="snippet_create"),
    # This one is redundant!
    url('^create$', SnippetCreateView.as_view(), name="snippet_create_new"),
    url('^(?P<id>\d+)/$', SnippetDetailView.as_view(), name="snippet_detail"),
    url('^(?P<id>\d+)/edit$', SnippetUpdateView.as_view(), name="snippet_update"),
    url('^my-snippets/$', SnippetListView.as_view(), name="user_snippet_list")
)
Esempio n. 4
0
sitemaps = {
    'snippets': SnippetSiteMap
}

urlpatterns = patterns('',
    # Social integration
    url('', include('social.apps.django_app.urls', namespace='social')),

    # Auth
    url('', include('django.contrib.auth.urls', namespace='auth')),

    # Comments
    (r'^comments/', include('django_comments.urls')),

    # Index - create new snippet
    url(r'^$', login_required(SnippetCreateView.as_view(
        )), name='snippet_create'),

    # Individual posts
    url(r'^(?P<pub_date__year>\d{4})/(?P<pub_date__month>\d{1,2})/(?P<slug>[a-zA-Z0-9-]+)/?$', cache_page(900)(SnippetDetailView.as_view(
        )), name='snippet_detail'),

    # Login
    url(r'^accounts/login/?$', anonymous_required(LoginView.as_view(
        )), name='login'),

    # Sitemap
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
            name='django.contrib.sitemaps.views.sitemap'),
)