예제 #1
0
def test_cache_mixin(mocker):
    assert 'team|0' in repr(Team(id=0, team_name="hello"))
    assert Team(id=0, team_name='hello').pk_name() == 'id'
    assert Team(id=0, team_name='hello').pk_attribute().key == 'id'

    t = Team(team_name='test_cache_mixin')
    DBSession.add(t)
    DBSession.commit()
    assert len(Team.mget([t.id], force=True)) == 1

    with pytest.raises(NotImplementedError):
        CacheMixinBase._cache_client.error

    with pytest.raises(NotImplementedError):
        CacheMixinBase._db_session.error

    with mocker.patch.object(CacheMixinBase, 'RAWDATA_VERSION',
                             mocker.MagicMock(__str__=lambda x: '233')):
        assert Team.gen_raw_key(1) == 'team|1|233'

    with mocker.patch.object(Team.__mapper__, 'primary_key',
                             mocker.MagicMock(return_value=[],
                                              __nonzero__=mocker.MagicMock(
                                                  return_value=False))):
        assert Team(id=2, team_name='hello').pk_name() is None
        assert Team(id=3, team_name='hello').pk_attribute() is None
예제 #2
0
def test_make_transient_to_detached_error():
    t = Team(id=0, team_name='233')
    with pytest.raises(sa_exc.InvalidRequestError):
        DBSession.add(t)
        make_transient_to_detached(t)