Exemple #1
0
    def convert_dict_to_model(node):
        item = Item(**node)

        item.__dict__.update(**node)

        item.available = False

        # make sure description is a string, not None
        item.description = item.description or ""

        item.extra_fields = _make_extra_fields_value(
            item._meta.get_field_names(), node)

        return item
Exemple #2
0
    def test_writes_db_to_archive(self):
        with tempfile.NamedTemporaryFile() as zffobj:
            zf = zipfile.ZipFile(zffobj, "w")

            with tempfile.NamedTemporaryFile() as dbfobj:
                db = SqliteDatabase(dbfobj.name)
                db.connect()
                with Using(db, [Item]):
                    Item.create_table()
                    item = Item(id="test",
                                title="test",
                                description="test",
                                available=False,
                                slug="srug",
                                kind=NodeType.video,
                                path="/test/test")
                    item.save()
                db.close()

                save_db(db, zf)

            zf.close()

            # reopen the db from the zip, see if our object was saved
            with tempfile.NamedTemporaryFile() as f:
                # we should only have one file in the zipfile, the db. Assume
                # that the first file is the db.
                zf = zipfile.ZipFile(zffobj.name)
                dbfobj = zf.open(zf.infolist()[0])
                f.write(dbfobj.read())
                f.seek(0)

                db = SqliteDatabase(f.name)

                with Using(db, [Item]):
                    Item.get(title="test")