0

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

我正在使用“manage.py dumpdata --format=json >> 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)

夹具文件中的 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 模型正确加载,但 Task one 没有。我正在通过以下方式检查:

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

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

谢谢,

布莱恩·山部

4

1 回答 1

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"}}
]
于 2009-11-07T20:21:43.873 回答