예제 #1
0
파일: export.py 프로젝트: xeila00/markovbot
    def test_import_single(self):
        structure = {
            "person:id": dict(_id="person:id", seq=11),
            "account:id": dict(_id="account:id", seq=33)
        }
        data = json.dumps(structure)
        data = appier.legacy.bytes(data)

        adapter = appier.get_adapter()
        manager = appier.ExportManager(adapter, multiple=self.app.resolve())

        collection = adapter.collection("counter")
        manager._import_single(collection, data, key="_id")

        values = collection.find()
        values = [value for value in values]

        self.assertEqual(type(values), list)
        self.assertEqual(len(values), 2)

        value = collection.find_one(dict(_id="person:id"))

        self.assertEqual(value["seq"], 11)
예제 #2
0
파일: export.py 프로젝트: xeila00/markovbot
    def test_import_multiple(self):
        data = [("person:id",
                 appier.legacy.bytes(json.dumps(dict(_id="person:id", seq=11)),
                                     encoding="utf-8")),
                ("account:id",
                 appier.legacy.bytes(json.dumps(dict(_id="account:id",
                                                     seq=33)),
                                     encoding="utf-8"))]

        adapter = appier.get_adapter()
        manager = appier.ExportManager(adapter, multiple=self.app.resolve())

        collection = adapter.collection("counter")
        manager._import_multiple(collection, data, key="_id")

        values = collection.find()
        values = [value for value in values]

        self.assertEqual(type(values), list)
        self.assertEqual(len(values), 2)

        value = collection.find_one(dict(_id="person:id"))

        self.assertEqual(value["seq"], 11)