首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有关系的fixture在app-engine-patch中能工作吗?

有关系的fixture在app-engine-patch中能工作吗?
EN

Stack Overflow用户
提问于 2009-10-31 09:56:20
回答 1查看 207关注 0票数 0

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

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

以下是涉及到的模型:

代码语言:javascript
复制
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如下所示:

代码语言:javascript
复制
[
{"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不能。我通过执行以下操作来检查:

代码语言:javascript
复制
books = BibleBook.gql('')
self.assertEquals(books.count(), 1)
tasks = Task.gql('')
self.assertEquals(tasks.count(), 1)

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

谢谢,

Brian Yamabe

EN

回答 1

Stack Overflow用户

发布于 2009-11-08 04:21:44

谢谢,塞洛普,你要额外的代码。我决定使用json文件,并通过对pk使用简单的数字来修复问题。以下是为我发布的模型和测试修复问题的JSON:

代码语言:javascript
复制
[
{"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"}}
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1653154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档