带有关系的灯具是否适用于app-engine-patch?

时间:2009-10-31 01:56:20

标签: django google-app-engine app-engine-patch

我有一个夹具,我正在使用多个模型进行测试。它 适用于基本模型,但无法为其创建实体 有关系的模型。这是app-engine-patch的已知限制还是我遗漏了 什么?我正在使用JSON作为夹具文件。

我正在使用'manage.py dumpdata --format = json>>创建fixture文件。 file.json'

以下是涉及的模型:

class BibleBook(db.Model):
    name = db.StringProperty(required=True)
    description = db.TextProperty(required=True)

class Task(db.Model):
    name = db.StringProperty(required=True)
    description = db.TextProperty(required=True)
    energy = db.IntegerProperty(default=1)
    focus = db.IntegerProperty(default=0)
    empathy = db.IntegerProperty(default=0)
    denarii = db.IntegerProperty(default=0)
    talents = db.IntegerProperty(default=0)
    experience = db.IntegerProperty(default=1)
    percent_per_task = db.IntegerProperty(default=5)
    bibleBook = db.ReferenceProperty(BibleBook)
    level = db.StringProperty(required=True, choices=set(["Catachumen", "Laymen", "Elder"]))
    drop_percentage = db.IntegerProperty(default=10)

fixture文件中的json如下所示:

[
{"pk": "ag5sYXctYW5kLWdvc3BlbHIcCxIWbGF3YW5kZ29zcGVsX2JpYmxlYm9vaxgDDA", 
 "model": "lawandgospel.biblebook", 
 "fields": {"name": "Luke", "description": "Description"}},

{"pk": "ag5sYXctYW5kLWdvc3BlbHIXCxIRbGF3YW5kZ29zcGVsX3Rhc2sYBQw",
 "model": "lawandgospel.task",
 "fields": {"empathy": 0, "name": "Study Luke", "level": "Catachumen", "energy": 1,
 "focus": 0, "experience": 1, "drop_percentage": 10, "talents": 0,
 "bibleBook": "ag5sYXctYW5kLWdvc3BlbHIcCxIWbGF3YW5kZ29zcGVsX2JpYmxlYm9vaxgDDA",
 "percent_per_task": 5, "denarii": 0, "description": "The Book of Luke"}}
]

BibleBook模型正确加载,但任务1没有。 我正在检查这个:

books = BibleBook.gql('')
self.assertEquals(books.count(), 1)
tasks = Task.gql('')
self.assertEquals(tasks.count(), 1)

第一次测试通过,但第二次没有。

谢谢,

Brian Yamabe

1 个答案:

答案 0 :(得分:1)

谢谢,celopes,要求提供额外的代码。我决定使用json文件并通过使用pk的简单数字来解决问题。这是修复我发布的模型和测试问题的JSON:

[
{"pk": "1",
 "model": "lawandgospel.biblebook",
 "fields": {"name": "Luke", "description": "The Gospel According to St. Luke."}},

{"pk": "2",
 "model": "lawandgospel.task",
 "fields": {"empathy": 0, "name": "Study the Gospel of Luke", "level": "Catachumen",
 "energy": 1, "focus": 0, "experience": 1, "drop_percentage": 10, "talents": 0,
 "bibleBook": "1", "percent_per_task": 5, "denarii": 0,
 "description": "The Book of Luke"}}
]