MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_no_pk

Method test_no_pk

test/sql/test_insert_exec.py:2352–2421  ·  view source on GitHub ↗
(
        self,
        metadata,
        connection,
        randomize_returning,
        sort_by_parameter_order,
        warn_for_downgrades,
        add_sentinel,
        set_identity,
    )

Source from the content-addressed store, hash-verified

2350 "set_identity", [(True, testing.requires.identity_columns), False]
2351 )
2352 def test_no_pk(
2353 self,
2354 metadata,
2355 connection,
2356 randomize_returning,
2357 sort_by_parameter_order,
2358 warn_for_downgrades,
2359 add_sentinel,
2360 set_identity,
2361 ):
2362 if set_identity:
2363 id_col = Column("id", Integer(), Identity())
2364 else:
2365 id_col = Column("id", Integer())
2366
2367 uuids = [uuid.uuid4() for i in range(10)]
2368
2369 sentinel_col = Column(
2370 "unique_id",
2371 Uuid,
2372 default=functools.partial(next, iter(uuids)),
2373 insert_sentinel=bool(add_sentinel),
2374 )
2375 t1 = Table(
2376 "nopk",
2377 metadata,
2378 id_col,
2379 Column("data", String(50)),
2380 sentinel_col,
2381 Column(
2382 "has_server_default",
2383 String(30),
2384 server_default="some_server_default",
2385 ),
2386 )
2387 metadata.create_all(connection)
2388
2389 fixtures.insertmanyvalues_fixture(
2390 connection,
2391 randomize_rows=bool(randomize_returning),
2392 warn_on_downgraded=bool(warn_for_downgrades),
2393 )
2394
2395 stmt = insert(t1).returning(
2396 t1.c.id,
2397 t1.c.data,
2398 t1.c.has_server_default,
2399 sort_by_parameter_order=bool(sort_by_parameter_order),
2400 )
2401 if not set_identity:
2402 data = [{"id": i + 1, "data": f"d{i}"} for i in range(10)]
2403 else:
2404 data = [{"data": f"d{i}"} for i in range(10)]
2405
2406 with self._expect_downgrade_warnings(
2407 warn_for_downgrades=warn_for_downgrades,
2408 sort_by_parameter_order=sort_by_parameter_order,
2409 separate_sentinel=add_sentinel,

Callers

nothing calls this directly

Calls 11

ColumnClass · 0.90
IntegerClass · 0.90
IdentityClass · 0.90
TableClass · 0.90
StringClass · 0.90
insertFunction · 0.90
eq_Function · 0.90
create_allMethod · 0.80
returningMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected