Browse files

ticket3: pep8, named url, 10 first, test <10 request

  • Loading branch information...
1 parent c980321 commit c52e8b2ebb8e963163ae00ec6df9dc5c22777932 @andreysobol committed Mar 11, 2012
View
3 testsobol/mainapp/middleware.py
@@ -2,8 +2,9 @@
from models import Request
+
class RequestMiddleware(object):
-
+
def process_request(self, request):
r = Request()
r.date = datetime.now()
View
1 testsobol/mainapp/models.py
@@ -11,6 +11,7 @@ class Bio(models.Model):
other = models.TextField()
bio = models.TextField()
+
class Request(models.Model):
date = models.DateTimeField()
url = models.CharField(max_length=250)
View
25 testsobol/mainapp/tests.py
@@ -29,7 +29,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):
@@ -38,3 +42,22 @@ def test(self):
page = self.client.get('/http/')
self.assertEqual(page.status_code, 200)
self.assertTrue(bool(page.context['request']))
+
+
+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)
View
3 testsobol/mainapp/views.py
@@ -12,11 +12,12 @@ def get_context_data(self, **kwargs):
super(Index, self).get_context_data(**kwargs)
return model_to_dict(Bio.objects.get(pk=1))
+
class Http(ListView):
context_object_name = 'request'
template_name = 'http.html'
paginate_by = 10
def get_queryset(self):
- return Request.objects.order_by('-date')
+ return Request.objects.order_by('date')
View
2 testsobol/templates/index.html
@@ -24,5 +24,5 @@
</div>
</div>
<div class="clear"></div>
- <a href="/http/">request</a>
+ <a href="{% url http %}">request</a>
{% endblock %}
View
2 testsobol/urls.py
@@ -8,7 +8,7 @@
urlpatterns = patterns('',
# Examples:
url(r'^$', Index.as_view()),
- url(r'^http/$', Http.as_view()),
+ url(r'^http/$', Http.as_view(), name="http"),
# url(r'^testsobol/', include('testsobol.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:

0 comments on commit c52e8b2

Please sign in to comment.