| 1582 | argnames="get_object", |
| 1583 | ) |
| 1584 | def test_keys(self, connection, get_object): |
| 1585 | users = self.tables.users |
| 1586 | addresses = self.tables.addresses |
| 1587 | |
| 1588 | connection.execute(users.insert(), dict(user_id=1, user_name="foo")) |
| 1589 | result = connection.execute(users.select()) |
| 1590 | |
| 1591 | obj = get_object(result) |
| 1592 | |
| 1593 | if isinstance(obj, Row): |
| 1594 | keys = obj._mapping.keys() |
| 1595 | else: |
| 1596 | keys = obj.keys() |
| 1597 | |
| 1598 | # in 1.4, keys() is now a view that includes support for testing |
| 1599 | # of columns and other objects |
| 1600 | eq_(len(keys), 2) |
| 1601 | eq_(list(keys), ["user_id", "user_name"]) |
| 1602 | eq_(keys, ["user_id", "user_name"]) |
| 1603 | ne_(keys, ["user_name", "user_id"]) |
| 1604 | in_("user_id", keys) |
| 1605 | not_in("foo", keys) |
| 1606 | in_(users.c.user_id, keys) |
| 1607 | not_in(0, keys) |
| 1608 | not_in(addresses.c.user_id, keys) |
| 1609 | not_in(addresses.c.address, keys) |
| 1610 | |
| 1611 | if isinstance(obj, Row): |
| 1612 | eq_(obj._fields, ("user_id", "user_name")) |
| 1613 | |
| 1614 | def test_row_mapping_keys(self, connection): |
| 1615 | users = self.tables.users |