Permalink
Browse files

Merge branch 't4_settings_in_context' into t5_forms_and_auth

Conflicts:
	testsobol/mainapp/models.py
	testsobol/mainapp/tests.py
	testsobol/mainapp/views.py
	testsobol/templates/index.html
	testsobol/urls.py
  • Loading branch information...
2 parents 1537a88 + 512e72f commit 3a44bf4b611f1848682d636e3ccf033fd157ef5b @andreysobol committed Mar 11, 2012
View
@@ -0,0 +1,2 @@
+test:
+ python manage.py test mainapp
@@ -1,4 +1,5 @@
from django.conf import settings
+
def settings_context_processor(request):
- return {'settings':settings}
+ return {'settings': settings}
@@ -2,8 +2,9 @@
from models import Request
+
class RequestMiddleware(object):
-
+
def process_request(self, request):
r = Request()
r.date = datetime.now()
@@ -20,6 +20,7 @@ def render(self):
return self.get_struct(get)
+
class Request(models.Model):
date = models.DateTimeField()
url = models.CharField(max_length=250)
View
@@ -15,8 +15,6 @@
class IndexViewTest(TestCase):
def test(self):
- fixtures = ['initial_data.json']
-
page = self.client.get('')
self.assertEqual(page.status_code, 200)
@@ -30,7 +28,11 @@ class RequestTest(TestCase):
def test(self):
page = self.client.get('')
- self.assertTrue(bool(Request.objects.filter(date__gte = (datetime.now() - timedelta(minutes=1)))))
+
+ self.assertEqual(page.status_code, 200)
+
+ self.assertTrue(bool(Request.objects.filter(
+ date__gte=(datetime.now() - timedelta(minutes=1)))))
class RequestViewTest(TestCase):
@@ -40,12 +42,14 @@ def test(self):
self.assertEqual(page.status_code, 200)
self.assertTrue(bool(page.context['request']))
+
class SettingsContextTest(TestCase):
-
+
def test(self):
page = self.client.get('')
self.assertEqual(page.status_code, 200)
self.assertTrue(page.context['settings'])
+ self.assertEqual(page.context['settings'].STATIC_URL, '/static/')
class Edit(TestCase):
@@ -63,3 +67,22 @@ def test(self):
page = self.client.post('/edit/', {"bio": "Noooooooooooooo", "surname": "Sobol", "name": "Andrey", "other": "pigeon post - white pigeon only"})
self.assertEqual(page.status_code, 200)
self.assertTrue(page.content.find("error") != -1)
+
+
+class NameUrlTest(TestCase):
+
+ def test(self):
+ page = self.client.get('/')
+ self.assertEqual(page.status_code, 200)
+ self.assertTrue(page.content.find('a href="/http/"') != -1)
+
+
+class ManyRequestTest(TestCase):
+
+ def test(self):
+ for t in range(11):
+ page = self.client.get('/')
+ self.assertEqual(page.status_code, 200)
+
+ page = self.client.get('/http/')
+ self.assertTrue(page.context['request'].count() == 10)
@@ -8,12 +8,13 @@
from models import Bio, Request
from forms import BioForm
+
class Index(TemplateView):
template_name = 'index.html'
def get_context_data(self, **kwargs):
- context = super(Index, self).get_context_data(**kwargs)
+ super(Index, self).get_context_data(**kwargs)
return {'renders':Bio.objects.get(pk = 1).render()}
@@ -52,4 +53,4 @@ class Http(ListView):
paginate_by = 10
def get_queryset(self):
- return Request.objects.order_by('-date')
+ return Request.objects.order_by('date')
View
@@ -13,12 +13,12 @@
DATABASES = {
'default': {
- 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': 'db.sqlite3', # Or path to database file if using sqlite3.
- 'USER': '', # Not used with sqlite3.
- 'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': 'db.sqlite3',
+ 'USER': '',
+ 'PASSWORD': '',
+ 'HOST': '',
+ 'PORT': '',
}
}
@@ -51,7 +51,7 @@
{% else %}
<a href="/edit/">login and edit</a>
{% endif %}
- <a href="/http/">request</a>
+ <a href="{% url http %}">request</a>
</div>
{% endif %}
{% endblock %}
View
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns, include, url
+from django.conf.urls.defaults import patterns, url
from django.conf import settings
from testsobol.mainapp.views import Index, Http, Edit
@@ -10,7 +10,7 @@
# Examples:
url(r'^$', Index.as_view()),
url(r'^edit/$', Edit.as_view()),
- url(r'^http/$', Http.as_view()),
+ url(r'^http/$', Http.as_view(), name="http"),
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
(r'^accounts/login/$', 'django.contrib.auth.views.login', { "template_name": "admin/login.html" } ),

0 comments on commit 3a44bf4

Please sign in to comment.