Commits

H3n0xek committed cf7899b

URLs for tests

  • Participants
  • Parent commits 98fb177
  • Branches tests

Comments (0)

Files changed (2)

diario/tests/urls.py

+# -*- coding: utf-8 -*-
+#
+#  Copyright (c) 2008-2012 Guilherme Gondim and contributors
+#
+#  This file is part of Django Diario.
+#
+#  Django Diario is free software under terms of the GNU Lesser
+#  General Public License version 3 (LGPLv3) as published by the Free
+#  Software Foundation. See the file README for copying conditions.
+#
+'''This module contains URLs used with built-in diario tests'''
+
+from django.conf.urls import patterns, include, url
+from diario.views.entries import BaseEntryDetailView, BaseEntryListView
+from django.conf import settings
+from django.db.models import get_model
+
+# Retrieve user entry class from settings
+# EntryClassStr must be a string in format 'applabel.modelname'
+EntryClassStr = getattr(settings, 'DIARIO_TEST_ENTRY_MODEL', None)
+if EntryClassStr is None:
+    raise ImproperlyConfigured("You must specify DIARIO_TEST_ENTRY_MODEL in your project settings to launch tests")
+entry_app, entry_model = EntryClassStr.split('.')
+EntryModel = get_model(entry_app, entry_model)
+if EntryModel is None:
+    raise "Fatal error: Couldn't find a model to test with. Looked for %s" % EntryClassStr
+
+    
+class TestEntryDetailView(BaseEntryDetailView):
+    model = EntryModel
+    
+class TestEntryListView(BaseEntryListView):
+    model = EntryModel
+
+urlpatterns = patterns('',    
+    url(r'^$', TestEntryListView.as_view(), name='diario-entry-list'),
+    url(
+        r'^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
+        TestEntryDetailView.as_view(),
+        name='diario-entry-detail'
+    ),
+)

diario/tests/views.py

 
 
 def is_reverse_exists(name, *args, **kwargs):
+    '''Check whether there is any defined URL matching viewname'''
+    
     try:
         reverse(name, args=args, kwargs=kwargs)
         return True
         return False
 
 
-class TestList(TestCase):    
+class TestList(TestCase):  
+    urls = 'diario.tests.urls'
 
     def setUp(self):
         self.c = Client()