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


Python User.save方法代码示例

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


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

示例1: MergeTests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class MergeTests(TestCase):

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast1.save()
        self.podcast2.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])

        self.episode1.save()
        self.episode2.save()

        self.user = User(username='test')
        self.user.email = '[email protected]'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        state1 = self.episode1.get_user_state(self.user)
        state2 = self.episode2.get_user_state(self.user)

        action1 = EpisodeAction(action='play', timestamp=datetime.utcnow())
        action2 = EpisodeAction(action='download', timestamp=datetime.utcnow())

        state1.add_actions([action1])
        state2.add_actions([action2])

        state1.save()
        state2.save()

        pm = PodcastMerger([self.podcast1, self.podcast2])
        pm.merge()

        state1 = self.episode1.get_user_state(self.user)
        state2 = self.episode2.get_user_state(self.user)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)



    def tearDown(self):
        self.podcast1.delete()
        self.episode1.delete()

        try:
            self.podcast2.delete()
            self.episode2.delete()
        except:
            pass

        self.user.delete()
开发者ID:Mic92,项目名称:mygpo,代码行数:60,代码来源:tests.py

示例2: SubscriptionAPITests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class SubscriptionAPITests(unittest.TestCase):
    """ Tests the Subscription API """

    def setUp(self):
        self.password = 'asdf'
        self.username = 'user'
        self.device_uid = 'test-device'
        self.user = User(username=self.username, email='[email protected]')
        self.user.set_password(self.password)
        self.user.save()
        self.user.is_active = True
        self.client = Client()

        self.extra = {
            'HTTP_AUTHORIZATION': create_auth_string(self.username,
                                                     self.password)
        }

        self.action_data = {
            'add': ['http://example.com/podcast.rss'],
        }

        self.url = reverse('subscriptions-api', kwargs={
            'version': '2',
            'username': self.user.username,
            'device_uid': self.device_uid,
        })

    def tearDown(self):
        self.user.delete()

    def test_set_get_subscriptions(self):
        """ Tests that an upload subscription is returned back correctly """

        # upload a subscription
        response = self.client.post(self.url, json.dumps(self.action_data),
                                    content_type="application/json",
                                    **self.extra)
        self.assertEqual(response.status_code, 200, response.content)

        # verify that the subscription is returned correctly
        response = self.client.get(self.url, {'since': '0'}, **self.extra)
        self.assertEqual(response.status_code, 200, response.content)
        response_obj = json.loads(response.content)
        self.assertEqual(self.action_data['add'], response_obj['add'])
        self.assertEqual([], response_obj.get('remove', []))

    def test_unauth_request(self):
        """ Tests that an unauthenticated request gives a 401 response """
        response = self.client.get(self.url, {'since': '0'})
        self.assertEqual(response.status_code, 401, response.content)
开发者ID:kerrickstaley,项目名称:mygpo,代码行数:53,代码来源:tests.py

示例3: SimpleWebTests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class SimpleWebTests(TestCase):
    @classmethod
    def setUpClass(self):
        self.user = User(username="web-test", email="[email protected]")
        self.user.set_password("pwd")
        self.user.save()

        self.auth_string = create_auth_string("test", "pwd")

    @classmethod
    def tearDownClass(self):
        self.user.delete()

    def test_access_parameterless_pages(self):
        pages = [
            "history",
            "suggestions",
            "tags",
            "subscriptions",
            "subscriptions-opml",
            "subscriptions-download",
            "favorites",
            "account",
            "privacy",
            "delete-account",
            "share",
            "toplist",
            "episode-toplist",
            "devices",
            "device-create",
            "login",
            "logout",
            "home",
        ]

        self.access_pages(pages, [], True)

    def test_access_podcast_pages(self):
        pages = ["podcast"]

    def access_pages(self, pages, args, login):
        if login:
            self.client.post("/login/", dict(login_username=self.user.username, pwd="pwd"))

        for page in pages:
            response = self.client.get(reverse(page, args=args), follow=True)
            self.assertEquals(response.status_code, 200)
开发者ID:kerrickstaley,项目名称:mygpo,代码行数:49,代码来源:tests.py

示例4: UnsubscribeMergeTests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class UnsubscribeMergeTests(TestCase):
    """ Test if merged podcasts can be properly unsubscribed

    TODO: this test fails intermittently """

    P2_URL = 'http://test.org/podcast/'

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=[self.P2_URL])
        self.podcast1.save()
        self.podcast2.save()

        self.user = User(username='test-merge')
        self.user.email = '[email protected]'
        self.user.set_password('secret!')
        self.user.save()

        self.device = get_device(self.user, 'dev', '')

    def test_merge_podcasts(self):
        self.podcast2.subscribe(self.user, self.device)

        # merge podcast2 into podcast1
        pm = PodcastMerger([self.podcast1, self.podcast2], Counter(), [])
        pm.merge()

        # seems that setting delayed_commit = false in the CouchDB config, as
        # well as a delay here fix the intermittent failures.
        # TODO: further investiation needed
        import time
        time.sleep(2)

        # get podcast for URL of podcast2 and unsubscribe from it
        p = podcast_for_url(self.P2_URL)
        p.unsubscribe(self.user, self.device)

        subscriptions = subscribed_podcast_ids_by_user_id(self.user._id)
        self.assertEqual(0, len(subscriptions))

    def tearDown(self):
        self.podcast1.delete()
        self.user.delete()
开发者ID:fk-lx,项目名称:mygpo,代码行数:45,代码来源:tests.py

示例5: DeviceSyncTests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class DeviceSyncTests(unittest.TestCase):

    def setUp(self):
        self.user = User(username='test')
        self.user.email = '[email protected]'
        self.user.set_password('secret!')
        self.user.save()


    def test_group(self):
        dev1 = Device(uid='d1')
        self.user.devices.append(dev1)

        dev2 = Device(uid='d2')
        self.user.devices.append(dev2)

        group = self.user.get_grouped_devices().next()
        self.assertEquals(group.is_synced, False)
        self.assertIn(dev1, group.devices)
        self.assertIn(dev2, group.devices)


        dev3 = Device(uid='d3')
        self.user.devices.append(dev3)

        self.user.sync_devices(dev1, dev3)

        groups = self.user.get_grouped_devices()
        g1 = groups.next()

        self.assertEquals(g1.is_synced, True)
        self.assertIn(dev1, g1.devices)
        self.assertIn(dev3, g1.devices)

        g2 = groups.next()
        self.assertEquals(g2.is_synced, False)
        self.assertIn(dev2, g2.devices)


        targets = self.user.get_sync_targets(dev1)
        target = targets.next()
        self.assertEquals(target, dev2)
开发者ID:fk-lx,项目名称:mygpo,代码行数:44,代码来源:tests.py

示例6: test_merge

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
    def test_merge(self):

        p1 = Podcast()
        p1.urls = ['http://example.com/podcast1.rss']
        p1.save()

        p2 = Podcast()
        p2.urls = ['http://example.com/podcast2.rss']
        p2.save()


        e1 = Episode()
        e1.title = 'Episode 1'
        e1.podcast = p1.get_id()
        e1.urls = ['http://example.com/podcast1/e1.mp3']
        e1.save()

        e2 = Episode()
        e2.title = 'Episode 2'
        e2.podcast = p1.get_id()
        e2.urls = ['http://example.com/podcast1/e2.mp3']
        e2.save()

        e3 = Episode()
        e3.title = 'Episode 3'
        e3.podcast = p2.get_id()
        e3.urls = ['http://example.com/podcast2/e2.mp3']
        e3.save()

        e4 = Episode()
        e4.title = 'Episode 4'
        e4.podcast = p2.get_id()
        e4.urls = ['http://example.com/podcast2/e3.mp3']
        e4.save()

        user = User()
        user.username = 'user'
        user.email = '[email protected]'
        user.set_password('secret')

        device1 = Device()
        device1.uid = 'dev1'

        device2 = Device()
        device2.uid = 'dev2'

        user.devices.append(device1)
        user.devices.append(device2)
        user.save()


        p1.subscribe(user, device1)
        time.sleep(1)
        p1.unsubscribe(user, device1)
        time.sleep(1)
        p1.subscribe(user, device1)
        p2.subscribe(user, device2)

        s1 = e1.get_user_state(user)
        s1.add_actions([EpisodeAction(action='play')])
        s1.save()

        s3 = e3.get_user_state(user)
        s3.add_actions([EpisodeAction(action='play')])
        s3.save()

        # we need that for later
        e3_id = e3._id

        actions = Counter()

        # decide which episodes to merge
        groups = [(0, [e1]), (1, [e2, e3]), (2, [e4])]

        # carry out the merge
        pm = PodcastMerger([p1, p2], actions, groups)
        pm.merge()

        e1 = Episode.get(e1._id)
        es1 = e1.get_user_state(user)
        self.assertEqual(len(es1.actions), 1)

        # check if merged episode's id can still be accessed
        e3 = Episode.get(e3_id)
        es3 = e3.get_user_state(user)
        self.assertEqual(len(es3.actions), 1)

        p1 = Podcast.get(p1.get_id())
        ps1 = p1.get_user_state(user)
        self.assertEqual(len(ps1.get_subscribed_device_ids()), 2)

        self.assertEqual(len(list(p1.get_episodes())), 3)
开发者ID:Mic92,项目名称:mygpo,代码行数:94,代码来源:tests.py

示例7: MergeTests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class MergeTests(TestCase):
    """ Tests merging of two podcasts, their episodes and states """

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast1.save()
        self.podcast2.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])

        self.episode1.save()
        self.episode2.save()

        self.user = User(username='test-merge')
        self.user.email = '[email protected]'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        # Create additional data that will be merged
        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, self.episode2)

        action1 = EpisodeAction(action='play',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))
        action2 = EpisodeAction(action='download',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))

        add_episode_actions(state1, [action1])
        add_episode_actions(state2, [action2])

        # copy of the object
        episode2 = episode_by_id(self.episode2._id)

        # decide which episodes to merge
        groups = [(0, [self.episode1, self.episode2])]
        counter = Counter()

        pm = PodcastMerger([self.podcast1, self.podcast2], counter, groups)
        pm.merge()

        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, episode2)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)
        self.assertEqual(state2._id, None)



    def tearDown(self):
        self.podcast1.delete()
        self.episode1.delete()

        #self.podcast2.delete()
        #self.episode2.delete()

        self.user.delete()
开发者ID:fk-lx,项目名称:mygpo,代码行数:68,代码来源:tests.py

示例8: MergeGroupTests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class MergeGroupTests(TestCase):
    """ Tests merging of two podcasts, one of which is part of a group """

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast3 = Podcast(urls=['http://test.org/feed/'])
        self.podcast1.save()
        self.podcast2.save()
        self.podcast3.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode3 = Episode(podcast=self.podcast3.get_id(),
                urls = ['http://example.com/media.mp3'])


        self.episode1.save()
        self.episode2.save()
        self.episode3.save()

        self.podcast2.group_with(self.podcast3, 'My Group', 'Feed1', 'Feed2')

        self.user = User(username='test-merge-group')
        self.user.email = '[email protected]'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        podcast1 = podcast_by_id(self.podcast1.get_id())
        podcast2 = podcast_by_id(self.podcast2.get_id())
        podcast3 = podcast_by_id(self.podcast3.get_id())

        # assert that the podcasts are actually grouped
        self.assertEqual(podcast2._id, podcast3._id)
        self.assertNotEqual(podcast2.get_id(), podcast2._id)
        self.assertNotEqual(podcast3.get_id(), podcast3._id)

        # Create additional data that will be merged
        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, self.episode2)

        action1 = EpisodeAction(action='play',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))
        action2 = EpisodeAction(action='download',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))

        add_episode_actions(state1, [action1])
        add_episode_actions(state2, [action2])

        # copy of the object
        episode2 = episode_by_id(self.episode2._id)

        # decide which episodes to merge
        groups = [(0, [self.episode1, self.episode2])]
        counter = Counter()

        pm = PodcastMerger([podcast2, podcast1], counter, groups)
        pm.merge()

        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, episode2)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)
        self.assertEqual(state2._id, None)

        episode1 = episode_by_id(self.episode1._id)

        # episode2 has been merged into episode1, so it must contain its
        # merged _id
        self.assertEqual(episode1.merged_ids, [episode2._id])



    def tearDown(self):
        self.podcast2.delete()
        self.episode1.delete()

        #self.podcast2.delete()
        #self.episode2.delete()

        self.user.delete()
开发者ID:fk-lx,项目名称:mygpo,代码行数:91,代码来源:tests.py

示例9: AdvancedAPITests

# 需要导入模块: from mygpo.users.models import User [as 别名]
# 或者: from mygpo.users.models.User import save [as 别名]
class AdvancedAPITests(unittest.TestCase):

    def setUp(self):
        self.password = 'asdf'
        self.username = 'user'
        self.user = User(username=self.username, email='[email protected]')
        self.user.set_password(self.password)
        self.user.save()
        self.user.is_active = True
        self.client = Client()

        self.extra = {
            'HTTP_AUTHORIZATION': create_auth_string(self.username, self.password)
        }

        self.action_data = [
          {
           "podcast": "http://example.com/feed.rss",
           "episode": "http://example.com/files/s01e20.mp3",
           "device": "gpodder_abcdef123",
           "action": "download",
           "timestamp": "2009-12-12T09:00:00"
          },
          {
           "podcast": "http://example.org/podcast.php",
           "episode": "http://ftp.example.org/foo.ogg",
           "action": "play",
           "started": 15,
           "position": 120,
           "total":  500
          }
        ]



    def tearDown(self):
        self.user.delete()


    def test_episode_actions(self):
        url = reverse(episodes, kwargs=dict(version='2', username=self.user.username))

        # upload actions
        response = self.client.post(url, json.dumps(self.action_data),
                content_type="application/json", **self.extra)
        self.assertEqual(response.status_code, 200, response.content)


        # get all
        extra = deepcopy(self.extra)
        extra['since'] = 0

        response = self.client.get(url, **extra)
        self.assertEqual(response.status_code, 200, response.content)
        response_obj = json.loads(response.content)
        actions = response_obj['actions']
        self.assertTrue(self.compare_action_list(self.action_data, actions))


    def compare_action_list(self, as1, as2):
        for a1 in as1:
            found = False
            for a2 in as2:
                if self.compare_actions(a1, a2):
                    found = True

            if not found:
                raise ValueError('%s not found in %s' % (a1, as2))
                return False

        return True


    def compare_actions(self, a1, a2):
        for key, val in a1.items():
            if a2.get(key, None) != val:
                return False
        return True
开发者ID:fk-lx,项目名称:mygpo,代码行数:80,代码来源:tests.py


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