def test_index_view(self):
        response = self.client.get(reverse('core:welcome'))

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Welcome To Django')
        environment_name = response.context.get('DJANGO_ENVIRONMENT_NAME',
                                                None)
        console(environment_name)
        self.assertTrue(environment_name in ['testing', 'development'])

        templates = list(map(lambda t: t.name, response.templates))
        self.assertTrue('core/welcome.html' in templates)
Пример #2
0
from django.db import connections
from django.test import TestCase

from modules.utils.console import console
from .base_models import Category, Member, Person, Post

console = console(source=__name__)


class BaseModelWithSoftDeleteTestCase(TestCase):
    """Unit tests of BaseModelWithSoftDelete"""
    @classmethod
    def setUpTestData(cls):
        with connections['default'].schema_editor() as schema_editor:
            schema_editor.create_model(Category)
            schema_editor.create_model(Post)
            schema_editor.create_model(Person)
            schema_editor.create_model(Member)

        cls.category = Category.objects.create(title='Python')
        cls.posts = [
            Post.objects.create(category=cls.category, title='Python post 1'),
            Post.objects.create(category=cls.category, title='Python post 2'),
        ]
        cls.people = [
            Person.objects.create(name='Person 1'),
            Person.objects.create(name='Person 2')
        ]
        cls.member = Member.objects.create(title='Membership')
        cls.member.members.add(*cls.people)