# Copyright 2008 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests that the combined appengine and Django models function correctly."""
from django import VERSION
from django.db.models import get_models
from django import forms
from google.appengine.ext.db import djangoforms
from google.appengine.ext import db
from appengine_django.models import BaseModel
from appengine_django.models import ModelManager
from appengine_django.models import ModelOptions
from appengine_django.models import RegistrationTestModel
"""Test model class for checking property -> Django field setup."""
property1 = db.StringProperty()
property2 = db.IntegerProperty()
property3 = db.Reference()
"""Unit tests for the combined model class."""
"""Tests that a combined model class has been registered with Django."""
self.assert_(RegistrationTestModel in get_models())
"""Tests that a combined model class still has datastore properties."""
"""Tests the parts of a model required by Django are correctly stubbed."""
# Django requires model options to be found at ._meta.
# Django requires a manager at .objects
# Django requires ._default_manager.
"""Tests that a combined model class has (faked) Django fields."""
fields = TestModelWithProperties._meta.local_fields
# Check each fake field has the minimal properties that Django needs.
for field in fields:
# The Django serialization code looks for rel to determine if the field
# is a relationship/reference to another model.
# serialize is required to tell Django to serialize the field.
if field.name == "property3":
# Extra checks for the Reference field.
# rel.field_name is used during serialization to find the field in the
# other model that this field is related to. This should always be
# 'key_name' for appengine models.
"""Tests that the options stub has the required properties by Django."""
# Django requires object_name and app_label for serialization output.
# The pk.name member is required during serialization for dealing with
# related fields.
# The many_to_many method is called by Django in the serialization code to
# find m2m relationships. m2m is not supported by the datastore.
"""Tests that the manager stub acts as Django would expect."""
# The serialization code calls model.objects.all() to retrieve all objects
# to serialize.
"""Tests that each model instance has a 'primary key' generated."""
obj = RegistrationTestModel(key_name="test")
pk = obj._get_pk_val()
new_obj = RegistrationTestModel.get(pk)
"""Tests that the Django ModelForm is being successfully patched."""