# -*- coding: utf-8 -*- from heinzel.core import models from heinzel.core import exceptions from heinzel.tests.utils import Fixture, runtests from model_examples import Car, Brand, Manufacturer, Driver, Key models.register([Manufacturer, Brand, Car, Driver, Key]) class BasicAssumptions(Fixture): def runTest(self): bmwgroup = Manufacturer(name="Bayerische Motoren Werke AG") bmwgroup.save() bmw = Brand(name="BMW") bmw.save() bmw.manufacturer = bmwgroup bmw3er = Car(name="3er") bmw7er = Car(name="7er") bmwX3 = Car(name="X3") bmw3er.save() bmw7er.save() bmwX3.save()
# encoding: utf-8 from utils import Fixture, runtests from heinzel.core.exceptions import DoesNotExist from heinzel.core import utils from model_examples import Actor, Movie, Car, Brand, Manufacturer, Driver, Key from heinzel.core import models models.register([Actor, Movie]) class TestSelectQuery(Fixture): def runTest(self): pass
# -*- coding: utf-8 -*- from utils import Fixture, runtests from heinzel.core.exceptions import DoesNotExist, SQLSyntaxError from heinzel.core import utils from model_examples import ( Actor, Movie, Car, Brand, Manufacturer, Driver, Key, Item ) from heinzel.core.sql.dml import (Avg, Max, Min, Count, Sum) from heinzel.core import models models.register([Actor, Movie, Item]) from heinzel.core.queries import storage as store class QuerySetBasics(Fixture): """ Demonstrate properties of QuerySets. """ def runTest(self): # Make some datasets shell, created = Movie.objects.create(title="Ghost in the shell") ghosts, created = Movie.objects.create(title="Ghost Rider") akira, created = Movie.objects.create(title="Akira") northstar, created = Movie.objects.create(title="Fist of the north star")
import unittest, os from heinzel.core import exceptions from utils import Fixture, runtests from heinzel import settings from heinzel.core.queries import storage as store # Import the models. from model_examples import (Picture, Tag, Actor, Movie, Car, Brand, Manufacturer, Driver, Key, Item) # Register models, so their relations can be set up and syncdb can do its job. from heinzel.core import models models.register([Picture, Tag, Actor, Movie, Item]) class CullTest(Fixture): """ The cache culls entries once it has reached it's max size. """ def setUp(self): store._cache.max_size = 10 super(CullTest, self).setUp() def tearDown(self): store._cache.max_size = settings.MAX_CACHE
where ‘fieldname‘ is the attribute name of the RelationField and ‘model‘ is the primary model where it is defined. """ import unittest, os from heinzel.core import models from heinzel.core import exceptions from utils import Fixture, runtests # Import the models. from model_examples import Character, Party, Address, Location, Country, TraitSheet, Title, MALE, FEMALE, NEUTRAL # Register models, so their relations can be set up and syncdb can do its job. models.register([Character, Party, Address, Location, Country, TraitSheet, Title]) class GrandUnifiedRelationsTest(Fixture): """Test some rather complex models.""" def runTest(self): # Imagine some kind of role playing game # Player Herrmann herman = Character(firstname="Herrmann", lastname="von Fintel", age=18, sex=MALE, height=185, weight=85).save()[ 0 ] hermanstraits = TraitSheet( max_hitpoints=16, experience=5, level=0, agility=10, strength=12, intelligence=105
# encoding: utf-8 from utils import Fixture, runtests from heinzel.core.exceptions import DoesNotExist, DatabaseSanityError from heinzel.core import utils from model_examples import (Actor, Movie, UniqueTitleMovie, Car, Brand, Manufacturer, Driver, Key) from heinzel.core import models models.register([Actor, Movie, UniqueTitleMovie]) # only imported for verifying QuerySet results from heinzel.core.queries import storage as store from heinzel.core.info import get_inst_info class Debug(Fixture): def runTest(self): print "-------------------------hi-------------------" for i in xrange(20): m = Movie(title="Debug %s" %i) m.save() qs = Movie.objects.filter(title__startswith="Debug")
# -*- coding: utf-8 -*- """Please see file ‘test_relations‘ for an explanation of what's being tested below.""" from utils import Fixture, runtests from model_examples import Book, ISBN from heinzel.core import models models.register([Book, ISBN]) class populate(Fixture): def runTest(self): redstar = Book(title="Red Star over China") redstar.save() star_isbn = ISBN(code="1234567890123") star_isbn.save() redstar.isbn = star_isbn xdhycd = Book(title=u"现代汉语词典") xdhycd.save() xdhycd_isbn = ISBN(code="4564564564561") xdhycd_isbn.save()
from heinzel.core import models from heinzel.core.utils import datetime_localize class Car(models.Model): name = models.TextField(max_length=100, initial="Bug") depreciation_total = models.FloatField(initial=0.0) build_date = models.DatetimeField(initial=datetime.datetime.now) last_checkup = models.DatetimeField() # in the future, cars will have their own IP address, says everybody. ip_address = models.IPv6Field() models.register([Car]) class TestFieldInitial(Fixture): def runTest(self): bug = Car().save()[0] self.assert_(bug.name == "Bug") class TestFloatFieldInitial(Fixture): def runTest(self): bug = Car().save()[0] self.assert_(bug.depreciation_total == 0.0) class TestDatetimeField(Fixture):