Yeah, sure.  How to set it?

On Apr 13, 8:31 pm, Jeff S <j...@google.com> wrote:
> Hi slatvick,
>
> Could we see the class declaration for Player? It seems like user should be
> set to a db.UserProperty.
>
> Thank you,
>
> Jeff
>
> 2009/4/11 slatvick <slatv...@gmail.com>
>
>
>
> > thanks guys.
>
> > I do:
> > os.environ['USER_EMAIL'] = "t...@example.com"
> > user = users.get_current_user()
>
> > and even user.nickname returns right string.
>
> > BUT, when i want to create connected data in model it does not work.
> > Creating model:
> > ..
> > player = Player(user=users.get_current_user(), ...) # <<- wrong right
> > here
> > player.put()
> > ..
>
> > it returns:
> > <pre>Traceback (most recent call last):
> >  File &quot;/base/python_lib/versions/1/google/appengine/ext/webapp/
> > __init__.py&quot;, line 501, in
> >  __call__
> >    handler.get(*groups)
> >  File &quot;/base/data/home/apps/gpsball/1.332716226397017546/
> > helloworld.py&quot;, line 272, in get
> >    player = game.Player()
> >  File &quot;/base/data/home/apps/gpsball/1.332716226397017546/
> > helloworld.py&quot;, line 23, in Play
> > er
> >    player = Player(user=users.get_current_user(), ... )
> >  File &quot;/base/python_lib/versions/1/google/appengine/ext/db/
> > __init__.py&quot;, line 596, in __i
> > nit__
> >    prop.__set__(self, value)
> >  File &quot;/base/python_lib/versions/1/google/appengine/ext/db/
> > __init__.py&quot;, line 396, in __s
> > et__
> >    value = self.validate(value)
> >  File &quot;/base/python_lib/versions/1/google/appengine/ext/db/
> > __init__.py&quot;, line 2305, in va
> > lidate
> >    value = super(UserProperty, self).validate(value)
> >  File &quot;/base/python_lib/versions/1/google/appengine/ext/db/
> > __init__.py&quot;, line 423, in val
> > idate
> >    raise BadValueError('Property %s is required' % self.name)
> > BadValueError: Property user is required
> > </pre>
>
> > What's wrong? is this way logining not fully?
>
> > On Apr 10, 2:56 pm, Alkis Evlogimenos ('Αλκης Ευλογημένος)
> > <evlogime...@gmail.com> wrote:
> > > I switched to using this decorator for my test methods using webtest:
> > > from nose.tools import make_decorator
>
> > > def credentials(user=False, admin=False):
> > >   def _decorator(func):
> > >     def _wrapper(*args, **kwds):
> > >       old_user = os.environ.get('USER_EMAIL', '')
> > >       old_admin = os.environ.get('USER_IS_ADMIN', '0')
>
> > >       if user or admin:
> > >         os.environ['USER_EMAIL'] = 'u...@test.com'
> > >       else:
> > >         os.environ['USER_EMAIL'] = ''
>
> > >       if admin:
> > >         os.environ['USER_IS_ADMIN'] = '1'
> > >       else:
> > >         os.environ['USER_IS_ADMIN'] = '0'
>
> > >       try:
> > >         func(*args, **kwds)
> > >       finally:
> > >         os.environ['USER_EMAIL'] = old_user
> > >         os.environ['USER_IS_ADMIN'] = old_admin
>
> > >     _wrapper = make_decorator(func)(_wrapper)
> > >     return _wrapper
> > >   return _decorator
>
> > > Usage is:
>
> > > class MyTest(unittest.TestCase):
> > >   def setUp(self):
> > >     self.app = ... make your app here using webtest or any other
> > webtesting
> > > framework
>
> > >   @credentials
> > >   def testIndexPublic(self):
> > >     response = self.app.get('/')
> > >     self.assertTrue('some string only found when noone has logged in' in
> > > response)
>
> > >   @credentials(user=True)
> > >   def testIndexUser(self):
> > >     response = self.app.get('/')
> > >     self.assertTrue('some string only found in user logged in rendering'
> > in
> > > response)
>
> > >   @credentials(admin=True)
> > >   def testIndexAdmin(self):
> > >     response = self.app.get('/')
> > >     self.assertTrue('some string only found in admin rendering' in
> > response)
>
> > > I hope this helps.
>
> > > On Fri, Apr 10, 2009 at 12:30 PM, slatvick <slatv...@gmail.com> wrote:
>
> > > > Mahmoud:
> > > > Thanks, but this method does not do loging as the standard login form
> > > > does.
> > > > I already have data connected to "t...@example.com"-user in my model
> > > > and this:
> > > > os.environ['USER_EMAIL'] ="t...@example.com"
> > > > does not logins properly, but redirects to the login-form.
>
> > > > Alkis Evlogimenos:
> > > > Sorry, but where is "env" contains? Because i have "global name 'env'
> > > > is not defined" and cannot find in docs.
> > > > thanks in advance.
>
> > > --
>
> > > Alkis
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to