def test_save_with_new_type(self): docs = [{ "key": "/type/foo", "type": { "key": "/type/type" } }, { "key": "/foo", "type": { "key": "/type/foo" } }] s = SaveImpl(db) timestamp = datetime.datetime(2010, 1, 1, 1, 1, 1) s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save") type = db.query("SELECT * FROM thing where key='/type/foo'")[0] thing = db.query("SELECT * FROM thing where key='/foo'")[0] assert thing.type == type.id
def test_save(self): s = SaveImpl(db) timestamp = datetime.datetime(2010, 1, 1, 1, 1, 1) a = {"key": "/a", "type": {"key": "/type/object"}, "title": "a"} status = s.save([a], timestamp=timestamp, ip="1.2.3.4", author=None, comment="Testing create.", action="save") assert status['changes'][0]['revision'] == 1 assert self.get_json('/a') == update_doc(a, 1, timestamp, timestamp) a['title'] = 'b' timestamp2 = datetime.datetime(2010, 2, 2, 2, 2, 2) status = s.save([a], timestamp=timestamp2, ip="1.2.3.4", author=None, comment="Testing update.", action="save") assert status['changes'][0]['revision'] == 2 assert self.get_json('/a') == update_doc(a, 2, timestamp, timestamp2)
def test_type_change(self): s = SaveImpl(db) timestamp = datetime.datetime(2010, 1, 1, 1, 1, 1) a = {"key": "/a", "type": {"key": "/type/object"}, "title": "a"} status = s.save([a], timestamp=timestamp, ip="1.2.3.4", author=None, comment="Testing create.", action="save") # insert new type type_delete_id = db.insert("thing", key='/type/delete') a['type']['key'] = '/type/delete' timestamp2 = datetime.datetime(2010, 2, 2, 2, 2, 2) status = s.save([a], timestamp=timestamp2, ip="1.2.3.4", author=None, comment="Testing type change.", action="save") assert status['changes'][0]['revision'] == 2 assert self.get_json('/a') == update_doc(a, 2, timestamp, timestamp2) thing = db.select("thing", where="key='/a'")[0] assert thing.type == type_delete_id
def test_type_change(self): s = SaveImpl(db) timestamp = datetime.datetime(2010, 01, 01, 01, 01, 01) a = {"key": "/a", "type": {"key": "/type/object"}, "title": "a"} status = s.save([a], timestamp=timestamp, ip="1.2.3.4", author=None, comment="Testing create.", action="save") # insert new type type_delete_id = db.insert("thing", key='/type/delete') a['type']['key'] = '/type/delete' timestamp2 = datetime.datetime(2010, 02, 02, 02, 02, 02) status = s.save([a], timestamp=timestamp2, ip="1.2.3.4", author=None, comment="Testing type change.", action="save") assert status['changes'][0]['revision'] == 2 assert self.get_json('/a') == update_doc(a, 2, timestamp, timestamp2) thing = db.select("thing", where="key='/a'")[0] assert thing.type == type_delete_id
def test_save(self): s = SaveImpl(db) timestamp = datetime.datetime(2010, 01, 01, 01, 01, 01) a = {"key": "/a", "type": {"key": "/type/object"}, "title": "a"} status = s.save([a], timestamp=timestamp, ip="1.2.3.4", author=None, comment="Testing create.", action="save") assert status['changes'][0]['revision'] == 1 assert self.get_json('/a') == update_doc(a, 1, timestamp, timestamp) a['title'] = 'b' timestamp2 = datetime.datetime(2010, 02, 02, 02, 02, 02) status = s.save([a], timestamp=timestamp2, ip="1.2.3.4", author=None, comment="Testing update.", action="save") assert status['changes'][0]['revision'] == 2 assert self.get_json('/a') == update_doc(a, 2, timestamp, timestamp2)
def test_save_with_long_string(self): docs = [{ "key": "/type/foo", "type": {"key": "/type/type"}, "title": "a" * 4000 }] s = SaveImpl(db) timestamp = datetime.datetime(2010, 01, 01, 01, 01, 01) s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save")
def _save(self, docs, author=None, ip="1.2.3.4", comment="testing", kind="test_save", timestamp=None, data=None): timestamp = timestamp=timestamp or datetime.datetime(2010, 01, 02, 03, 04, 05) s = SaveImpl(db) s.save(docs, timestamp=timestamp, comment=comment, ip=ip, author=author, action=kind, data=data )
def test_save_with_long_string(self): docs = [ {"key": "/type/foo", "type": {"key": "/type/type"}, "title": "a" * 4000} ] s = SaveImpl(db) timestamp = datetime.datetime(2010, 1, 1, 1, 1, 1) s.save( docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save", )
def test_transaction(self, wildcard): docs = [{ "key": "/foo", "type": { "key": "/type/object" }, }] s = SaveImpl(db) timestamp = datetime.datetime(2010, 1, 1, 1, 1, 1) changeset = s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save") changeset.pop("docs") changeset.pop("old_docs") assert changeset == { "id": wildcard, "kind": "save", "timestamp": timestamp.isoformat(), "bot": False, "comment": "foo", "ip": "1.2.3.4", "author": None, "changes": [{ "key": "/foo", "revision": 1 }], "data": {} }
def test_save_with_new_type(self): docs = [{ "key": "/type/foo", "type": {"key": "/type/type"} }, { "key": "/foo", "type": {"key": "/type/foo"} }] s = SaveImpl(db) timestamp = datetime.datetime(2010, 01, 01, 01, 01, 01) s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save") type = db.query("SELECT * FROM thing where key='/type/foo'")[0] thing = db.query("SELECT * FROM thing where key='/foo'")[0] assert thing.type == type.id
def _save(self, docs, author=None, ip="1.2.3.4", comment="testing", kind="test_save", timestamp=None, data=None): timestamp = timestamp = timestamp or datetime.datetime( 2010, 01, 02, 03, 04, 05) s = SaveImpl(db) s.save(docs, timestamp=timestamp, comment=comment, ip=ip, author=author, action=kind, data=data)
def _save(self, docs): s = SaveImpl(db) timestamp = datetime.datetime(2010, 1, 1, 1, 1, 1) return s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save")
def save_many(self, docs, timestamp, comment, data, ip, author, action=None): docs = list(docs) action = action or "bulk_update" logger.debug( "saving %d docs - %s", len(docs), dict( timestamp=timestamp, comment=comment, data=data, ip=ip, author=author, action=action, ), ) s = SaveImpl(self.db, self.schema, self.indexer, self.property_manager) # Hack to allow processing of json data before using. Required for OL legacy. s.process_json = process_json docs = common.format_data(docs) changeset = s.save( docs, timestamp=timestamp, comment=comment, ip=ip, author=author, action=action, data=data, ) # update cache. # Use the docs from result as they contain the updated revision and last_modified fields. for doc in changeset.get('docs', []): web.ctx.new_objects[doc['key']] = json.dumps(doc) return changeset
def test_transaction(self, wildcard): docs = [{ "key": "/foo", "type": {"key": "/type/object"}, }] s = SaveImpl(db) timestamp = datetime.datetime(2010, 01, 01, 01, 01, 01) changeset = s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save") changeset.pop("docs") changeset.pop("old_docs") assert changeset == { "id": wildcard, "kind": "save", "timestamp": timestamp.isoformat(), "bot": False, "comment": "foo", "ip": "1.2.3.4", "author": None, "changes": [{"key": "/foo", "revision": 1}], "data": {} }
def _save(self, docs): s = SaveImpl(db) timestamp = datetime.datetime(2010, 01, 01, 01, 01, 01) return s.save(docs, timestamp=timestamp, comment="foo", ip="1.2.3.4", author=None, action="save")