mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +11:00
One time tests and docs.
This commit is contained in:
parent
4eec1ab692
commit
3b8bb915e5
3 changed files with 50 additions and 3 deletions
|
@ -55,8 +55,28 @@ behavior without touching the code:
|
||||||
(3600 * 24 * 30 * 12 * 100, ugettext(u'100 Years')),
|
(3600 * 24 * 30 * 12 * 100, ugettext(u'100 Years')),
|
||||||
)
|
)
|
||||||
|
|
||||||
You can keep snippets forever when you set the choice key to ``never``.
|
**One-time snippets** are supported. One time snippets are automatically
|
||||||
The management command will ignore these snippets::
|
deleted once a defined view count has reached (Default: ``2``). To
|
||||||
|
enable one-time snippets you have to add a choice ``onetime`` to the
|
||||||
|
expire choices::
|
||||||
|
|
||||||
|
ugettext = lambda s: s
|
||||||
|
DPASTE_EXPIRE_CHOICES = (
|
||||||
|
('onetime', ugettext(u'One-Time snippet')),
|
||||||
|
(3600, ugettext(u'In one hour')),
|
||||||
|
(3600 * 24 * 7, ugettext(u'In one week')),
|
||||||
|
(3600 * 24 * 30, ugettext(u'In one month')),
|
||||||
|
)
|
||||||
|
|
||||||
|
You can also set the maximum view count after what the snippet gets
|
||||||
|
deleted. The default is ``2``. One view is from the author, one view
|
||||||
|
is from another user::
|
||||||
|
|
||||||
|
DPASTE_ONETIME_LIMIT = 2
|
||||||
|
|
||||||
|
**Infinite snippets** are supported. You can keep snippets forever when
|
||||||
|
you set the choice key to ``never``. The management command will ignore
|
||||||
|
these snippets::
|
||||||
|
|
||||||
ugettext = lambda s: s
|
ugettext = lambda s: s
|
||||||
DPASTE_EXPIRE_CHOICES = (
|
DPASTE_EXPIRE_CHOICES = (
|
||||||
|
|
|
@ -8,11 +8,13 @@ from dpaste.models import Snippet
|
||||||
from dpaste.highlight import LEXER_LIST, LEXER_DEFAULT, LEXER_KEYS
|
from dpaste.highlight import LEXER_LIST, LEXER_DEFAULT, LEXER_KEYS
|
||||||
|
|
||||||
EXPIRE_CHOICES = getattr(settings, 'DPASTE_EXPIRE_CHOICES', (
|
EXPIRE_CHOICES = getattr(settings, 'DPASTE_EXPIRE_CHOICES', (
|
||||||
|
('onetime', _(u'One Time Snippet')),
|
||||||
(3600, _(u'In one hour')),
|
(3600, _(u'In one hour')),
|
||||||
(3600 * 24 * 7, _(u'In one week')),
|
(3600 * 24 * 7, _(u'In one week')),
|
||||||
(3600 * 24 * 30, _(u'In one month')),
|
(3600 * 24 * 30, _(u'In one month')),
|
||||||
|
# ('never', _(u'Never')),
|
||||||
))
|
))
|
||||||
EXPIRE_DEFAULT = getattr(settings, 'DPASTE_EXPIRE_DEFAULT', EXPIRE_CHOICES[2][0])
|
EXPIRE_DEFAULT = getattr(settings, 'DPASTE_EXPIRE_DEFAULT', EXPIRE_CHOICES[3][0])
|
||||||
MAX_CONTENT_LENGTH = getattr(settings, 'DPASTE_MAX_CONTENT_LENGTH', 250*1024*1024)
|
MAX_CONTENT_LENGTH = getattr(settings, 'DPASTE_MAX_CONTENT_LENGTH', 250*1024*1024)
|
||||||
|
|
||||||
class SnippetForm(forms.ModelForm):
|
class SnippetForm(forms.ModelForm):
|
||||||
|
|
|
@ -104,6 +104,31 @@ class SnippetTestCase(TestCase):
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 0)
|
self.assertEqual(Snippet.objects.count(), 0)
|
||||||
|
|
||||||
|
def test_new_snippet_onetime(self):
|
||||||
|
"""
|
||||||
|
One-time snippets get deleted after two views.
|
||||||
|
"""
|
||||||
|
# POST data
|
||||||
|
data = self.valid_form_data()
|
||||||
|
data['expires'] = 'onetime'
|
||||||
|
|
||||||
|
# First view, the author gets redirected after posting
|
||||||
|
response = self.client.post(self.new_url, data, follow=True)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
|
self.assertContains(response, data['content'])
|
||||||
|
|
||||||
|
# Second View, another user looks at the snippet
|
||||||
|
response = self.client.get(response.request['PATH_INFO'], follow=True)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
|
self.assertContains(response, data['content'])
|
||||||
|
|
||||||
|
# Third/Further View, another user looks at the snippet but it was deleted
|
||||||
|
response = self.client.get(response.request['PATH_INFO'], follow=True)
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
self.assertEqual(Snippet.objects.count(), 0)
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# Reply
|
# Reply
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue