MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_session_merge

Method test_session_merge

test/ext/test_mutable.py:217–250  ·  view source on GitHub ↗

test #8446

(
        self, decl_base, connection, present, load, merge_subject
    )

Source from the content-addressed store, hash-verified

215 )
216 @testing.requires.json_type
217 def test_session_merge(
218 self, decl_base, connection, present, load, merge_subject
219 ):
220 """test #8446"""
221
222 class Thing(decl_base):
223 __tablename__ = "thing"
224 id = Column(Integer, primary_key=True)
225 data = Column(MutableDict.as_mutable(JSON))
226
227 decl_base.metadata.create_all(connection)
228
229 with Session(connection) as sess:
230 sess.add(Thing(id=1, data={"foo": "bar"}))
231 sess.commit()
232
233 if merge_subject == "transient":
234 t1_to_merge = Thing(id=1, data={"foo": "bar"})
235 elif merge_subject == "detached":
236 with Session(connection) as sess:
237 t1_to_merge = sess.get(Thing, 1)
238
239 with Session(connection) as sess:
240 already_present = None
241 if present == "key_present":
242 already_present = sess.get(Thing, 1)
243
244 t1_merged = sess.merge(t1_to_merge, load=load)
245
246 t1_merged.data["foo"] = "bat"
247 if present == "key_present":
248 is_(t1_merged, already_present)
249
250 is_true(inspect(t1_merged).attrs.data.history.added)
251
252 def test_no_duplicate_reg_w_inheritance(self, decl_base):
253 """test #9676"""

Callers

nothing calls this directly

Calls 10

SessionClass · 0.90
is_Function · 0.90
is_trueFunction · 0.90
inspectFunction · 0.90
create_allMethod · 0.80
ThingClass · 0.70
addMethod · 0.45
commitMethod · 0.45
getMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected