Example #1
0
 def testFirstSignup(self):
     setCurrentUser("*****@*****.**", "Administrator")
     '''Should fail repeatedly with a NoUserNameException'''
     self.assertRaises(NoUserNameException, _get_my_profile)
     self.assertRaises(NoUserNameException, _get_my_profile)
     '''Should create the Site Administrator with its own place for template Roles'''
     register_new_user('SiteAdmin')
     '''Should have a SiteAdmin now'''
     self.assertIsInstance(_get_my_profile(), SiteMasterProfile)
     self.assertEquals(SiteMasterProfile.query().count(), 1)
     self.assertEquals(Profile.query().count(), 1)
     '''Should be called whatever it was set up as'''
     self.assertEquals('SiteAdmin', get_my_profile_name())
     '''Check number of entities'''
     self.assertEquals(1, SiteMasterProfile.query().count())
     '''Should just fail with a NoUserException if logged out'''
     logoutCurrentUser()
     self.assertRaises(NoUserException, _get_my_profile)
Example #2
0
def register_new_user(name):
    ''' register a Profile for the current user as long as the name hasn't been used and the user doesn't already have a Profile '''
    if name is None:
        raise ActionException('Name is required')
    if len(Profile.query(Profile.name_order == name.upper()).fetch(1)) > 0:
        raise ActionException('Name has been used by someone else')
    profile, userid = _get_profile()
    if profile is None:
        sm = _get_site_master()
        if sm is None:
            profile = SiteMasterProfile(id=userid)
            profile.free_games = 1
            profile.free_places = 2
        else:
            profile = Profile(id=userid)
    else:
        raise ActionException('User already has a profile')
    profile.name = name
    profile.name_order = name.upper()
    profile.updated = datetime.now()
    profile.playing = profile.key
    profile.put()
    return profile.key.urlsafe()
Example #3
0
 def testNextSignup(self):
     setCurrentUser("*****@*****.**", "Administrator")
     self.assertRaises(NoUserNameException, _get_my_profile)
     self.assertRaises(NoUserNameException, _get_my_profile)
     register_new_user('SiteAdmin')
     self.assertIsInstance(_get_my_profile(), Profile)
     self.assertEquals('SiteAdmin', get_my_profile_name())
     self.assertEquals(1, SiteMasterProfile.query().count())
     self.assertEquals(1, Profile.query().count())
     logoutCurrentUser()
     self.assertRaises(NoUserException, _get_my_profile)
     setCurrentUser("*****@*****.**", "NewUser1")
     self.assertRaises(NoUserNameException, _get_my_profile)
     self.assertRaises(NoUserNameException, _get_my_profile)
     '''Should create a GameMaster for this new profile with its own Place for private conversations'''
     register_new_user('NewUserOne')
     '''Should have an profile now'''
     self.assertIsInstance(_get_my_profile(), Profile)
     '''Should be called whatever it was set up as'''
     self.assertEquals('NewUserOne', get_my_profile_name())
     self.assertEquals(2, Profile.query().count())
     logoutCurrentUser()
     self.assertRaises(NoUserException, _get_my_profile)
Example #4
0
def _get_site_master():
    sml = SiteMasterProfile.query().fetch(1)
    return sml[0] if len(sml) > 0 else None