I have some django-based app. Inside this app I have tests.py file. Inside this file I have two test classes:
# -*- coding: utf-8 -*-
from django.test import TestCase, RequestFactory
from django.contrib.auth.models import User
from translations import utils, views_ajax
from translations.models import Project
import json
def print_results(sentences):
for sent in sentences:
print "u\"" + sent + "\","
class TextSplitTest(TestCase):
maxDiff = None
def test_en_split(self):
# some actions
sentences, marked_text, count_num = utils.split_text(text_to_split, 'en')
self.assertEqual(sentences, good_result)
def test_fr_split(self):
# some actions
sentences, marked_text, count_num = utils.split_text(text_to_split, 'ru')
self.assertEqual(sentences, good_result)
def test_zh_split(self):
# some actions
sentences, marked_text, count_num = utils.split_text(text_to_split, 'zh')
self.assertEqual(sentences, good_result)
def test_es_split(self):
# some actions
sentences, marked_text, count_num = utils.split_text(text_to_split, 'es')
# print_results(sentences)
self.assertEqual(sentences, good_result)
class CreateProjectTest(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.user = User.objects.create_user(username='jacob', email='jacob@gmail.com', password='top_secret')
def create_project(self):
request = self.factory.post('/api/project-create/',
data=json.dumps({'name': 4321, 'description': "ololo", 'type': "public"}),
content_type='application/json')
request.user = self.user
response = views_ajax.create_project_ajax(request)
all_user_projects = Project.objects.filter(manager=self.user)
self.assertEqual(len(all_user_projects), 1)
self.assertEqual(response.status_code, 200)
def add_text_to_project(self):
project = Project.objects.get(manager=self.user, name='4321')
data = json.dumps({"project":project.id,
"title":"French test",
"subject":1,
"sourceLang":7,
"targetLang":2,
"textBody":"Some text"})
request = self.factory.post('/api/text/', data=data, content_type='application/json')
request.user = self.user
response = views_ajax.text_ajax(request)
self.assertEqual(response.status_code, 200)
But when I'm trying to start tests, I'm getting:
# python manage.py test -v 2
...
test_basic_addition (entries.tests.SimpleTest) ... ok
test_en_split (translations.tests.TextSplitTest) ... ok
test_es_split (translations.tests.TextSplitTest) ... ok
test_fr_split (translations.tests.TextSplitTest) ... ok
test_ru_split (translations.tests.TextSplitTest) ... ok
test_zh_split (translations.tests.TextSplitTest) ... ok
----------------------------------------------------------------------
Ran 6 tests in 0.224s
OK
And when I'm trying to start exact test class:
# python manage.py test translations.tests.CreateProjectTest -v 2
...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Why django ignores some tests? I've tried to google it out, but get nothing:(
Aucun commentaire:
Enregistrer un commentaire