def test_mappings(self): result = self._fixture() eq_( [dict(r) for r in result.mappings()], [ { "a": 1, "b": 1, "c": 1 }, { "a": 2, "b": 1, "c": 2 }, { "a": 1, "b": 3, "c": 2 }, { "a": 4, "b": 1, "c": 2 }, ], )
def test_one_unique_mapping(self): # assert that one() counts rows after uniqueness has been applied. # this would raise if we didnt have unique result = self._fixture(data=[(1, 1, 1), (1, 1, 1)]) row = result.mappings().unique().one() eq_(row, {"a": 1, "b": 1, "c": 1})
def test_mappings_with_columns(self): result = self._fixture() m1 = result.mappings().columns("b", "c") eq_(m1.fetchmany(2), [{"b": 1, "c": 1}, {"b": 1, "c": 2}]) # no slice here eq_(result.fetchone(), (1, 3, 2)) # still slices eq_(m1.fetchone(), {"b": 1, "c": 2})
def test_scalars_no_fetchone(self): result = self._fixture() s = result.scalars() assert not hasattr(s, "fetchone") # original result is unchanged eq_(result.mappings().fetchone(), {"a": 1, "b": 1, "c": 1}) # scalars eq_(s.all(), [2, 1, 4])
def test_scalars_no_fetchone(self): result = self._fixture() result = result.scalars() assert_raises_message( exc.InvalidRequestError, r"Can't use fetchone\(\) when returning scalar values; ", result.fetchone, ) # mappings() switches the flag off eq_(result.mappings().fetchone(), {"a": 1})
def test_one_mapping(self): result = self._fixture(num_rows=1) row = result.mappings().one() eq_(row, {"a": 1, "b": 1, "c": 1})