def test_login_or_logout(self, client, username=''):
    from cookielib import Cookie
    args = [None, None, '', None, None, '/', None, None, 86400, None, None,
            None, None]
    try:
      auth_model_class = import_string(settings.AUTH_USER_MODEL)
    except (ImportError, __HOLE__), e:
      raise ImproperlyConfigured, \
          'Failed to import %s: "%s".' % (settings.AUTH_USER_MODEL, e)
    user = auth_model_class.get_by_user_name(username)
    session_store = import_string(settings.SESSION_STORE)()
    data = None
    for cookie in client.cookie_jar:
      if cookie.name == settings.COOKIE_NAME:
        data = cookie.value
    if data is None:
      session = session_store.new()
    else:
      session = session_store.get(data)
    if user:
      session['_user'] = user.key()
    elif session.has_key('_user'):
      del session['_user']
    session_store.save(session)
    data = "\"%s\"" % session_store.get_data(session)
    client.cookie_jar.set_cookie(Cookie(1, settings.COOKIE_NAME,
                                        data,
                                        *args))
dataset/ETHPy150Open IanLewis/kay/kay/auth/backends/datastore.py/DatastoreBackend.test_login_or_logout