| 1517 | argnames="get_object", |
| 1518 | ) |
| 1519 | def test_keys(self, connection, get_object): |
| 1520 | users = self.tables.users |
| 1521 | addresses = self.tables.addresses |
| 1522 | |
| 1523 | connection.execute(users.insert(), dict(user_id=1, user_name="foo")) |
| 1524 | result = connection.execute(users.select()) |
| 1525 | |
| 1526 | obj = get_object(result) |
| 1527 | |
| 1528 | if isinstance(obj, Row): |
| 1529 | keys = obj._mapping.keys() |
| 1530 | else: |
| 1531 | keys = obj.keys() |
| 1532 | |
| 1533 | # in 1.4, keys() is now a view that includes support for testing |
| 1534 | # of columns and other objects |
| 1535 | eq_(len(keys), 2) |
| 1536 | eq_(list(keys), ["user_id", "user_name"]) |
| 1537 | eq_(keys, ["user_id", "user_name"]) |
| 1538 | ne_(keys, ["user_name", "user_id"]) |
| 1539 | in_("user_id", keys) |
| 1540 | not_in("foo", keys) |
| 1541 | in_(users.c.user_id, keys) |
| 1542 | not_in(0, keys) |
| 1543 | not_in(addresses.c.user_id, keys) |
| 1544 | not_in(addresses.c.address, keys) |
| 1545 | |
| 1546 | if isinstance(obj, Row): |
| 1547 | eq_(obj._fields, ("user_id", "user_name")) |
| 1548 | |
| 1549 | def test_row_mapping_keys(self, connection): |
| 1550 | users = self.tables.users |