Commits

Mikhail Korobov committed 6978f36

немного тестов

Comments (0)

Files changed (4)

+#!/bin/sh
+
+default_tests='blog russian_admin'
+
+if [ $# -eq 0 ]
+then
+    ./test_project/manage.py test $default_tests
+else
+    ./test_project/manage.py test $* -v2
+fi

test_project/blog/tests.py

+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+from django_webtest import WebTest
+from django.contrib.auth.models import User
+
+class BaseTestCase(WebTest):
+    extra_environ = {'HTTP_ACCEPT_LANGUAGE': 'ru'}
+
+    def setUp(self):
+        self.user = User.objects.create_superuser('vasia', 'vasia@example.com', '123')
+
+    def admin_index(self):
+        return self.app.get('/admin/', user=self.user)
+
+    def assertHaveValue(self, response, selector, value):
+        values = []
+        for elem in response.lxml.cssselect(selector):
+            values.append(elem.text_content())
+        self.assertIn(value, values)
+
+
+class AppNameLocalizeTest(BaseTestCase):
+
+    def test_localized_blog(self):
+        page = self.admin_index()
+        self.assertHaveValue(page, '.dashboard-module-content h3', u'Блог')
+
+    def test_app_list_correct_template(self):
+        page = self.admin_index()
+        self.assertTemplateUsed(page, 'russian_admin/dashboard/modules/app_list.html')

test_project/requirements.txt

 # последняя (на 2011-08-12) версия django-admin-tools (с поддержкой django 1.3)
 # в версии с pypi (0.4) пришлось бы копировать статику в проект руками
 -e hg+https://bitbucket.org/izi/django-admin-tools@8bcc0fba2346#egg=django-admin-tools
+
+# для тестов:
+django-webtest >= 1.4.1
+lxml

test_project/settings.py

 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.locale.LocaleMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',