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


Python Badge.award_to方法代码示例

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


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

示例1: test_delete

# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import award_to [as 别名]
    def test_delete(self):
        """Can delete badge"""
        user = self._get_user()
        badge = Badge(creator=user, title="Test III",
                      description="Another test")
        badge.save()
        slug = badge.slug

        badge.award_to(user)

        self.client.login(username="tester", password="trustno1")

        r = self.client.get(reverse('badger.views.detail',
            args=(badge.slug,)), follow=True)
        doc = pq(r.content)

        eq_('badge_detail', doc.find('body').attr('id'))
        delete_url = doc.find('a.delete_badge').attr('href')
        ok_(delete_url is not None)

        r = self.client.get(delete_url)
        doc = pq(r.content)
        eq_('badge_delete', doc.find('body').attr('id'))
        eq_("1", doc.find('.awards_count').text())

        r = self.client.post(delete_url, {}, follow=True)
        doc = pq(r.content)

        try:
            badge = Badge.objects.get(slug=slug)
            ok_(False)
        except Badge.DoesNotExist:
            ok_(True)
开发者ID:askvictor,项目名称:django-badger,代码行数:35,代码来源:test_views.py

示例2: test_delete_award

# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import award_to [as 别名]
    def test_delete_award(self):
        """Can delete award"""
        user = self._get_user()
        badge = Badge(creator=user, title="Test III",
                      description="Another test")
        badge.save()

        award = badge.award_to(user)

        self.client.login(username="tester", password="trustno1")

        r = self.client.get(reverse('badger.views.award_detail',
            args=(badge.slug, award.id)), follow=True)
        doc = pq(r.content)

        eq_('award_detail', doc.find('body').attr('id'))
        delete_url = doc.find('a.delete_award').attr('href')
        ok_(delete_url is not None)

        r = self.client.post(delete_url, {}, follow=True)

        try:
            award = Award.objects.get(pk=award.pk)
            ok_(False)
        except Award.DoesNotExist:
            ok_(True)
开发者ID:askvictor,项目名称:django-badger,代码行数:28,代码来源:test_views.py

示例3: BadgerApiViewsTests

# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import award_to [as 别名]

#.........这里部分代码省略.........
                award_user.email,
                invite_email,
                invalid_email,
            ],
        )

        # POST to the awards URL
        resp = self.client.post(self.awards_url, json.dumps(data),
                                content_type='application/json',
                                HTTP_AUTHORIZATION=self.basic_auth)
        
        ok_(self.badge.is_awarded_to(award_user))
        award = Award.objects.get(user=award_user, badge=self.badge)
        eq_(description, award.description)

        eq_('application/json', resp['Content-Type'])
        data = json.loads(resp.content)

        ok_('successes' in data)
        ok_(award_user.email in data['successes'])
        eq_('AWARDED', data['successes'][award_user.email])
        ok_(invite_email in data['successes'])
        eq_('INVITED', data['successes'][invite_email])

        ok_('errors' in data)
        ok_(invalid_email in data['errors'])
        eq_('INVALID', data['errors'][invalid_email])

    def test_no_description(self):
        """Awards can be issued with no description"""
        award_user = self._get_user(username="awardee1",
                                    email="[email protected]")

        data = {"emails": [award_user.email]}

        resp = self.client.post(self.awards_url, json.dumps(data),
                                content_type='application/json',
                                HTTP_AUTHORIZATION=self.basic_auth)

        eq_('application/json', resp['Content-Type'])
        data = json.loads(resp.content)
        
        ok_(award_user.email in data['successes'])
        ok_(award_user.email not in data['errors'])
        ok_(self.badge.is_awarded_to(award_user))

    def test_already_awarded(self):
        """Can award badges from API"""
        description = "Is a hoopy frood."
        invite_email = '[email protected]'
        award_user = self._get_user(username="awardee1",
                                    email="[email protected]")

        award = self.badge.award_to(email=award_user.email)
        deferred_award = self.badge.award_to(email=invite_email)

        # Construct the request data...
        data = dict(
            description = description,
            emails = [
                invite_email,
                award_user.email,
            ],
        )

        # POST to the awards URL
        resp = self.client.post(self.awards_url, json.dumps(data),
                                content_type='application/json',
                                HTTP_AUTHORIZATION=self.basic_auth)
        
        eq_('application/json', resp['Content-Type'])
        data = json.loads(resp.content)

        print "DATA %s" % data

        ok_('errors' in data)
        ok_(award_user.email in data['errors'])
        eq_('ALREADYAWARDED', data['errors'][award_user.email])
        ok_(invite_email in data['errors'])
        eq_('ALREADYAWARDED', data['errors'][invite_email])

    def test_disallowed_badge_award(self):
        """User should not be able to POST an award to a badge for which the
        user hasn't got permission to do so"""
        user = self._get_user(username="heyyou",
                              email="[email protected]")
        badge = Badge(creator=user, title="Hey you badge",
                      description="Another test", unique=True)
        badge.save()

        awards_url = reverse('badger.views.awards_list',
                             args=(self.badge.slug,))

        data = dict(emails=['[email protected]',])

        resp = self.client.post(awards_url, json.dumps(data),
                                content_type='application/json',
                                HTTP_AUTHORIZATION=self.basic_auth)

        ok_(403, resp.status_code)
开发者ID:6thmonth,项目名称:badges.mozilla.org,代码行数:104,代码来源:test_views.py


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