Source

django-cms-mycmsproject-toporojo / hvad / test_utils / fixtures.py

# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from hvad.test_utils.data import D1, D3, D2
from hvad.test_utils.project.app.models import Normal, Date, Standard


class Fixture(object):
    def create_fixtures(self):
        pass


class OneSingleTranslatedNormalMixin(Fixture):
    def create_fixtures(self):
        Normal.objects.language('en').create(
            shared_field='shared',
            translated_field='English'
        )
        super(OneSingleTranslatedNormalMixin, self).create_fixtures()


class TwoTranslatedNormalMixin(Fixture):
    def create_fixtures(self):
        en1 = Normal.objects.language('en').create(
            shared_field = 'Shared1',
            translated_field = 'English1',
        )
        ja1 = en1.translate('ja')
        ja1.translated_field = u'日本語一'
        ja1.save()
        
        en2 = Normal.objects.language('en').create(
            shared_field = 'Shared2',
            translated_field = 'English2',
        )
        ja2 = en2.translate('ja')
        ja2.translated_field = u'日本語二'
        ja2.save()
        super(TwoTranslatedNormalMixin, self).create_fixtures()


class SuperuserMixin(Fixture):
    def create_fixtures(self):
        su = User(
            email='admin@admin.com',
            is_staff=True,
            is_superuser=True,
            is_active=True,
            username='admin',
        )
        su.set_password('admin')
        su.save()
        super(SuperuserMixin, self).create_fixtures()


class DatesMixin(Fixture):
    def create_fixtures(self):
        en1 = Date.objects.language('en').create(shared_date=D1,
                                                translated_date=D3)
        ja1 = en1.translate('ja')
        ja1.translated_date = D2
        ja1.save()
        en2 = Date.objects.language('en').create(shared_date=D3,
                                                translated_date=D2)
        ja2 = en2.translate('ja')
        ja2.translated_date = D1
        ja2.save()
        en3 = Date.objects.language('en').create(shared_date=D2,
                                                translated_date=D1)
        ja3 = en3.translate('ja')
        ja3.translated_date = D3
        ja3.save()
        super(DatesMixin, self).create_fixtures()

class TwoNormalOneStandardMixin(Fixture):
    def create_fixtures(self):
        en = Normal.objects.language('en').create(
            shared_field='shared',
            translated_field='English'
        )
        ja = en.translate('ja')
        ja.translated_field = u'日本語'
        ja.save()
        Standard.objects.create(normal_field="normal", normal=en) 
        super(TwoNormalOneStandardMixin, self).create_fixtures()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.