本文整理汇总了Python中badger.models.Badge.save方法的典型用法代码示例。如果您正苦于以下问题:Python Badge.save方法的具体用法?Python Badge.save怎么用?Python Badge.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类badger.models.Badge
的用法示例。
在下文中一共展示了Badge.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [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)
示例2: test_delete_award
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [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)
示例3: test_edit
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def test_edit(self):
"""Can edit badge detail"""
user = self._get_user()
badge = Badge(creator=user, title="Test II", description="Another test")
badge.save()
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"))
edit_url = doc.find("a.edit_badge").attr("href")
ok_(edit_url is not None)
r = self.client.get(edit_url)
doc = pq(r.content)
eq_("badge_edit", doc.find("body").attr("id"))
badge_title = "Edited title"
badge_desc = "Edited description"
r = self.client.post(edit_url, dict(title=badge_title, description=badge_desc), follow=True)
doc = pq(r.content)
eq_("badge_detail", doc.find("body").attr("id"))
ok_(badge_title in doc.find(".badge .title").text())
eq_(badge_desc, doc.find(".badge .description").text())
slug = doc.find(".badge").attr("data-slug")
badge = Badge.objects.get(slug=slug)
eq_(badge_title, badge.title)
eq_(badge_desc, badge.description)
示例4: setUp
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def setUp(self):
self.creator = self._get_user(username="creator")
self.testuser = self._get_user()
self.mw = RecentBadgeAwardsMiddleware()
self.badges = []
for n in ("test1", "test2", "test3"):
badge = Badge(title=n, creator=self.creator)
badge.save()
self.badges.append(badge)
self.awards = []
for b in self.badges:
self.awards.append(b.award_to(self.testuser))
示例5: test_edit_preserves_creator
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def test_edit_preserves_creator(self):
"""Edit preserves the original creator of the badge (bugfix)"""
orig_user = self._get_user(username="orig_user")
badge = Badge(creator=orig_user, title="Test 3", description="Another test")
badge.save()
edit_user = self._get_user(username="edit_user")
edit_user.is_superuser = True
edit_user.save()
self.client.login(username="edit_user", password="trustno1")
edit_url = reverse("badger.views.edit", args=(badge.slug,))
r = self.client.post(edit_url, dict(title="New Title"), follow=True)
doc = pq(r.content)
# The badge's creator should not have changed to the editing user.
badge_after = Badge.objects.get(pk=badge.pk)
ok_(badge_after.creator.pk != edit_user.pk)
示例6: test_disallowed_badge_award
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
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)
示例7: test_badge_detail
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def test_badge_detail(self):
"""Can view badge detail"""
user = self._get_user()
badge = Badge(creator=user, title="Test II", description="Another test")
badge.save()
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"))
eq_(1, doc.find('.badge-title:contains("%s")' % badge.title).length)
eq_(badge.description, doc.find(".badge .description").text())
# Now, take a look at the JSON format
url = reverse("badger.detail_json", args=(badge.slug,))
r = self.client.get(url, follow=True)
data = simplejson.loads(r.content)
eq_(badge.title, data["name"])
eq_(badge.description, data["description"])
eq_("http://testserver%s" % badge.get_absolute_url(), data["criteria"])
示例8: test_badge_detail
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def test_badge_detail(self):
"""Can view badge detail"""
user = self._get_user()
badge = Badge(creator=user, title="Test II",
description="Another test")
badge.save()
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'))
eq_(badge.title, doc.find('.badge .title').text())
eq_(badge.description, doc.find('.badge .description').text())
# Now, take a look at the JSON format
url = reverse('badger.detail_json', args=(badge.slug, ))
r = self.client.get(url, follow=True)
data = simplejson.loads(r.content)
eq_(badge.title, data['name'])
eq_(badge.description, data['description'])
eq_('http://testserver%s' % badge.get_absolute_url(),
data['criteria'])
示例9: create
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def create(user, badge_type):
badge = Badge()
badge.user = user
badge.badge_type = badge_type
badge.save()
return badge
示例10: BadgerApiViewsTests
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
class BadgerApiViewsTests(BadgerTestCase):
def setUp(self):
self.client = Client()
self.testuser = self._get_user()
self.badge = Badge(creator=self.testuser, title="Test II",
description="Another test", unique=True)
self.badge.save()
self.awards_url = reverse('badger.views.awards_list',
args=(self.badge.slug,))
key = Key()
key.user = self.testuser
self.password = key.generate_secret()
self.username = key.key
key.save()
self.key = key
auth_ct = '%s:%s' % (self.username, self.password)
self.basic_auth = 'Basic %s' % b64encode(auth_ct)
self.headers = {'HTTP_AUTHORIZATION': self.basic_auth}
Award.objects.all().delete()
def tearDown(self):
self.key.delete()
Award.objects.all().delete()
Badge.objects.all().delete()
def test_forbidden_without_key(self):
"""POST should require a valid key, or else yield a 403 response"""
resp = self.client.get(self.awards_url)
ok_(200, resp.status_code)
resp = self.client.post(self.awards_url)
ok_(403, resp.status_code)
resp = self.client.post(self.awards_url,
{'HTTP_AUTHORIZATION': 'Basic THISISINVALID'})
ok_(403, resp.status_code)
resp = self.client.post(self.awards_url, self.headers)
ok_(200, resp.status_code)
resp = self.client.get(self.awards_url, self.headers)
ok_(200, resp.status_code)
def test_bad_data(self):
"""Bad JSON request should result in a 400 response"""
resp = self.client.post(self.awards_url, "THISISBADDATA",
content_type='application/json',
HTTP_AUTHORIZATION=self.basic_auth)
ok_(400, resp.status_code)
def test_badge_award(self):
"""Can award badges from API"""
invite_email = '[email protected]'
invalid_email = 'THISISINVALID'
description = "Is a hoopy frood."
award_user = self._get_user(username="awardee1",
email="[email protected]")
# Construct the request data...
data = dict(
description = description,
emails = [
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",
#.........这里部分代码省略.........
示例11: badgeModule
# 需要导入模块: from badger.models import Badge [as 别名]
# 或者: from badger.models.Badge import save [as 别名]
def badgeModule(sender, module, **kwargs):
badge = Badge(title= module.name, slug = module.slug, description = module.description, unique = True)
badge.save()