当前位置: 首页>>代码示例>>Python>>正文


Python models.User类代码示例

本文整理汇总了Python中auth.models.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete_spot_copy

    def test_delete_spot_copy(self):
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot.put()
        dow=1
        hour=0
        slot=0
        constraint = models.SpotConstraint(dow=dow, hour=hour, slot=slot, spots=[spot.key()])
        constraint.put()

        author = User(email='test')
        author.put()
        spot_copy = models.SpotCopy(
                        body='First',
                        spot=spot,
                        author=author)
        spot_copy.put()

        self.assertEqual(spot.get_spot_copy(dow, hour, slot)[0].body, "First")

        # now edit the second one:
        resp = self.client.get(reverse('traffic_log.deleteSpotCopy', args=(spot_copy.key(),)))

        self.assertEqual([c for c in spot.all_spot_copy()], [])

        self.assertEqual(spot.get_spot_copy(dow, hour, slot), (None, False))
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:27,代码来源:tests.py

示例2: test_edit_spot_copy

    def test_edit_spot_copy(self):
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=1, hour=0, slot=0, spots=[spot.key()])
        constraint.put()

        author = User(email='test')
        author.put()
        spot_copy = models.SpotCopy(
                        body='First',
                        spot=spot,
                        author=author)
        spot_copy.put()
        spot_copy2 = models.SpotCopy(
                        body='You are listening to chirpradio.org',
                        spot=spot,
                        author=author)
        spot_copy2.put()

        # now edit the second one:
        resp = self.client.post(reverse('traffic_log.editSpotCopy', args=(spot_copy2.key(),)), {
            'spot_key': spot.key(),
            'body': 'Something else entirely',
            'underwriter': 'another underwriter',
            'expire_on': ''
        })
        self.assertNoFormErrors(resp)

        spot_copy = [c for c in spot.all_spot_copy()]
        self.assertEqual(sorted([c.body for c in spot_copy]), ['First','Something else entirely'])
        self.assertEqual(sorted([c.underwriter for c in spot_copy]), [None, 'another underwriter'])
        self.assertEqual(sorted([c.author.email for c in spot_copy]), ['test', '[email protected]'])
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:34,代码来源:tests.py

示例3: test_user_edit_form

 def test_user_edit_form(self):
     steve = User(
         email='[email protected]',
         first_name='Steve',
         last_name='Dolfin',
         dj_name='DJ Steve',
         roles=['dj'],
         is_active=True,
         password='123456' # pretend this is encrypted
     )
     steve.save()
     
     resp = self.client.post('/auth/edit_user/', {
         'original_email': '[email protected]', # this is the key
         'email': '[email protected]',
         'first_name': 'Steven',
         'last_name': 'Dolfin III',
         'dj_name': 'Steve Holt!',
         'is_active': 'checked',
         # change roles:
         'is_volunteer_coordinator': 'checked'
     })
     self.assertNoFormErrors(resp)
     
     user = User.all().filter('email =', '[email protected]').fetch(1)[0]
     self.assertEqual(user.first_name, 'Steven')
     self.assertEqual(user.last_name, 'Dolfin III')
     self.assertEqual(user.dj_name, 'Steve Holt!')
     self.assertEqual(user.roles, ['volunteer_coordinator'])
     self.assertEqual(user.password, '123456') # should be untouched
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:30,代码来源:test_views.py

示例4: test_edit_spot_copy

    def test_edit_spot_copy(self):
        spot = models.Spot(title="Legal ID", type="Station ID")
        spot.put()
        constraint = models.SpotConstraint(dow=1, hour=0, slot=0, spots=[spot.key()])
        constraint.put()

        author = User(email="test")
        author.put()
        spot_copy = models.SpotCopy(body="First", spot=spot, author=author)
        spot_copy.put()
        spot_copy2 = models.SpotCopy(body="You are listening to chirpradio.org", spot=spot, author=author)
        spot_copy2.put()

        # now edit the second one:
        resp = self.client.post(
            reverse("traffic_log.editSpotCopy", args=(spot_copy2.key(),)),
            {
                "spot_key": spot.key(),
                "body": "Something else entirely",
                "underwriter": "another underwriter",
                "expire_on": "",
            },
        )
        self.assertNoFormErrors(resp)

        spot_copy = [c for c in spot.all_spot_copy()]
        self.assertEqual(sorted([c.body for c in spot_copy]), ["First", "Something else entirely"])
        self.assertEqual(sorted([c.underwriter for c in spot_copy]), [None, "another underwriter"])
        self.assertEqual(sorted([c.author.email for c in spot_copy]), ["test", "[email protected]"])
开发者ID:chirpradio,项目名称:chirpradio,代码行数:29,代码来源:tests.py

示例5: setUp

    def setUp(self):
        assert self.client.login(email="[email protected]", roles=[roles.TRAFFIC_LOG_ADMIN])

        author = User(email="test")
        author.save()
        self.author = author
        spot = models.Spot(title="Legal ID", type="Station ID", author=author)
        self.spot = spot
        spot.put()

        self.now = time_util.chicago_now()
        self.today = self.now.date()
        self.dow = self.today.isoweekday()

        constraint = self.add_spot_to_constraint(spot)
        self.constraint = constraint
        spot_copy = models.SpotCopy(body="You are listening to chirpradio.org", spot=spot, author=author)
        self.spot_copy = spot_copy
        spot_copy.put()
        spot.random_spot_copies = [spot_copy.key()]
        spot.save()

        logged_spot = models.TrafficLogEntry(
            log_date=self.today,
            spot=spot_copy.spot,
            spot_copy=spot_copy,
            dow=self.dow,
            hour=self.now.hour,
            slot=0,
            scheduled=constraint,
            readtime=time_util.chicago_now(),
            reader=author,
        )
        logged_spot.put()
开发者ID:chirpradio,项目名称:chirpradio,代码行数:34,代码来源:tests.py

示例6: test_user_edit_form_change_password

    def test_user_edit_form_change_password(self):
        steve = User(
            email='[email protected]',
            first_name='Steve',
            last_name='Dolfin',
            dj_name='DJ Steve',
            roles=['dj'],
            is_active=True,
            password='123456'
        )
        steve.save()
        
        resp = self.client.post('/auth/edit_user/', {
            'original_email': '[email protected]', # this is the key
            'email': '[email protected]',
            'first_name': 'Steve',
            'last_name': 'Dolfin',
            'dj_name': 'DJ Seteve',
            'is_active': 'checked',
            'is_dj': 'checked',
            # new password
            'password': '1234567'
        })
        self.assertNoFormErrors(resp)

        user = User.all().filter('email =', '[email protected]').fetch(1)[0]
        # password was changed:
        self.assertEqual(user.check_password('1234567'), True)
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:28,代码来源:test_views.py

示例7: test_change_password_form

    def test_change_password_form(self):
        # Set up a test user
        user = User(email='[email protected]')
        user.set_password('password')
        
        # The form should fail to validate if the current password is wrong.
        form = auth_forms.ChangePasswordForm({
                'current_password': 'incorrect password',
                'new_password': 'foo',
                'confirm_new_password': 'foo',
                })
        form.set_user(user)
        self.assertFalse(form.is_valid())

        # The form should fail to validate if the two versions of the
        # new password do not agree.
        form = auth_forms.ChangePasswordForm({
                'current_password': 'password',
                'new_password': 'foo',
                'confirm_new_password': 'bar',
                })
        form.set_user(user)
        self.assertFalse(form.is_valid())

        # This should work.
        form = auth_forms.ChangePasswordForm({
                'current_password': 'password',
                'new_password': 'foo',
                'confirm_new_password': 'foo',
                })
        form.set_user(user)
        self.assertTrue(form.is_valid())
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:32,代码来源:test_views.py

示例8: test_non_dj_cannot_create_playlist

 def test_non_dj_cannot_create_playlist(self):
     not_a_dj = User(email="test")
     not_a_dj.put()
     def make_playlist():
         playlist = DJPlaylist(name='funk 45 collection', created_by_dj=not_a_dj)
         playlist.put()
     self.assertRaises(ValueError, make_playlist)
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:7,代码来源:test_models.py

示例9: test_bootstrapping_via_google_accounts

 def test_bootstrapping_via_google_accounts(self):
     client = Client()
     # Not signed in at all?  We should be redirected to a Google
     # login page.
     response = client.get('/auth/_bootstrap')
     self.assertEqual(302, response.status_code)
     # Already signed in?  You should see a 403.
     client.login(email='[email protected]')
     response = client.get('/auth/_bootstrap')
     self.assertEqual(403, response.status_code)
     self.assertEqual('Already logged in', response.content)
     client.logout()
     # Reject people who are not superusers.
     g_email = '[email protected]'
     self.g_user = google_users.User(email=g_email)
     self.is_superuser = False
     response = client.get('/auth/_bootstrap')
     self.assertEqual(403, response.status_code)
     self.assertEqual('Not a chirpradio project admin', response.content)
     # Create a new User object for superusers.
     self.assertEqual(None, User.get_by_email(g_email))
     self.is_superuser = True
     response = client.get('/auth/_bootstrap')
     self.assertEqual(302, response.status_code)  # Redirect to login page.
     user = User.get_by_email(g_email)
     self.assertEqual(g_email, user.email)
     # If the user already exists for the superuser, 403.
     response = client.get('/auth/_bootstrap')
     self.assertEqual(403, response.status_code)
     self.assertEqual('User %s already exists' % g_email, response.content)
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:30,代码来源:test_views.py

示例10: PlaylistTest

class PlaylistTest(APITest):

    def setUp(self):
        super(PlaylistTest, self).setUp()
        dbconfig['lastfm.api_key'] = 'SEKRET_LASTFM_KEY'
        self.dj = User(dj_name='DJ Night Moves', first_name='Steve',
                       last_name='Dolfin', email='[email protected]',
                       roles=[auth.roles.DJ])
        self.dj.save()
        self.playlist = ChirpBroadcast()
        (self.stevie,
         self.talking_book,
         self.tracks) = create_stevie_wonder_album_data()

    def play_stevie_song(self, song_name):
        self.playlist_track = PlaylistTrack(
                playlist=self.playlist,
                selector=self.dj,
                artist=self.stevie,
                album=self.talking_book,
                track=self.tracks[song_name],
                notes='from 1972!',
                freeform_label='Motown')
        self.playlist_track.save()
        return self.playlist_track
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:25,代码来源:tests.py

示例11: test_finish_spot

    def test_finish_spot(self):
        self.assertEqual(list(models.TrafficLogEntry.all().fetch(5)), [])

        author = User(email='test')
        author.save()
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID',
                        author=author)
        spot.put()

        # make a constraint closest to now:
        now = time_util.chicago_now()
        today = now.date()
        current_hour = now.hour
        constraint = models.SpotConstraint(
            dow=today.isoweekday(), hour=current_hour, slot=0, spots=[spot.key()])
        constraint.put()

        spot_copy = models.SpotCopy(
                        body='You are listening to chirpradio.org',
                        spot=spot,
                        author=author)
        spot_copy.put()

        spot.random_spot_copies = [spot_copy.key()]
        spot.save()

        resp = self.client.get(reverse('traffic_log.index'))
        # unfinished spot should have been marked in static HTML:
        assert '<tr class="new">' in resp.content

        resp = self.client.get(reverse('traffic_log.finishReadingSpotCopy', args=(spot_copy.key(),)), {
            'hour': constraint.hour,
            'dow': constraint.dow,
            'slot': constraint.slot
        })
        logged = models.TrafficLogEntry.all().fetch(1)[0]
        self.assertEqual(logged.reader.email, "[email protected]")
        self.assertEqual(logged.readtime.timetuple()[0:5], datetime.datetime.now().timetuple()[0:5])
        self.assertEqual(logged.log_date, time_util.chicago_now().date())
        self.assertEqual(logged.spot.key(), spot.key())
        self.assertEqual(logged.spot_copy.key(), spot_copy.key())
        self.assertEqual(logged.scheduled.key(), constraint.key())
        self.assertEqual(logged.hour, constraint.hour)
        self.assertEqual(logged.dow, constraint.dow)

        resp = self.client.get(reverse('traffic_log.index'))
        # finished spot should have been marked in static HTML:
        assert '<tr class="finished">' in resp.content

        resp = self.client.get(reverse('traffic_log.spotTextForReading', args=(spot.key(),)), {
            'hour': constraint.hour,
            'dow': constraint.dow,
            'slot': constraint.slot
        })
        context = resp.context
        # already finished, no need for finish URL:
        self.assertEqual(context['url_to_finish_spot'], None)
        assert '(already finished)' in resp.content
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:60,代码来源:tests.py

示例12: test_spot_constraint_assign

 def test_spot_constraint_assign(self):
     user = User(email='test')
     user.save()
     spot_key = models.Spot(title='test',body='body',type='Live Read Promo', author=user).put()
     constraint_key = models.SpotConstraint(dow=1,hour=1,slot=0).put()
     views.connectConstraintsAndSpot([constraint_key], spot_key)
     self.assertEqual(models.Spot.get(spot_key).constraints.count(), 1)
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:7,代码来源:tests.py

示例13: test_landing_page_shows_spots

    def test_landing_page_shows_spots(self):
        user = User(email='test')
        user.save()
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot_key = spot.put()
        # assign it to every day of the week at the top of the hour:
        constraint_keys = views.saveConstraint(dict(hour_list=range(0,24), dow_list=range(1,8), slot=0))
        views.connectConstraintsAndSpot(constraint_keys, spot_key)

        spot_copy = models.SpotCopy(body='body',
                                    spot=spot,
                                    author=user)
        spot_copy.put()

        resp = self.client.get(reverse('traffic_log.index'))
        context = resp.context[0]
        spot_map = {}
        constraint_map = {}
        for c in context['slotted_spots']:
            spot_map[c.hour] = list(c.iter_spots())[0]
            constraint_map[c.hour] = c

        now = time_util.chicago_now()

        # first hour:
        self.assertEqual(spot_map[now.hour].title, 'Legal ID')
        # second hour:
        self.assertEqual(spot_map[(now + datetime.timedelta(hours=1)).hour].title,
                'Legal ID')
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:31,代码来源:tests.py

示例14: test_view_spot_for_reading_basic

    def test_view_spot_for_reading_basic(self):
        author = User(email='test')
        author.save()
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot.put()
        constraint = models.SpotConstraint(dow=1, hour=0, slot=0, spots=[spot.key()])
        constraint.put()

        spot_copy = models.SpotCopy(
                        body='You are listening to chirpradio.org',
                        spot=spot,
                        author=author)
        spot_copy.put()

        resp = self.client.get(reverse('traffic_log.spotTextForReading', args=(spot.key(),)), {
            'hour': constraint.hour,
            'dow': constraint.dow,
            'slot': constraint.slot
        })
        context = resp.context
        self.assertEqual(context['spot_copy'].body, 'You are listening to chirpradio.org')
        self.assertEqual(context['url_to_finish_spot'],
            "/traffic_log/spot-copy/%s/finish?hour=0&dow=1&slot=0" % spot_copy.key())
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:25,代码来源:tests.py

示例15: test_spot_copy

    def test_spot_copy(self):
        author = User(email='test')
        author.save()
        spot = models.Spot(
                        title='Legal ID',
                        type='Station ID')
        spot.put()
        self.assertEqual(spot.get_add_copy_url(),
                            reverse('traffic_log.views.addCopyForSpot', args=(spot.key(),)))

        constraint = models.SpotConstraint(dow=1, hour=0, slot=0, spots=[spot.key()])
        constraint.put()

        spot_copy = models.SpotCopy(
                        body=(
                            'You are now and forever listening to a killer '
                            'radio station called chirpradio.org'),
                        spot=spot,
                        author=author)
        spot_copy.put()

        self.assertEqual(str(spot_copy), "You are now and forever listening to a killer radio...")
        self.assertEqual(spot_copy.get_edit_url(),
                            reverse('traffic_log.editSpotCopy', args=(spot_copy.key(),)))
        self.assertEqual(spot_copy.get_delete_url(),
                            reverse('traffic_log.deleteSpotCopy', args=(spot_copy.key(),)))
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:26,代码来源:tests.py


注:本文中的auth.models.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。