test_models.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:gthnk 作者: iandennismiller 项目源码 文件源码
def test_crud(self):
        "Go through CRUD operations to exercise the models."
        # test create
        day = Day.create(date=datetime.date.today())
        self.assertIsNotNone(day, "Day is created")

        entry = Entry.create(day=day, content="empty", timestamp=datetime.datetime.now())
        self.assertIsNotNone(entry, "Entry is created")

        # attach an image to a day
        with open("gthnk/tests/data/gthnk-big.jpg", "rb") as f:
            buf = six.BytesIO(f.read())
            page = day.attach(buf.getvalue())
            self.assertIsNotNone(page, "Page is created")

        # test read
        day_find = Day.find(date=datetime.date.today())
        self.assertIsNotNone(day_find, "Day can be retrieved")
        self.assertEqual(day_find.entries[0].content, "empty", "contains correct value")

        entry_find = Entry.find(content="empty")
        self.assertIsNotNone(entry_find, "Entry can be retrieved")
        self.assertEqual(entry_find.content, "empty", "contains correct value")

    # special testing for Page class
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号