Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 't2_request_middleware' into t4_settings_in_context

Conflicts:
	testsobol/mainapp/tests.py
  • Loading branch information...
commit bfa1afdb3d24f50bdf9b8447db6cb565c43c5620 2 parents de05c7e + c52e8b2
@andreysobol authored
View
2  testsobol/Makefile
@@ -0,0 +1,2 @@
+test:
+ python manage.py test mainapp
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
2  testsobol/mainapp/models.py
@@ -1,5 +1,6 @@
from django.db import models
+
class Bio(models.Model):
name = models.CharField(max_length=250)
surname = models.CharField(max_length=250)
@@ -10,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
34 testsobol/mainapp/tests.py
@@ -14,22 +14,26 @@
class IndexViewTest(TestCase):
def test(self):
- fixtures = ['initial_data.json']
- bio = Bio.objects.get(pk = 1)
+ bio = Bio.objects.get(pk=1)
page = self.client.get('')
self.assertEqual(page.status_code, 200)
- lines = ('name','surname','birth','email','jabber','skype','bio','other',)
+ lines = ('name', 'surname', 'birth', 'email',
+ 'jabber', 'skype', 'bio', 'other',)
for line in lines:
- self.assertEqual(page.context[line],getattr(bio,line))
+ self.assertEqual(page.context[line], getattr(bio, line))
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):
@@ -39,9 +43,29 @@ 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'])
+
+
+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
8 testsobol/mainapp/views.py
@@ -3,13 +3,15 @@
from models import Bio, Request
+
class Index(TemplateView):
template_name = 'index.html'
def get_context_data(self, **kwargs):
- context = super(Index, self).get_context_data(**kwargs)
- return model_to_dict(Bio.objects.get(pk = 1))
+ super(Index, self).get_context_data(**kwargs)
+ return model_to_dict(Bio.objects.get(pk=1))
+
class Http(ListView):
@@ -18,4 +20,4 @@ class Http(ListView):
paginate_by = 10
def get_queryset(self):
- return Request.objects.order_by('-date')
+ return Request.objects.order_by('date')
View
12 testsobol/settings.py
@@ -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': '',
}
}
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
4 testsobol/urls.py
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import patterns, include, url
+from django.conf.urls.defaults import patterns, url
from testsobol.mainapp.views import Index, Http
# Uncomment the next two lines to enable the admin:
@@ -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:
Please sign in to comment.
Something went wrong with that request. Please try again.